tracker-0.16.2/src/libtracker-fts/tracker-parser-utils.c

No issues found

 1 /*
 2  * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
 3  *
 4  * This library is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU Lesser General Public
 6  * License as published by the Free Software Foundation; either
 7  * version 2.1 of the License, or (at your option) any later version.
 8  *
 9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301  USA
18  */
19 
20 #include "config.h"
21 
22 #include <string.h>
23 
24 #include <libtracker-common/tracker-utils.h>
25 
26 #include "tracker-parser-utils.h"
27 
28 /*
29  * Definition of the possible reserved words.
30  *  Length of word is explicitly given to avoid strlen() calls
31  */
32 typedef struct {
33 	const gchar *word;
34 	gsize        word_length;
35 } TrackerParserReservedWord;
36 
37 static const TrackerParserReservedWord reserved_words[] = {
38 	{ "or", 2 },
39 	{ NULL, 0 }
40 };
41 
42 gboolean
43 tracker_parser_is_reserved_word_utf8 (const gchar *word,
44                                       gsize word_length)
45 {
46 	gint i = 0;
47 
48 	/* Loop the array of predefined reserved words */
49 	while (reserved_words[i].word != NULL) {
50 		if (word_length == reserved_words[i].word_length &&
51 		    strncmp (word,
52 		             reserved_words[i].word,
53 		             word_length) == 0) {
54 			return TRUE;
55 		}
56 		i++;
57 	}
58 
59 	return FALSE;
60 }
61 
62 
63 #if TRACKER_PARSER_DEBUG_HEX
64 void
65 tracker_parser_message_hex (const gchar  *message,
66                             const gchar  *str,
67                             gsize         str_length)
68 {
69 	gchar *hex_aux;
70 	gchar *str_aux;
71 
72 	g_return_if_fail (message);
73 	g_return_if_fail (str);
74 	g_return_if_fail (str_length != 0);
75 
76 	/* String may not come NIL-terminated */
77 	str_aux = g_malloc (str_length + 1);
78 	memcpy (str_aux, str, str_length);
79 	str_aux[str_length] = '\0';
80 
81 	/* Get hexadecimal representation of the input string */
82 	hex_aux = tracker_strhex (str, str_length, ':');
83 
84 	/* Log it */
85 	g_message ("%s: '%s' (%s)",
86 	           message, str_aux, hex_aux);
87 
88 	g_free (str_aux);
89 	g_free (hex_aux);
90 }
91 #endif