gmime r1495 - in trunk: . util
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1495 - in trunk: . util
- Date: Tue, 7 Oct 2008 16:16:49 +0000 (UTC)
Author: fejj
Date: Tue Oct 7 16:16:48 2008
New Revision: 1495
URL: http://svn.gnome.org/viewvc/gmime?rev=1495&view=rev
Log:
2008-10-07 Jeffrey Stedfast <fejj novell com>
* util/gtrie.c (g_trie_search): Instead of returning the first
match, find instead the best match starting at the same starting
offset (e.g. if we have two patterns "abc" and "abcdef" and the
input buffer is "abcdefghi", we want to match "abcdef" rather than
just "abc").
(g_trie_quick_search): Renamed from the old g_trie_search().
Modified:
trunk/ChangeLog
trunk/util/gtrie.c
Modified: trunk/util/gtrie.c
==============================================================================
--- trunk/util/gtrie.c (original)
+++ trunk/util/gtrie.c Tue Oct 7 16:16:48 2008
@@ -329,12 +329,12 @@
*/
const char *
-g_trie_search (GTrie *trie, const char *buffer, size_t buflen, int *matched_id)
+g_trie_quick_search (GTrie *trie, const char *buffer, size_t buflen, int *matched_id)
{
const unsigned char *inptr, *inend, *prev, *pat;
register size_t inlen = buflen;
- struct _trie_state *q;
struct _trie_match *m = NULL;
+ struct _trie_state *q;
gunichar c;
inptr = (const unsigned char *) buffer;
@@ -350,6 +350,7 @@
pat = (const unsigned char *) buffer + buflen;
g_warning ("Invalid UTF-8 in buffer '%.*s' at %.*s",
buflen, buffer, pat - prev, prev);
+
pat = prev = inptr;
}
@@ -372,7 +373,7 @@
if (matched_id)
*matched_id = q->id;
- return (const char *) pat;
+ return pat;
}
}
@@ -382,6 +383,72 @@
return NULL;
}
+const char *
+g_trie_search (GTrie *trie, const char *buffer, size_t buflen, int *matched_id)
+{
+ const unsigned char *inptr, *inend, *prev, *pat;
+ register size_t inlen = buflen;
+ struct _trie_match *m = NULL;
+ struct _trie_state *q;
+ size_t matched = 0;
+ gunichar c;
+
+ inptr = (const unsigned char *) buffer;
+ inend = inptr + buflen;
+
+ q = &trie->root;
+ pat = prev = inptr;
+ while ((c = trie_utf8_getc (&inptr, inlen))) {
+ inlen = (inend - inptr);
+
+ if (c == 0xfffe) {
+ if (matched)
+ return pat;
+
+ prev = (inptr - 1);
+ pat = (const unsigned char *) buffer + buflen;
+ g_warning ("Invalid UTF-8 in buffer '%.*s' at %.*s",
+ buflen, buffer, pat - prev, prev);
+
+ pat = prev = inptr;
+ }
+
+ if (trie->icase)
+ c = g_unichar_tolower (c);
+
+ while (q != NULL && (m = g (q, c)) == NULL && matched == 0)
+ q = q->fail;
+
+ if (q == &trie->root) {
+ if (matched)
+ return pat;
+
+ pat = prev;
+ }
+
+ if (q == NULL) {
+ if (matched)
+ return pat;
+
+ q = &trie->root;
+ pat = inptr;
+ } else if (m != NULL) {
+ q = m->state;
+
+ if (q->final > matched) {
+ if (matched_id)
+ *matched_id = q->id;
+
+ matched = q->final;
+ }
+ }
+
+ prev = inptr;
+ }
+
+ return matched ? pat : NULL;
+}
+
#ifdef TEST
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]