summaryrefslogtreecommitdiffstats
path: root/tools/localize/Configuration.cpp
blob: 56addbd4b9c513dd7efe7f7e2195a9e6dda104c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Configuration.h"
#include <string.h>

int
Configuration::Compare(const Configuration& that) const
{
    int n;

    n = locale.compare(that.locale);
    if (n != 0) return n;

    n = vendor.compare(that.vendor);
    if (n != 0) return n;

    n = orientation.compare(that.orientation);
    if (n != 0) return n;

    n = density.compare(that.density);
    if (n != 0) return n;

    n = touchscreen.compare(that.touchscreen);
    if (n != 0) return n;

    n = keyboard.compare(that.keyboard);
    if (n != 0) return n;

    n = navigation.compare(that.navigation);
    if (n != 0) return n;

    n = screenSize.compare(that.screenSize);
    if (n != 0) return n;

    return 0;
}

string
Configuration::ToString() const
{
    string s;
    if (locale.length() > 0) {
        if (s.length() > 0) {
            s += "-";
        }
        s += locale;
    }
    return s;
}

bool
split_locale(const string& in, string* language, string* region)
{
    const int len = in.length();
    if (len == 2) {
        if (isalpha(in[0]) && isalpha(in[1])) {
            *language = in;
            region->clear();
            return true;
        } else {
            return false;
        }
    }
    else if (len == 5) {
        if (isalpha(in[0]) && isalpha(in[1]) && (in[2] == '_' || in[2] == '-')
                && isalpha(in[3]) && isalpha(in[4])) {
            language->assign(in.c_str(), 2);
            region->assign(in.c_str()+3, 2);
            return true;
        } else {
            return false;
        }
    }
    else {
        return false;
    }
}