forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformIntlDummy.cpp
More file actions
167 lines (138 loc) · 4.78 KB
/
PlatformIntlDummy.cpp
File metadata and controls
167 lines (138 loc) · 4.78 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "hermes/Platform/Intl/PlatformIntl.h"
#if HERMES_PLATFORM_INTL == HERMES_PLATFORM_INTL_DUMMY
#include <deque>
#include <string>
#include <unordered_map>
using namespace ::facebook;
using namespace ::hermes;
namespace hermes {
namespace platform_intl {
vm::CallResult<std::vector<std::u16string>> getCanonicalLocales(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales) {
return std::vector<std::u16string>{u"fr-FR", u"es-ES"};
}
vm::CallResult<std::u16string> toLocaleLowerCase(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const std::u16string &str) {
return std::u16string(u"lowered");
}
vm::CallResult<std::u16string> toLocaleUpperCase(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const std::u16string &str) {
return std::u16string(u"uppered");
}
struct Collator::Impl {
std::u16string locale;
};
Collator::Collator() : impl_(std::make_unique<Impl>()) {}
Collator::~Collator() {}
vm::CallResult<std::vector<std::u16string>> Collator::supportedLocalesOf(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
return std::vector<std::u16string>{u"en-CA", u"de-DE"};
}
vm::ExecutionStatus Collator::initialize(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
impl_->locale = u"en-US";
return vm::ExecutionStatus::RETURNED;
}
Options Collator::resolvedOptions() noexcept {
Options options;
options.emplace(u"locale", Option(impl_->locale));
options.emplace(u"numeric", Option(false));
return options;
}
double Collator::compare(
const std::u16string &x,
const std::u16string &y) noexcept {
return x.compare(y);
}
struct DateTimeFormat::Impl {
std::u16string locale;
};
DateTimeFormat::DateTimeFormat() : impl_(std::make_unique<Impl>()) {}
DateTimeFormat::~DateTimeFormat() {}
vm::CallResult<std::vector<std::u16string>> DateTimeFormat::supportedLocalesOf(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
return std::vector<std::u16string>{u"en-CA", u"de-DE"};
}
vm::ExecutionStatus DateTimeFormat::initialize(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
impl_->locale = u"en-US";
return vm::ExecutionStatus::RETURNED;
}
Options DateTimeFormat::resolvedOptions() noexcept {
Options options;
options.emplace(u"locale", Option(impl_->locale));
options.emplace(u"numeric", Option(false));
return options;
}
std::u16string DateTimeFormat::format(double jsTimeValue) noexcept {
auto s = std::to_string(jsTimeValue);
return std::u16string(s.begin(), s.end());
}
std::vector<std::unordered_map<std::u16string, std::u16string>>
DateTimeFormat::formatToParts(double jsTimeValue) noexcept {
std::unordered_map<std::u16string, std::u16string> part;
part[u"type"] = u"integer";
// This isn't right, but I didn't want to do more work for a stub.
std::string s = std::to_string(jsTimeValue);
part[u"value"] = {s.begin(), s.end()};
return std::vector<std::unordered_map<std::u16string, std::u16string>>{part};
}
struct NumberFormat::Impl {
std::u16string locale;
};
NumberFormat::NumberFormat() : impl_(std::make_unique<Impl>()) {}
NumberFormat::~NumberFormat() {}
vm::CallResult<std::vector<std::u16string>> NumberFormat::supportedLocalesOf(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
return std::vector<std::u16string>{u"en-CA", u"de-DE"};
}
vm::ExecutionStatus NumberFormat::initialize(
vm::Runtime *runtime,
const std::vector<std::u16string> &locales,
const Options &options) noexcept {
impl_->locale = u"en-US";
return vm::ExecutionStatus::RETURNED;
}
Options NumberFormat::resolvedOptions() noexcept {
Options options;
options.emplace(u"locale", Option(impl_->locale));
options.emplace(u"numeric", Option(false));
return options;
}
std::u16string NumberFormat::format(double number) noexcept {
auto s = std::to_string(number);
return std::u16string(s.begin(), s.end());
}
std::vector<std::unordered_map<std::u16string, std::u16string>>
NumberFormat::formatToParts(double number) noexcept {
std::unordered_map<std::u16string, std::u16string> part;
part[u"type"] = u"integer";
// This isn't right, but I didn't want to do more work for a stub.
std::string s = std::to_string(number);
part[u"value"] = {s.begin(), s.end()};
return std::vector<std::unordered_map<std::u16string, std::u16string>>{part};
}
} // namespace platform_intl
} // namespace hermes
#endif