xref: /haiku/headers/private/file_systems/QueryParserUtils.h (revision de9c0613398645390b8d450089051b2888e2e15b)
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 #ifdef FS_SHELL
12 #	include <new>
13 
14 #	include "fssh_api_wrapper.h"
15 #	include "fssh_auto_deleter.h"
16 #else
17 #	include <sys/cdefs.h>
18 
19 #	include <SupportDefs.h>
20 #endif	// !FS_SHELL
21 
22 
23 
24 namespace QueryParser {
25 
26 
27 enum match {
28 	NO_MATCH = 0,
29 	MATCH_OK = 1,
30 
31 	MATCH_BAD_PATTERN = -2,
32 	MATCH_INVALID_CHARACTER
33 };
34 
35 // return values from isValidPattern()
36 enum {
37 	PATTERN_INVALID_ESCAPE = -3,
38 	PATTERN_INVALID_RANGE,
39 	PATTERN_INVALID_SET
40 };
41 
42 
43 __BEGIN_DECLS
44 
45 
46 void		skipWhitespace(char** expr, int32 skip = 0);
47 void		skipWhitespaceReverse(char** expr, char* stop);
48 int			compareKeys(uint32 type, const void* key1, size_t length1,
49 				const void* key2, size_t length2);
50 uint32		utf8ToUnicode(char** string);
51 int32		getFirstPatternSymbol(char* string);
52 status_t	isValidPattern(char* pattern);
53 status_t	matchString(char* pattern, char* string);
54 
55 
56 __END_DECLS
57 
58 
59 static inline bool
60 isPattern(char* string)
61 {
62 	return getFirstPatternSymbol(string) >= 0 ? true : false;
63 }
64 
65 
66 }	// namespace QueryParser
67 
68 
69 #endif	// _FILE_SYSTEMS_QUERY_PARSER_UTILS_H
70