gtranslator r3628 - in trunk/src: . translation-memory/berkeley
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtranslator r3628 - in trunk/src: . translation-memory/berkeley
- Date: Mon, 22 Sep 2008 09:39:49 +0000 (UTC)
Author: icq
Date: Mon Sep 22 09:39:49 2008
New Revision: 3628
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3628&view=rev
Log:
Squashed commit of the following:
commit 398d92461f7fb1a284cdb1f2d3caf26b85b41748
Author: Ignacio Casal Quinteiro <nacho resa gmail com>
Date: Thu Jul 31 15:57:23 2008 +0200
2008-07-31 Ignacio Casal Quinteiro <nacho ansalon>
* translation-memory/berkeley/berkeley.c
(gtranslator_berkeley_store):
* translation-memory/berkeley/db-words.c
(gtranslator_db_words_append):
* utils.c (check_good_word),
(gtranslator_utils_split_string_in_words):
Improved a lot the split_string_in_words func and fixed several
bug fixes.
Modified:
trunk/src/ChangeLog
trunk/src/translation-memory/berkeley/berkeley.c
trunk/src/translation-memory/berkeley/db-words.c
trunk/src/utils.c
Modified: trunk/src/translation-memory/berkeley/berkeley.c
==============================================================================
--- trunk/src/translation-memory/berkeley/berkeley.c (original)
+++ trunk/src/translation-memory/berkeley/berkeley.c Mon Sep 22 09:39:49 2008
@@ -91,6 +91,7 @@
words[i],
sz,
key);
+ g_strfreev (words);
}
return ok;
}
@@ -98,22 +99,28 @@
{
gboolean found = FALSE;
gint i = 0;
+ gchar *translation_collate;
GPtrArray *t = gtranslator_db_trans_read (ber->priv->trans,
key);
if (!t)
return FALSE;
+ translation_collate = g_utf8_collate_key (translation, -1);
// -1 because we know that last element is NULL
while (i < t->len - 1)
{
- if (g_utf8_collate (g_ptr_array_index (t, i), translation) == 0)
+ gchar *array_word = g_utf8_collate_key (g_ptr_array_index (t, i), -1);
+
+ if (strcmp (array_word, translation_collate) == 0)
{
found = TRUE;
break;
}
+ g_free (array_word);
i++;
}
+ g_free (translation_collate);
if (!found)
{
Modified: trunk/src/translation-memory/berkeley/db-words.c
==============================================================================
--- trunk/src/translation-memory/berkeley/db-words.c (original)
+++ trunk/src/translation-memory/berkeley/db-words.c Mon Sep 22 09:39:49 2008
@@ -138,6 +138,8 @@
value_buf[count] = value;
data.data = value_buf;
data.size = (count + 1) * sizeof(db_recno_t);
+
+ g_object_unref (keys);
}
error = gtranslator_db_base_put (GTR_DB_BASE (db_words),
Modified: trunk/src/utils.c
==============================================================================
--- trunk/src/utils.c (original)
+++ trunk/src/utils.c Mon Sep 22 09:39:49 2008
@@ -55,28 +55,8 @@
NULL
};
-static gchar *
-create_word_from_positions (const gchar *string,
- gint start,
- gint end)
-{
- gchar toret[end+1 - start];
- gint i = start;
- gint j = 0;
-
- while (i <= end)
- {
- toret[j] = string[i];
- j++;
- i++;
- }
- toret[j] = '\0';
-
- return g_strdup (toret);
-}
-
static gboolean
-check_good_word (const gchar *word)
+check_good_word (const gchar *word, gchar **badwords)
{
gboolean check = TRUE;
gchar *lower = g_utf8_strdown (word, -1);
@@ -84,12 +64,15 @@
while (badwords[i] != NULL)
{
- if (g_utf8_collate (lower, badwords[i]) == 0)
+ gchar *lower_collate = g_utf8_collate_key (lower, -1);
+
+ if (strcmp (lower_collate, badwords[i]) == 0)
{
check = FALSE;
break;
}
i++;
+ g_free (lower_collate);
}
return check;
}
@@ -110,7 +93,23 @@
GPtrArray *array;
gint char_len;
gint i = 0;
- gint start;
+ gchar *s;
+ static gchar **badwords_collate = NULL;
+
+ if (badwords_collate == NULL)
+ {
+ gint words_size = g_strv_length ((gchar **)badwords);
+ gint x = 0;
+
+ badwords_collate = g_new0 (gchar *, words_size);
+
+ while (badwords[x] != NULL)
+ {
+ badwords_collate[x] = g_utf8_collate_key (badwords[x], -1);
+ x++;
+ }
+ badwords_collate[x] = NULL;
+ }
char_len = g_utf8_strlen (string, -1);
attrs = g_new (PangoLogAttr, char_len + 1);
@@ -124,28 +123,26 @@
array = g_ptr_array_new ();
+ s = (gchar *)string;
while (i <= char_len)
{
+ gchar *start, *end;
+
if (attrs[i].is_word_start)
+ start = s;
+ if (attrs[i].is_word_end)
{
- start = i;
+ gchar *word;
- if (attrs[i].is_word_end)
- {
- gchar *word = create_word_from_positions (string, start, i);
-
- if (check_good_word (word))
- g_ptr_array_add (array, word);
- }
- }
- else if (attrs[i].is_word_end)
- {
- gchar *word = create_word_from_positions (string, start, i);
+ end = s;
+ word = g_strndup (start, end - start);
- if (check_good_word (word))
+ if (check_good_word (word, badwords_collate))
g_ptr_array_add (array, word);
}
+
i++;
+ s = g_utf8_next_char (s);
}
g_free (attrs);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]