haiku/headers/private/file_systems/QueryParserUtils.h
Augustin Cavalier 6d7e181767 file_systems/QueryParser: Rewrite parsing logic to avoid recursion.
This way, we can handle parse trees of arbitrary depth without
running into stack overflows. Of course, evaluation is still
a problem...

While at it, use "const char*" everywhere, and also put the
query parser into an Init() function so we can return
more statuses than just B_BAD_VALUE.

Part of #18692.

Change-Id: Ib81e6545935ce484df10dfe36ca4ffcf2b3cd607
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7710
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-06-24 19:40:08 +00:00

69 lines
1.4 KiB
C++

/*
* Copyright 2001-2014, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* This file may be used under the terms of the MIT License.
*/
#ifndef _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
#define _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
#include <sys/cdefs.h>
#ifdef FS_SHELL
# include <new>
# include "fssh_api_wrapper.h"
# include "fssh_auto_deleter.h"
#else
# include <SupportDefs.h>
#endif // !FS_SHELL
namespace QueryParser {
enum match {
NO_MATCH = 0,
MATCH_OK = 1,
MATCH_BAD_PATTERN = -2,
MATCH_INVALID_CHARACTER
};
// return values from isValidPattern()
enum {
PATTERN_INVALID_ESCAPE = -3,
PATTERN_INVALID_RANGE,
PATTERN_INVALID_SET
};
__BEGIN_DECLS
void skipWhitespace(const char** expr, int32 skip = 0);
void skipWhitespaceReverse(const char** expr, const char* stop);
int compareKeys(uint32 type, const void* key1, size_t length1,
const void* key2, size_t length2);
uint32 utf8ToUnicode(const char** string);
int32 getFirstPatternSymbol(const char* string);
status_t isValidPattern(const char* pattern);
status_t matchString(const char* pattern, const char* string);
__END_DECLS
static inline bool
isPattern(char* string)
{
return getFirstPatternSymbol(string) >= 0 ? true : false;
}
} // namespace QueryParser
#endif // _FILE_SYSTEMS_QUERY_PARSER_UTILS_H