blob: 56addbd4b9c513dd7efe7f7e2195a9e6dda104c0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#include "Configuration.h"
2#include <string.h>
3
4int
5Configuration::Compare(const Configuration& that) const
6{
7 int n;
8
9 n = locale.compare(that.locale);
10 if (n != 0) return n;
11
12 n = vendor.compare(that.vendor);
13 if (n != 0) return n;
14
15 n = orientation.compare(that.orientation);
16 if (n != 0) return n;
17
18 n = density.compare(that.density);
19 if (n != 0) return n;
20
21 n = touchscreen.compare(that.touchscreen);
22 if (n != 0) return n;
23
24 n = keyboard.compare(that.keyboard);
25 if (n != 0) return n;
26
27 n = navigation.compare(that.navigation);
28 if (n != 0) return n;
29
30 n = screenSize.compare(that.screenSize);
31 if (n != 0) return n;
32
33 return 0;
34}
35
36string
37Configuration::ToString() const
38{
39 string s;
40 if (locale.length() > 0) {
41 if (s.length() > 0) {
42 s += "-";
43 }
44 s += locale;
45 }
46 return s;
47}
48
49bool
50split_locale(const string& in, string* language, string* region)
51{
52 const int len = in.length();
53 if (len == 2) {
54 if (isalpha(in[0]) && isalpha(in[1])) {
55 *language = in;
56 region->clear();
57 return true;
58 } else {
59 return false;
60 }
61 }
62 else if (len == 5) {
63 if (isalpha(in[0]) && isalpha(in[1]) && (in[2] == '_' || in[2] == '-')
64 && isalpha(in[3]) && isalpha(in[4])) {
65 language->assign(in.c_str(), 2);
66 region->assign(in.c_str()+3, 2);
67 return true;
68 } else {
69 return false;
70 }
71 }
72 else {
73 return false;
74 }
75}
76