[evolution-data-server] libebook: Really extract the 2-letter country code



commit 518bfd3384b645520413d8ba56803aa2d724e0fa
Author: Mathias Hasselmann <mathias openismus com>
Date:   Wed Feb 6 19:09:12 2013 +0100

    libebook: Really extract the 2-letter country code
    
    Previous code took the locale-ids's language code
    instead of the country code.

 addressbook/libebook/e-phone-number-private.cpp |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/libebook/e-phone-number-private.cpp b/addressbook/libebook/e-phone-number-private.cpp
index 781e5b7..86c4e52 100644
--- a/addressbook/libebook/e-phone-number-private.cpp
+++ b/addressbook/libebook/e-phone-number-private.cpp
@@ -102,11 +102,17 @@ e_phone_number_make_region_code (const gchar *region_code)
 		/* From outside this is a C library, so we better consult the
 		 * C infrastructure instead of std::locale, which might divert. */
 		std::string current_region = setlocale (LC_ADDRESS, NULL);
+		const std::string::size_type uscore = current_region.find ('_');
 
-		const std::string::size_type underscore = current_region.find ('_');
+		if (uscore != std::string::npos) {
+			const std::string::size_type n = std::min (uscore + 3, current_region.length ());
 
-		if (underscore != std::string::npos)
-			current_region.resize (underscore);
+			if (n == current_region.length() || not ::isalpha(current_region.at(n)))
+				current_region = current_region.substr (uscore + 1, 2);
+		}
+
+		if (current_region.length() != 2)
+			return "US";
 
 		return current_region;
 	}


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