[gnumeric] Implement exception handling for first letter capitalization. [#613768]



commit c1dea2536f06a58981da59a9a97ab2bab188eb09
Author: Andreas J. Guelzow <aguelzow math concordia ab ca>
Date:   Fri Mar 26 10:03:05 2010 -0600

    Implement exception handling for first letter capitalization. [#613768]
    
    2010-03-26 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* auto-correct.c (autocorrect_first_letter_exception): new
    	(autocorrect_first_letter): don't consider symbols without following
    	  whitespace sentence enders and check for exceptions.

 NEWS                     |    2 +-
 src/tools/ChangeLog      |    6 +++++
 src/tools/auto-correct.c |   49 ++++++++++++++++++++++++++++++++++++---------
 3 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/NEWS b/NEWS
index 08520cd..82b9e2a 100644
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,7 @@ Andreas:
 	* Fix build with --disable-solver. [#612820]
 	* Fix column and row header display under Quartz. [#600085]
 	* Fix preferences in gconf-less situations. [#613523]
-	* Implement first letter capitalization w/o exceptions. [#613768]
+	* Implement first letter capitalization. [#613768]
 
 Morten:
 	* Improve object sizing tooltip positioning a bit.
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index 396bda3..4eaa357 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,5 +1,11 @@
 2010-03-26 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* auto-correct.c (autocorrect_first_letter_exception): new 
+	(autocorrect_first_letter): don't consider symbols without following
+	  whitespace sentence enders and check for exceptions.
+
+2010-03-26 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* auto-correct.c (autocorrect_first_letter): implement
 	
 2010-03-23 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/src/tools/auto-correct.c b/src/tools/auto-correct.c
index 7694fa2..df7907b 100644
--- a/src/tools/auto-correct.c
+++ b/src/tools/auto-correct.c
@@ -151,15 +151,38 @@ autocorrect_initial_caps (const char *src)
 	return res;
 }
 
+static gboolean
+autocorrect_first_letter_exception (const char *start, const char *end)
+{
+	GSList *l = gnm_conf_get_autocorrect_first_letter_list ();
+	char *text;
+
+	if (l == NULL)
+		return FALSE;
+
+	text = g_strndup (start, end - start + 1);
+
+	for (; l != NULL; l = l->next) {
+		if (g_str_has_suffix(text, l->data)) {
+			g_free (text);
+			return TRUE;
+		}
+	}
+	
+	g_free (text);
+	return FALSE;
+}
+
 
 static char *
-autocorrect_first_letter (G_GNUC_UNUSED const char *src)
+autocorrect_first_letter (const char *src)
 {
 	const char * last_end = NULL;
 	const char *last_copy = src;
 	const char *this;
 	GString *gstr = NULL;
 	gboolean seen_text = FALSE;
+	gboolean seen_white = FALSE;
 
 	for (this = src; '\0' != *this; this = g_utf8_next_char (this)) {
 		gunichar this_char = g_utf8_get_char (this);
@@ -171,16 +194,22 @@ autocorrect_first_letter (G_GNUC_UNUSED const char *src)
 				   type == G_UNICODE_BREAK_CLOSE_PUNCTUATION ||
 				   type == G_UNICODE_BREAK_EXCLAMATION))
 			last_end = this;
+		else if ((last_end != NULL) && g_unichar_isspace (this_char))
+			seen_white = TRUE;
 		else if ((last_end != NULL) && !g_unichar_isspace (this_char)) {
-			gunichar new = g_unichar_totitle (this_char);
-			
-			if (this_char != new) {
-				if (gstr == NULL)
-					gstr = g_string_new (NULL);
-				g_string_append_len (gstr, last_copy, 
-						     this - last_copy);
-				g_string_append_unichar (gstr, new);
-				last_copy = g_utf8_next_char (this);
+			if (seen_white) {
+				gunichar new = g_unichar_totitle (this_char);
+				
+				if ((this_char != new) && 
+				    !autocorrect_first_letter_exception (src, last_end)) {
+					if (gstr == NULL)
+						gstr = g_string_new (NULL);
+					g_string_append_len (gstr, last_copy, 
+							     this - last_copy);
+					g_string_append_unichar (gstr, new);
+					last_copy = g_utf8_next_char (this);
+				}
+				seen_white = FALSE;
 			}
 			last_end = NULL;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]