gucharmap r1649 - trunk/gucharmap
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gucharmap r1649 - trunk/gucharmap
- Date: Fri, 21 Mar 2008 10:50:22 +0000 (GMT)
Author: chpe
Date: Fri Mar 21 10:50:22 2008
New Revision: 1649
URL: http://svn.gnome.org/viewvc/gucharmap?rev=1649&view=rev
Log:
Move scripts strings to ro data.
Modified:
trunk/gucharmap/gen-guch-unicode-tables.pl
trunk/gucharmap/gucharmap-script-chapters-model.c
trunk/gucharmap/gucharmap-script-codepoint-list.c
trunk/gucharmap/unicode-scripts.h
Modified: trunk/gucharmap/gen-guch-unicode-tables.pl
==============================================================================
--- trunk/gucharmap/gen-guch-unicode-tables.pl (original)
+++ trunk/gucharmap/gen-guch-unicode-tables.pl Fri Mar 21 10:50:22 2008
@@ -779,23 +779,43 @@
print $out "typedef struct _UnicodeScript UnicodeScript;\n\n";
- print $out "static const gchar *unicode_script_list[] =\n";
- print $out "{\n";
+ print $out "/* for extraction by intltool */\n";
+ print $out "#if 0\n";
my $i = 0;
for my $script (sort keys %scripts)
{
$scripts{$script} = $i;
- print $out qq/ N_("$script"),\n/;
$i++;
+
+ print $out qq/ N_("$script"),\n/;
+ }
+ print $out "#endif /* 0 */\n\n";
+
+ print $out "static const gchar unicode_script_list_strings[] =\n";
+ my $offset = 0;
+ my %script_offsets;
+ for my $script (sort keys %scripts)
+ {
+ printf $out (qq/ "\%s\\0"\n/, $script);
+ $script_offsets{$script} = $offset;
+ $offset += length($script) + 1;
+ }
+ print $out " ;\n\n";
+ undef $offset;
+
+ print $out "static const guint16 unicode_script_list_offsets[] =\n";
+ print $out "{\n";
+ for my $script (sort keys %scripts)
+ {
+ printf $out (qq/ \%d,\n/, $script_offsets{$script});
}
- print $out " NULL\n";
print $out "};\n\n";
print $out "static const struct _UnicodeScript\n";
print $out "{\n";
print $out " gunichar start;\n";
print $out " gunichar end;\n";
- print $out " gint script_index; /* index into unicode_script_list */\n";
+ print $out " guint8 script_index; /* index into unicode_script_list_offsets */\n";
print $out "}\n";
print $out "unicode_scripts[] =\n";
print $out "{\n";
Modified: trunk/gucharmap/gucharmap-script-chapters-model.c
==============================================================================
--- trunk/gucharmap/gucharmap-script-chapters-model.c (original)
+++ trunk/gucharmap/gucharmap-script-chapters-model.c Fri Mar 21 10:50:22 2008
@@ -34,7 +34,7 @@
gucharmap_script_chapters_model_init (GucharmapScriptChaptersModel *model)
{
GtkListStore *store = GTK_LIST_STORE (model);
- const gchar **unicode_scripts = gucharmap_unicode_list_scripts ();
+ const gchar **unicode_scripts;
GtkTreeIter iter;
guint i;
GType types[] = {
@@ -44,6 +44,7 @@
gtk_list_store_set_column_types (store, G_N_ELEMENTS (types), types);
+ unicode_scripts = gucharmap_unicode_list_scripts ();
for (i = 0; unicode_scripts[i]; i++)
{
gtk_list_store_append (store, &iter);
@@ -52,6 +53,7 @@
CHAPTERS_LABEL_COL, _(unicode_scripts[i]),
-1);
}
+ g_free (unicode_scripts);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
CHAPTERS_LABEL_COL, GTK_SORT_ASCENDING);
Modified: trunk/gucharmap/gucharmap-script-codepoint-list.c
==============================================================================
--- trunk/gucharmap/gucharmap-script-codepoint-list.c (original)
+++ trunk/gucharmap/gucharmap-script-codepoint-list.c Fri Mar 21 10:50:22 2008
@@ -49,15 +49,15 @@
gint min, mid, max;
min = 0;
- max = sizeof (unicode_script_list) / sizeof (gchar *) - 2; /* itâs NULL-terminated */
+ max = G_N_ELEMENTS (unicode_script_list_offsets) - 1;
while (max >= min)
{
mid = (min + max) / 2;
- if (strcmp (script, unicode_script_list[mid]) > 0)
+ if (strcmp (script, unicode_script_list_strings + unicode_script_list_offsets[mid]) > 0)
min = mid + 1;
- else if (strcmp (script, unicode_script_list[mid]) < 0)
+ else if (strcmp (script, unicode_script_list_strings + unicode_script_list_offsets[mid]) < 0)
max = mid - 1;
else
return mid;
@@ -386,14 +386,28 @@
/**
* gucharmap_unicode_list_scripts:
*
- * Return value: NULL-terminated array of script names. These have been
- * marked for translation with N_(). Neither the list nor the scripts
- * should be modified by the caller.
+ * Return value: %NULL-terminated array of script names. These have been
+ * marked for translation with N_().
+ * The strings in the array are owned by gucharmap and should not be
+ * modified or free; the array itself however is allocated and should
+ * be freed with g_free().
+ *
+ * Returns: a newly allocated %NULL-terminated array of strings
**/
-G_CONST_RETURN gchar **
+const gchar **
gucharmap_unicode_list_scripts (void)
{
- return unicode_script_list;
+ const char **scripts;
+ guint i;
+
+ scripts = (const char **) g_new (char*, G_N_ELEMENTS (unicode_script_list_offsets) + 1);
+ for (i = 0; i < G_N_ELEMENTS (unicode_script_list_offsets); ++i)
+ {
+ scripts[i] = unicode_script_list_strings + unicode_script_list_offsets[i];
+ }
+ scripts[i] = NULL;
+
+ return scripts;
}
/**
@@ -422,7 +436,7 @@
else if (wc < unicode_scripts[mid].start)
max = mid - 1;
else
- return unicode_script_list[unicode_scripts[mid].script_index];
+ return unicode_script_list_strings + unicode_script_list_offsets[unicode_scripts[mid].script_index];
}
/* Unicode assigns "Common" as the script name for any character not
Modified: trunk/gucharmap/unicode-scripts.h
==============================================================================
--- trunk/gucharmap/unicode-scripts.h (original)
+++ trunk/gucharmap/unicode-scripts.h Fri Mar 21 10:50:22 2008
@@ -11,8 +11,8 @@
typedef struct _UnicodeScript UnicodeScript;
-static const gchar *unicode_script_list[] =
-{
+/* for extraction by intltool */
+#if 0
N_("Arabic"),
N_("Armenian"),
N_("Balinese"),
@@ -79,14 +79,152 @@
N_("Tifinagh"),
N_("Ugaritic"),
N_("Yi"),
- NULL
+#endif /* 0 */
+
+static const gchar unicode_script_list_strings[] =
+ "Arabic\0"
+ "Armenian\0"
+ "Balinese\0"
+ "Bengali\0"
+ "Bopomofo\0"
+ "Braille\0"
+ "Buginese\0"
+ "Buhid\0"
+ "Canadian Aboriginal\0"
+ "Cherokee\0"
+ "Common\0"
+ "Coptic\0"
+ "Cuneiform\0"
+ "Cypriot\0"
+ "Cyrillic\0"
+ "Deseret\0"
+ "Devanagari\0"
+ "Ethiopic\0"
+ "Georgian\0"
+ "Glagolitic\0"
+ "Gothic\0"
+ "Greek\0"
+ "Gujarati\0"
+ "Gurmukhi\0"
+ "Han\0"
+ "Hangul\0"
+ "Hanunoo\0"
+ "Hebrew\0"
+ "Hiragana\0"
+ "Inherited\0"
+ "Kannada\0"
+ "Katakana\0"
+ "Kharoshthi\0"
+ "Khmer\0"
+ "Lao\0"
+ "Latin\0"
+ "Limbu\0"
+ "Linear B\0"
+ "Malayalam\0"
+ "Mongolian\0"
+ "Myanmar\0"
+ "New Tai Lue\0"
+ "Nko\0"
+ "Ogham\0"
+ "Old Italic\0"
+ "Old Persian\0"
+ "Oriya\0"
+ "Osmanya\0"
+ "Phags Pa\0"
+ "Phoenician\0"
+ "Runic\0"
+ "Shavian\0"
+ "Sinhala\0"
+ "Syloti Nagri\0"
+ "Syriac\0"
+ "Tagalog\0"
+ "Tagbanwa\0"
+ "Tai Le\0"
+ "Tamil\0"
+ "Telugu\0"
+ "Thaana\0"
+ "Thai\0"
+ "Tibetan\0"
+ "Tifinagh\0"
+ "Ugaritic\0"
+ "Yi\0"
+ ;
+
+static const guint16 unicode_script_list_offsets[] =
+{
+ 0,
+ 7,
+ 16,
+ 25,
+ 33,
+ 42,
+ 50,
+ 59,
+ 65,
+ 85,
+ 94,
+ 101,
+ 108,
+ 118,
+ 126,
+ 135,
+ 143,
+ 154,
+ 163,
+ 172,
+ 183,
+ 190,
+ 196,
+ 205,
+ 214,
+ 218,
+ 225,
+ 233,
+ 240,
+ 249,
+ 259,
+ 267,
+ 276,
+ 287,
+ 293,
+ 297,
+ 303,
+ 309,
+ 318,
+ 328,
+ 338,
+ 346,
+ 358,
+ 362,
+ 368,
+ 379,
+ 391,
+ 397,
+ 405,
+ 414,
+ 425,
+ 431,
+ 439,
+ 447,
+ 460,
+ 467,
+ 475,
+ 484,
+ 491,
+ 497,
+ 504,
+ 511,
+ 516,
+ 524,
+ 533,
+ 542,
};
static const struct _UnicodeScript
{
gunichar start;
gunichar end;
- gint script_index; /* index into unicode_script_list */
+ guint8 script_index; /* index into unicode_script_list_offsets */
}
unicode_scripts[] =
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]