Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Locale_ss.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2006. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: Locale.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
3D Locale (Polygon) Object
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Locale_ss.h
"
17
18
void
Print
(
const
char
* fmt, ...);
19
20
// +--------------------------------------------------------------------+
21
22
static
List<Locale>
locales;
23
24
// +--------------------------------------------------------------------+
25
26
Locale::Locale
(
const
char
* l,
const
char
* c,
const
char
* v)
27
{
28
ZeroMemory(
this
,
sizeof
(
Locale
));
29
if
(l && *l) {
30
strncpy_s(
language
, l, 6);
31
char
* p =
language
;
32
while
(*p) {
33
*p = tolower(*p);
34
p++;
35
}
36
}
37
38
if
(c && *c) {
39
strncpy_s(
country
, c, 6);
40
char
* p =
country
;
41
while
(*p) {
42
*p = toupper(*p);
43
p++;
44
}
45
}
46
47
if
(v && *v) {
48
strncpy_s(
variant
, v, 6);
49
char
* p =
variant
;
50
while
(*p) {
51
*p = tolower(*p);
52
p++;
53
}
54
}
55
56
locales.
append
(
this
);
57
}
58
59
// +--------------------------------------------------------------------+
60
61
Locale::~Locale
()
62
{
63
locales.
remove
(
this
);
64
}
65
66
// +--------------------------------------------------------------------+
67
68
int
69
Locale::operator ==
(
const
Locale
& that)
const
70
{
71
if
(
this
== &that)
return
1;
72
73
return
!_stricmp(
language
, that.
language
) &&
74
!_stricmp(
country
, that.
country
) &&
75
!_stricmp(
variant
, that.
variant
);
76
}
77
78
// +--------------------------------------------------------------------+
79
80
Locale
*
81
Locale::ParseLocale
(
const
char
* str)
82
{
83
if
(str && *str) {
84
int
i = 0;
85
char
s1[4];
86
char
s2[4];
87
char
s3[4];
88
89
while
(*str && *str !=
'_'
&& i < 3) {
90
s1[i] = *str++;
91
i++;
92
}
93
s1[i] = 0;
94
i = 0;
95
96
if
(*str ==
'_'
)
97
str++;
98
99
while
(*str && *str !=
'_'
&& i < 3) {
100
s2[i] = *str++;
101
i++;
102
}
103
s2[i] = 0;
104
i = 0;
105
106
if
(*str ==
'_'
)
107
str++;
108
109
while
(*str && *str !=
'_'
&& i < 3) {
110
s3[i] = *str++;
111
i++;
112
}
113
s3[i] = 0;
114
i = 0;
115
116
return
CreateLocale
(s1, s2, s3);
117
}
118
119
return
0;
120
}
121
122
// +--------------------------------------------------------------------+
123
124
Locale
*
125
Locale::CreateLocale
(
const
char
* l,
const
char
* c,
const
char
* v)
126
{
127
ListIter<Locale>
iter = locales;
128
while
(++iter) {
129
Locale
* loc = iter.
value
();
130
if
(!_stricmp(l, loc->
GetLanguage
())) {
131
if
(c && *c) {
132
if
(!_stricmp(c, loc->
GetCountry
())) {
133
if
(v && *v) {
134
if
(!_stricmp(v, loc->
GetVariant
())) {
135
return
loc;
136
}
137
}
138
else
{
139
return
loc;
140
}
141
}
142
}
143
else
{
144
return
loc;
145
}
146
}
147
}
148
149
if
(l[0]) {
150
if
(c[0]) {
151
if
(v[0]) {
152
return
new
(__FILE__,__LINE__)
Locale
(l, c, v);
153
}
154
return
new
(__FILE__,__LINE__)
Locale
(l, c);
155
}
156
return
new
(__FILE__,__LINE__)
Locale
(l);
157
}
158
159
return
0;
160
}
161
162
// +--------------------------------------------------------------------+
163
164
const
List<Locale>
&
165
Locale::GetAllLocales
()
166
{
167
return
locales;
168
}
169
170
// +--------------------------------------------------------------------+
171
172
const
Text
173
Locale::GetFullCode
()
const
174
{
175
Text
result =
language
;
176
if
(*
country
) {
177
result.
append
(
"_"
);
178
result.
append
(
country
);
179
180
if
(*
variant
) {
181
result.
append
(
"_"
);
182
result.
append
(
variant
);
183
}
184
}
185
return
result;
186
}
187
188
// +--------------------------------------------------------------------+
189
190
static
const
char
* languages[] = {
191
"en"
,
"English"
,
192
"fr"
,
"French"
,
193
"de"
,
"German"
,
194
"it"
,
"Italian"
,
195
"pt"
,
"Portuguese"
,
196
"ru"
,
"Russian"
,
197
"es"
,
"Spanish"
198
};
199
200
static
const
char
* countries[] = {
201
"US"
,
"USA"
,
202
"CA"
,
"Canada"
,
203
"FR"
,
"France"
,
204
"DE"
,
"Germany"
,
205
"IT"
,
"Italy"
,
206
"PT"
,
"Portugal"
,
207
"RU"
,
"Russia"
,
208
"ES"
,
"Spain"
,
209
"UK"
,
"United Kingdom"
210
};
211
212
const
Text
213
Locale::GetDisplayName
()
const
214
{
215
Text
result;
216
if
(*
language
) {
217
for
(
int
i = 0; i < 14; i += 2) {
218
if
(!_stricmp(
language
, languages[i])) {
219
result = languages[i+1];
220
break
;
221
}
222
}
223
224
if
(*
country
) {
225
for
(
int
i = 0; i < 18; i += 2) {
226
if
(!_stricmp(
country
, countries[i])) {
227
result.
append
(
" - "
);
228
result.
append
(countries[i+1]);
229
break
;
230
}
231
}
232
}
233
234
}
235
return
result;
236
}
237
Magic2
Locale_ss.cpp
Generated on Tue Jun 5 2012 20:46:15 for Starshatter_Open by
1.8.1