[tracker/parser-unicode-libs-review: 73/85] Improved the way the debug logs showing hex contents are compiled
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/parser-unicode-libs-review: 73/85] Improved the way the debug logs showing hex contents are compiled
- Date: Tue, 4 May 2010 17:30:08 +0000 (UTC)
commit dc06561b28852fe4a1aec2ff63e0c1ec7593a564
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu Apr 29 15:31:02 2010 +0200
Improved the way the debug logs showing hex contents are compiled
src/libtracker-fts/tracker-parser-glib.c | 39 ++------------
src/libtracker-fts/tracker-parser-libunistring.c | 60 ++++------------------
src/libtracker-fts/tracker-parser-utils.c | 32 ++++++++++++
src/libtracker-fts/tracker-parser-utils.h | 14 +++++
4 files changed, 63 insertions(+), 82 deletions(-)
---
diff --git a/src/libtracker-fts/tracker-parser-glib.c b/src/libtracker-fts/tracker-parser-glib.c
index 891d9f6..de7ba4e 100644
--- a/src/libtracker-fts/tracker-parser-glib.c
+++ b/src/libtracker-fts/tracker-parser-glib.c
@@ -28,14 +28,9 @@
#include <pango/pango.h>
-#include <libtracker-common/tracker-common.h>
#include "tracker-parser.h"
#include "tracker-parser-utils.h"
-/* Define to 1 if you want to enable debugging logs showing HEX contents
- * of the words being parsed */
-#define TRACKER_PARSER_DEBUG_HEX 0
-
/* Need pango for CJK ranges which are : 0x3400 - 0x4DB5, 0x4E00 -
* 0x9FA5, 0x20000 - <= 0x2A6D6
*/
@@ -543,29 +538,15 @@ tracker_parser_process_word (TrackerParser *parser,
}
/* Log original word */
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- aux = tracker_strhex (word, bytes, ':');
- g_message ("ORIGINAL word: '%s' (%s)",
- word, aux);
- g_free (aux);
- }
-#endif
+ tracker_parser_message_hex ("ORIGINAL word",
+ word, bytes);
if (do_strip) {
stripped_word = tracker_parser_unaccent_string (word, bytes, &len);
/* Log after UNAC stripping */
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- aux = tracker_strhex (stripped_word, len, ':');
- g_message (" After UNAC stripping: '%s' (%s)",
- stripped_word, aux);
- g_free (aux);
- }
-#endif
+ tracker_parser_message_hex (" After UNAC stripping",
+ stripped_word, len);
} else {
stripped_word = NULL;
}
@@ -583,16 +564,8 @@ tracker_parser_process_word (TrackerParser *parser,
}
/* Log after normalization */
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- aux = tracker_strhex (str, strlen ((gchar *)str), ':');
- g_message (" After NFC normalization: '%s' (%s)",
- str, aux);
- g_free (aux);
- }
-#endif
-
+ tracker_parser_message_hex (" After NFC normalization",
+ str, strlen ((gchar *)str));
if (!str) {
return NULL;
diff --git a/src/libtracker-fts/tracker-parser-libunistring.c b/src/libtracker-fts/tracker-parser-libunistring.c
index 0052cb0..12d1951 100644
--- a/src/libtracker-fts/tracker-parser-libunistring.c
+++ b/src/libtracker-fts/tracker-parser-libunistring.c
@@ -35,14 +35,9 @@
#include <unictype.h>
#include <unicase.h>
-#include <libtracker-common/tracker-common.h>
#include "tracker-parser.h"
#include "tracker-parser-utils.h"
-/* Define to 1 if you want to enable debugging logs showing HEX contents
- * of the words being parsed */
-#define TRACKER_PARSER_DEBUG_HEX 0
-
/* ASCII-7 is in range [0x00,0x7F] */
#define IS_ASCII_BYTE(c) ((c) <= 0x7F)
@@ -317,23 +312,8 @@ tracker_parser_process_word (TrackerParser *parser,
}
/* Log original word */
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- gchar *word_aux;
-
- /* Word may not come NIL-terminated */
- word_aux = g_malloc (length + 1);
- memcpy (word_aux, word, length);
- word_aux[length] = '\0';
-
- aux = tracker_strhex (word, length, ':');
- g_message ("ORIGINAL word: '%s' (%s)",
- word_aux, aux);
- g_free (aux);
- g_free (word_aux);
- }
-#endif
+ tracker_parser_message_hex ("ORIGINAL word",
+ word, length);
/* Leave space for last NIL */
new_word_length = WORD_BUFFER_LENGTH - 1;
@@ -361,15 +341,9 @@ tracker_parser_process_word (TrackerParser *parser,
/* Set output NIL */
normalized[new_word_length] = '\0';
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- aux = tracker_strhex (normalized, new_word_length, ':');
- g_message (" After Casefolding and NFC normalization: '%s' (%s)",
- normalized, aux);
- g_free (aux);
- }
-#endif
+ /* Log after Normalization */
+ tracker_parser_message_hex (" After Casefolding and NFC normalization",
+ normalized, new_word_length);
/* UNAC stripping needed? */
if (do_strip) {
@@ -381,15 +355,8 @@ tracker_parser_process_word (TrackerParser *parser,
if (stripped) {
/* Log after UNAC stripping */
-#if TRACKER_PARSER_DEBUG_HEX
- {
- gchar *aux;
- aux = tracker_strhex (stripped, stripped_word_length, ':');
- g_message (" After UNAC stripping: '%s' (%s)",
- stripped, aux);
- g_free (aux);
- }
-#endif
+ tracker_parser_message_hex (" After UNAC stripping",
+ stripped, stripped_word_length);
new_word_length = stripped_word_length;
}
}
@@ -400,15 +367,10 @@ tracker_parser_process_word (TrackerParser *parser,
stemmed = tracker_language_stem_word (parser->language,
stripped ? stripped : normalized,
new_word_length);
-#if TRACKER_PARSER_DEBUG_HEX
- if (stemmed) {
- gchar *aux;
- aux = tracker_strhex (stemmed, strlen (stemmed), ':');
- g_message (" After stemming: '%s' (%s)",
- stemmed, aux);
- g_free (aux);
- }
-#endif
+
+ /* Log after stemming */
+ tracker_parser_message_hex (" After stemming",
+ stemmed, strlen (stemmed));
}
/* If stemmed wanted and succeeded, free previous and return it */
diff --git a/src/libtracker-fts/tracker-parser-utils.c b/src/libtracker-fts/tracker-parser-utils.c
index 503de1b..d2486ab 100644
--- a/src/libtracker-fts/tracker-parser-utils.c
+++ b/src/libtracker-fts/tracker-parser-utils.c
@@ -25,6 +25,7 @@
#include <unac.h>
#endif
+#include <libtracker-common/tracker-common.h>
#include "tracker-parser-utils.h"
gchar *
@@ -78,3 +79,34 @@ tracker_parser_unaccent_string (const gchar *str,
#endif
}
+
+
+#if TRACKER_PARSER_DEBUG_HEX
+void
+tracker_parser_message_hex (const gchar *message,
+ const gchar *str,
+ gsize str_length)
+{
+ gchar *hex_aux;
+ gchar *str_aux;
+
+ g_return_if_fail (message);
+ g_return_if_fail (str);
+ g_return_if_fail (str_length != 0);
+
+ /* String may not come NIL-terminated */
+ str_aux = g_malloc (str_length + 1);
+ memcpy (str_aux, str, str_length);
+ str_aux[str_length] = '\0';
+
+ /* Get hexadecimal representation of the input string */
+ hex_aux = tracker_strhex (str, str_length, ':');
+
+ /* Log it */
+ g_message ("%s: '%s' (%s)",
+ message, str_aux, hex_aux);
+
+ g_free (str_aux);
+ g_free (hex_aux);
+}
+#endif
diff --git a/src/libtracker-fts/tracker-parser-utils.h b/src/libtracker-fts/tracker-parser-utils.h
index 4e869b1..77eb662 100644
--- a/src/libtracker-fts/tracker-parser-utils.h
+++ b/src/libtracker-fts/tracker-parser-utils.h
@@ -28,6 +28,20 @@ gchar *tracker_parser_unaccent_string (const gchar *str,
gsize ilength,
gsize *p_olength);
+
+
+/* Define to 1 if you want to enable debugging logs showing HEX contents
+ * of the words being parsed */
+#define TRACKER_PARSER_DEBUG_HEX 0
+
+#if TRACKER_PARSER_DEBUG_HEX
+void tracker_parser_message_hex (const gchar *message,
+ const gchar *str,
+ gsize str_length);
+#else
+#define tracker_parser_message_hex(a,b,c)
+#endif
+
G_END_DECLS
#endif /* __TRACKER_PARSER_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]