gimp r26385 - in branches/soc-2008-tagging: . app/core app/widgets
- From: aurisj svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26385 - in branches/soc-2008-tagging: . app/core app/widgets
- Date: Tue, 5 Aug 2008 16:09:07 +0000 (UTC)
Author: aurisj
Date: Tue Aug 5 16:09:07 2008
New Revision: 26385
URL: http://svn.gnome.org/viewvc/gimp?rev=26385&view=rev
Log:
2008-08-05 Aurimas JuÅka <aurisj svn gnome org>
* app/core/gimptag.[ch]
* app/core/gimptagcache.c (gimp_tag_cache_load_text)
* app/widgets/gimptagentry.c (gimp_tag_entry_assign_tags): added rules
tag names.
Modified:
branches/soc-2008-tagging/ChangeLog
branches/soc-2008-tagging/app/core/gimptag.c
branches/soc-2008-tagging/app/core/gimptag.h
branches/soc-2008-tagging/app/core/gimptagcache.c
branches/soc-2008-tagging/app/widgets/gimptagentry.c
Modified: branches/soc-2008-tagging/app/core/gimptag.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptag.c (original)
+++ branches/soc-2008-tagging/app/core/gimptag.c Tue Aug 5 16:09:07 2008
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib-object.h>
+#include <string.h>
#include "core-types.h"
@@ -47,21 +48,28 @@
gimp_tag_new (const char *tag_string)
{
GimpTag *tag;
+ gchar *tag_name;
gchar *case_folded;
gchar *collate_key;
g_return_val_if_fail (tag_string != NULL, NULL);
- g_return_val_if_fail (gimp_tag_string_is_valid (tag_string), NULL);
+
+ tag_name = gimp_tag_string_make_valid (tag_string);
+ if (! tag_name)
+ {
+ return NULL;
+ }
tag = g_object_new (GIMP_TYPE_TAG, NULL);
- tag->tag = g_quark_from_string (tag_string);
+ tag->tag = g_quark_from_string (tag_name);
- case_folded = g_utf8_casefold (tag_string, -1);
+ case_folded = g_utf8_casefold (tag_name, -1);
collate_key = g_utf8_collate_key (case_folded, -1);
tag->collate_key = g_quark_from_string (collate_key);
g_free (collate_key);
g_free (case_folded);
+ g_free (tag_name);
return tag;
}
@@ -70,29 +78,31 @@
gimp_tag_try_new (const char *tag_string)
{
GimpTag *tag;
+ gchar *tag_name;
gchar *case_folded;
gchar *collate_key;
GQuark tag_quark;
GQuark collate_key_quark;
- if (! tag_string
- || ! gimp_tag_string_is_valid (tag_string))
+ tag_name = gimp_tag_string_make_valid (tag_string);
+ if (! tag_name)
{
- return NULL;
+ return NULL;
}
-
- tag_quark = g_quark_from_string (tag_string);
+ tag_quark = g_quark_from_string (tag_name);
if (! tag_quark)
{
+ g_free (tag_name);
return NULL;
}
- case_folded = g_utf8_casefold (tag_string, -1);
+ case_folded = g_utf8_casefold (tag_name, -1);
collate_key = g_utf8_collate_key (case_folded, -1);
collate_key_quark = g_quark_from_string (collate_key);
g_free (collate_key);
g_free (case_folded);
+ g_free (tag_name);
if (! collate_key_quark)
{
@@ -126,7 +136,7 @@
GimpTag *other)
{
g_return_val_if_fail (GIMP_IS_TAG (tag), FALSE);
- g_return_val_if_fail (GIMP_IS_TAG (tag), FALSE);
+ g_return_val_if_fail (GIMP_IS_TAG (other), FALSE);
return tag->tag == other->tag;
}
@@ -153,7 +163,6 @@
g_return_val_if_fail (GIMP_IS_TAG (tag), 0);
g_return_val_if_fail (tag_string != NULL, 0);
- g_return_val_if_fail (! gimp_tag_string_is_valid (tag_string), 0);
collate_key = g_quark_to_string (tag->collate_key);
case_folded = g_utf8_casefold (tag_string, -1);
@@ -166,15 +175,195 @@
}
gboolean
-gimp_tag_string_is_valid (const gchar *string)
+g_unichar_is_sentence_terminal (gunichar c)
{
- g_return_val_if_fail (string, FALSE);
+ switch (c)
+ {
+ /*
+ * sentence terminal
+ */
+
+ case 0x0021: /* (!) Po EXCLAMATION MARK */
+ case 0x002E: /* (.) Po FULL STOP */
+ case 0x003F: /* (?) Po QUESTION MARK */
+ case 0x0589: /* (Ö) Po ARMENIAN FULL STOP */
+ case 0x061F: /* (Ø) Po ARABIC QUESTION MARK */
+ case 0x06D4: /* (Û) Po ARABIC FULL STOP */
+ case 0x0700: /* (Ü) Po SYRIAC END OF PARAGRAPH */
+ case 0x0701: /* (Ü) Po SYRIAC SUPRALINEAR FULL STOP */
+ case 0x0702: /* (Ü) Po SYRIAC SUBLINEAR FULL STOP */
+ case 0x0964: /* (à) Po DEVANAGARI DANDA */
+ case 0x104A: /* (á) Po MYANMAR SIGN LITTLE SECTION */
+ case 0x104B: /* (á) Po MYANMAR SIGN SECTION */
+ case 0x1362: /* (á) Po ETHIOPIC FULL STOP */
+ case 0x1367: /* (á) Po ETHIOPIC QUESTION MARK */
+ case 0x1368: /* (á) Po ETHIOPIC PARAGRAPH SEPARATOR */
+ case 0x166E: /* (á) Po CANADIAN SYLLABICS FULL STOP */
+ case 0x1803: /* (á) Po MONGOLIAN FULL STOP */
+ case 0x1809: /* (á) Po MONGOLIAN MANCHU FULL STOP */
+ case 0x203C: /* (â) Po DOUBLE EXCLAMATION MARK */
+ case 0x203D: /* (â) Po INTERROBANG */
+ case 0x2047: /* (â) Po DOUBLE QUESTION MARK */
+ case 0x2048: /* (â) Po QUESTION EXCLAMATION MARK */
+ case 0x2049: /* (â) Po EXCLAMATION QUESTION MARK */
+ case 0x3002: /* (ã) Po IDEOGRAPHIC FULL STOP */
+ case 0xFE52: /* (ï) Po SMALL FULL STOP */
+ case 0xFE57: /* (ï) Po SMALL EXCLAMATION MARK */
+ case 0xFF01: /* (ï) Po FULLWIDTH EXCLAMATION MARK */
+ case 0xFF0E: /* (ï) Po FULLWIDTH FULL STOP */
+ case 0xFF1F: /* (ï) Po FULLWIDTH QUESTION MARK */
+ case 0xFF61: /* (ï) Po HALFWIDTH IDEOGRAPHIC FULL STOP */
+ return TRUE;
+
+ default:
+ return FALSE;
+ }
+}
- if (g_utf8_strchr (string, -1, ','))
+gboolean
+g_unichar_is_terminal_punctuation (gunichar c)
+{
+ switch (c)
{
- return FALSE;
+ /*
+ * sentence terminal
+ */
+
+ case 0x0021: /* (!) Po EXCLAMATION MARK */
+ case 0x002E: /* (.) Po FULL STOP */
+ case 0x003F: /* (?) Po QUESTION MARK */
+ case 0x0589: /* (Ö) Po ARMENIAN FULL STOP */
+ case 0x061F: /* (Ø) Po ARABIC QUESTION MARK */
+ case 0x06D4: /* (Û) Po ARABIC FULL STOP */
+ case 0x0700: /* (Ü) Po SYRIAC END OF PARAGRAPH */
+ case 0x0701: /* (Ü) Po SYRIAC SUPRALINEAR FULL STOP */
+ case 0x0702: /* (Ü) Po SYRIAC SUBLINEAR FULL STOP */
+ case 0x0964: /* (à) Po DEVANAGARI DANDA */
+ case 0x104A: /* (á) Po MYANMAR SIGN LITTLE SECTION */
+ case 0x104B: /* (á) Po MYANMAR SIGN SECTION */
+ case 0x1362: /* (á) Po ETHIOPIC FULL STOP */
+ case 0x1367: /* (á) Po ETHIOPIC QUESTION MARK */
+ case 0x1368: /* (á) Po ETHIOPIC PARAGRAPH SEPARATOR */
+ case 0x166E: /* (á) Po CANADIAN SYLLABICS FULL STOP */
+ case 0x1803: /* (á) Po MONGOLIAN FULL STOP */
+ case 0x1809: /* (á) Po MONGOLIAN MANCHU FULL STOP */
+ case 0x203C: /* (â) Po DOUBLE EXCLAMATION MARK */
+ case 0x203D: /* (â) Po INTERROBANG */
+ case 0x2047: /* (â) Po DOUBLE QUESTION MARK */
+ case 0x2048: /* (â) Po QUESTION EXCLAMATION MARK */
+ case 0x2049: /* (â) Po EXCLAMATION QUESTION MARK */
+ case 0x3002: /* (ã) Po IDEOGRAPHIC FULL STOP */
+ case 0xFE52: /* (ï) Po SMALL FULL STOP */
+ case 0xFE57: /* (ï) Po SMALL EXCLAMATION MARK */
+ case 0xFF01: /* (ï) Po FULLWIDTH EXCLAMATION MARK */
+ case 0xFF0E: /* (ï) Po FULLWIDTH FULL STOP */
+ case 0xFF1F: /* (ï) Po FULLWIDTH QUESTION MARK */
+ case 0xFF61: /* (ï) Po HALFWIDTH IDEOGRAPHIC FULL STOP */
+
+ /*
+ * B. Terminal_Punctuation but not in Sentence_Terminal:
+ */
+
+ case 0x002C: /* (,) Po COMMA */
+ case 0x003A: /* (:) Po COLON */
+ case 0x003B: /* (;) Po SEMICOLON */
+ case 0x037E: /* (Í) Po GREEK QUESTION MARK */
+ case 0x0387: /* (Î) Po GREEK ANO TELEIA */
+ case 0x060C: /* (Ø) Po ARABIC COMMA */
+ case 0x061B: /* (Ø) Po ARABIC SEMICOLON */
+ case 0x0703: /* (Ü) Po SYRIAC SUPRALINEAR COLON */
+ case 0x0704: /* (Ü) Po SYRIAC SUBLINEAR COLON */
+ case 0x0705: /* (Ü) Po SYRIAC HORIZONTAL COLON */
+ case 0x0706: /* (Ü) Po SYRIAC COLON SKEWED LEFT */
+ case 0x0707: /* (Ü) Po SYRIAC COLON SKEWED RIGHT */
+ case 0x0708: /* (Ü) Po SYRIAC SUPRALINEAR COLON SKEWED LEFT */
+ case 0x0709: /* (Ü) Po SYRIAC SUBLINEAR COLON SKEWED RIGHT */
+ case 0x070A: /* (Ü) Po SYRIAC CONTRACTION */
+ case 0x070C: /* (Ü) Po SYRIAC HARKLEAN METOBELUS */
+ case 0x0965: /* (à) Po DEVANAGARI DOUBLE DANDA */
+ case 0x0E5A: /* (à) Po THAI CHARACTER ANGKHANKHU */
+ case 0x0E5B: /* (à) Po THAI CHARACTER KHOMUT */
+ case 0x1361: /* (á) Po ETHIOPIC WORDSPACE */
+ case 0x1363: /* (á) Po ETHIOPIC COMMA */
+ case 0x1364: /* (á) Po ETHIOPIC SEMICOLON */
+ case 0x1365: /* (á) Po ETHIOPIC COLON */
+ case 0x1366: /* (á) Po ETHIOPIC PREFACE COLON */
+ case 0x166D: /* (á) Po CANADIAN SYLLABICS CHI SIGN */
+ case 0x16EB: /* (á) Po RUNIC SINGLE PUNCTUATION */
+ case 0x16EC: /* (á) Po RUNIC MULTIPLE PUNCTUATION */
+ case 0x16ED: /* (á) Po RUNIC CROSS PUNCTUATION */
+ case 0x17D4: /* (á) Po KHMER SIGN KHAN */
+ case 0x17D5: /* (á) Po KHMER SIGN BARIYOOSAN */
+ case 0x17D6: /* (á) Po KHMER SIGN CAMNUC PII KUUH */
+ case 0x17DA: /* (á) Po KHMER SIGN KOOMUUT */
+ case 0x1802: /* (á) Po MONGOLIAN COMMA */
+ case 0x1804: /* (á) Po MONGOLIAN COLON */
+ case 0x1805: /* (á) Po MONGOLIAN FOUR DOTS */
+ case 0x1808: /* (á) Po MONGOLIAN MANCHU COMMA */
+ case 0x1944: /* (á) Po LIMBU EXCLAMATION MARK */
+ case 0x1945: /* (á) Po LIMBU QUESTION MARK */
+ case 0x3001: /* (ã) Po IDEOGRAPHIC COMMA */
+ case 0xFE50: /* (ï) Po SMALL COMMA */
+ case 0xFE51: /* (ï) Po SMALL IDEOGRAPHIC COMMA */
+ case 0xFE54: /* (ï) Po SMALL SEMICOLON */
+ case 0xFE55: /* (ï) Po SMALL COLON */
+ case 0xFE56: /* (ï) Po SMALL QUESTION MARK */
+ case 0xFF0C: /* (ï) Po FULLWIDTH COMMA */
+ case 0xFF1A: /* (ï) Po FULLWIDTH COLON */
+ case 0xFF1B: /* (ï) Po FULLWIDTH SEMICOLON */
+ case 0xFF64: /* (ï) Po HALFWIDTH IDEOGRAPHIC COMMA */
+ return TRUE;
+
+ default:
+ return FALSE;
+ }
+}
+
+gchar *
+gimp_tag_string_make_valid (const gchar *string)
+{
+ gchar *tag;
+ GString *tag_string;
+ gchar *tag_cursor;
+ gunichar c;
+
+ g_return_val_if_fail (string, NULL);
+
+ tag = g_strdup (string);
+ tag = g_strstrip (tag);
+ if (! *tag)
+ {
+ g_free (tag);
+ return NULL;
}
- return TRUE;
+ tag_string = g_string_new ("");
+ tag_cursor = tag;
+ if (g_str_has_prefix (tag_cursor, GIMP_TAG_INTERNAL_PREFIX))
+ {
+ tag_cursor += strlen (GIMP_TAG_INTERNAL_PREFIX);
+ }
+ do
+ {
+ c = g_utf8_get_char (tag_cursor);
+ tag_cursor = g_utf8_next_char (tag_cursor);
+ if (g_unichar_isprint (c)
+ && ! g_unichar_is_terminal_punctuation (c))
+ {
+ g_string_append_unichar (tag_string, c);
+ }
+ } while (c);
+
+ g_free (tag);
+ tag = g_string_free (tag_string, FALSE);
+ tag = g_strstrip (tag);
+
+ if (! *tag)
+ {
+ g_free (tag);
+ return NULL;
+ }
+
+ return tag;
}
Modified: branches/soc-2008-tagging/app/core/gimptag.h
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptag.h (original)
+++ branches/soc-2008-tagging/app/core/gimptag.h Tue Aug 5 16:09:07 2008
@@ -24,6 +24,8 @@
#include "gimpobject.h"
+#define GIMP_TAG_INTERNAL_PREFIX "gimp:"
+
#define GIMP_TYPE_TAG (gimp_tag_get_type ())
#define GIMP_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TAG, GimpTag))
#define GIMP_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TAG, GimpTagClass))
@@ -62,7 +64,10 @@
gint gimp_tag_compare_with_string (GimpTag *tag,
const gchar *string);
-gboolean gimp_tag_string_is_valid (const gchar *tag_string);
+gchar * gimp_tag_string_make_valid (const gchar *tag_string);
+
+gboolean g_unichar_is_sentence_terminal (gunichar c);
+gboolean g_unichar_is_terminal_punctuation (gunichar c);
#endif // __GIMP_TAG_H__
Modified: branches/soc-2008-tagging/app/core/gimptagcache.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptagcache.c (original)
+++ branches/soc-2008-tagging/app/core/gimptagcache.c Tue Aug 5 16:09:07 2008
@@ -513,12 +513,17 @@
memcpy (buffer, text, text_len);
buffer[text_len] = '\0';
- printf ("assigning tag %s to %s\n", buffer,
- g_quark_to_string (parse_data->current_record.identifier));
-
tag = gimp_tag_new (buffer);
- parse_data->current_record.tags = g_list_append (parse_data->current_record.tags,
- tag);
+ if (tag)
+ {
+ parse_data->current_record.tags = g_list_append (parse_data->current_record.tags,
+ tag);
+ }
+ else
+ {
+ g_warning ("dropping invalid tag '%s' from '%s'\n", buffer,
+ g_quark_to_string (parse_data->current_record.identifier));
+ }
}
}
Modified: branches/soc-2008-tagging/app/widgets/gimptagentry.c
==============================================================================
--- branches/soc-2008-tagging/app/widgets/gimptagentry.c (original)
+++ branches/soc-2008-tagging/app/widgets/gimptagentry.c Tue Aug 5 16:09:07 2008
@@ -403,9 +403,9 @@
count = g_strv_length (parsed_tags);
for (i = 0; i < count; i++)
{
- if (gimp_tag_string_is_valid (parsed_tags[i]))
+ tag = gimp_tag_new (parsed_tags[i]);
+ if (tag)
{
- tag = gimp_tag_new (parsed_tags[i]);
tag_list = g_list_append (tag_list, tag);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]