xref: /haiku/headers/private/file_systems/QueryParserUtils.h (revision b8a45b3a2df2379b4301bf3bd5949b9a105be4ba)
1 /*
2  * Copyright 2001-2014, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
4  * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
5  * This file may be used under the terms of the MIT License.
6  */
7 #ifndef _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
8 #define _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
9 
10 
11 #include <sys/cdefs.h>
12 
13 #ifdef FS_SHELL
14 #	include <new>
15 
16 #	include "fssh_api_wrapper.h"
17 #	include "fssh_auto_deleter.h"
18 #else
19 #	include <SupportDefs.h>
20 #endif	// !FS_SHELL
21 
22 
23 namespace QueryParser {
24 
25 
26 enum match {
27 	NO_MATCH = 0,
28 	MATCH_OK = 1,
29 
30 	MATCH_BAD_PATTERN = -2,
31 	MATCH_INVALID_CHARACTER
32 };
33 
34 // return values from isValidPattern()
35 enum {
36 	PATTERN_INVALID_ESCAPE = -3,
37 	PATTERN_INVALID_RANGE,
38 	PATTERN_INVALID_SET
39 };
40 
41 
42 __BEGIN_DECLS
43 
44 
45 void		skipWhitespace(const char** expr, int32 skip = 0);
46 void		skipWhitespaceReverse(const char** expr, const char* stop);
47 int			compareKeys(uint32 type, const void* key1, size_t length1,
48 				const void* key2, size_t length2);
49 uint32		utf8ToUnicode(const char** string);
50 int32		getFirstPatternSymbol(const char* string);
51 status_t	isValidPattern(const char* pattern);
52 status_t	matchString(const char* pattern, const char* string);
53 
54 
55 __END_DECLS
56 
57 
58 static inline bool
59 isPattern(char* string)
60 {
61 	return getFirstPatternSymbol(string) >= 0 ? true : false;
62 }
63 
64 
65 }	// namespace QueryParser
66 
67 
68 #endif	// _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
69