aboutsummaryrefslogtreecommitdiff
path: root/lib/common.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-06-21 13:56:38 -0400
committerWilliam Hua <william.hua@canonical.com>2013-06-21 13:56:38 -0400
commitb7c785a8f7b5c071c6a55419286cb24d19735331 (patch)
tree2cf96ac1f76c17f6102dd48f0b224c47345d3723 /lib/common.vala
parent9d174c31bda88ec1abe97f20f34a62928c920d71 (diff)
downloadayatana-indicator-keyboard-b7c785a8f7b5c071c6a55419286cb24d19735331.tar.gz
ayatana-indicator-keyboard-b7c785a8f7b5c071c6a55419286cb24d19735331.tar.bz2
ayatana-indicator-keyboard-b7c785a8f7b5c071c6a55419286cb24d19735331.zip
Simplify abbreviations.
Diffstat (limited to 'lib/common.vala')
-rw-r--r--lib/common.vala66
1 files changed, 10 insertions, 56 deletions
diff --git a/lib/common.vala b/lib/common.vala
index 83652c8d..0e4e58e3 100644
--- a/lib/common.vala
+++ b/lib/common.vala
@@ -1,61 +1,15 @@
string get_abbreviation (string name) {
- string abbreviation = null;
-
- if (name != null) {
- char letters[2];
- var index = 0;
-
- for (var i = 0; i < name.length && index < 2; i++) {
- if (name[i].isupper ()) {
- letters[index++] = name[i];
- }
- }
-
- if (index < 2) {
- index = 0;
-
- for (var i = 0; i < name.length && index < 2; i++) {
- if (name[i].isalpha () && (i == 0 || !name[i - 1].isalpha ())) {
- letters[index++] = name[i++].toupper ();
- }
- }
-
- if (index < 2) {
- index = 0;
-
- for (var i = 0; i < name.length && index < 2; i++) {
- if (name[i].isalpha ()) {
- letters[index++] = name[i];
- }
- }
- }
- }
-
- if (index == 2) {
- abbreviation = @"$(letters[0])$(letters[1])";
- } else if (index == 1) {
- abbreviation = @"$(letters[0])";
+ var index = 0;
+ unichar first;
+ unichar second;
+
+ if (name.get_next_char (ref index, out first)) {
+ if (name.get_next_char (ref index, out second)) {
+ return @"$(first.toupper ())$second";
+ } else {
+ return @"$(first.toupper ())";
}
- }
-
- return abbreviation;
-}
-
-string? get_display_name (string? layout) {
- if (layout == null) {
- return null;
- }
-
- var language = Xkl.get_language_name (layout);
- var country = Xkl.get_country_name (layout);
-
- if (language != null && country != null) {
- return @"$language ($country)";
- } else if (language != null) {
- return language;
- } else if (country != null) {
- return country;
} else {
- return null;
+ return "";
}
}