ea8380baa720b7d7221335126c90da3ad7861ba1
[platform/upstream/v8.git] / src / i18n.h
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 // limitations under the License.
5
6 #ifndef V8_I18N_H_
7 #define V8_I18N_H_
8
9 #include "src/handles.h"
10 #include "unicode/uversion.h"
11
12 namespace U_ICU_NAMESPACE {
13 class BreakIterator;
14 class Collator;
15 class DecimalFormat;
16 class SimpleDateFormat;
17 }
18
19 namespace v8 {
20 namespace internal {
21
22 // Forward declarations.
23 class ObjectTemplateInfo;
24
25 class I18N {
26  public:
27   // Creates an ObjectTemplate with one internal field.
28   static Handle<ObjectTemplateInfo> GetTemplate(Isolate* isolate);
29
30   // Creates an ObjectTemplate with two internal fields.
31   static Handle<ObjectTemplateInfo> GetTemplate2(Isolate* isolate);
32
33  private:
34   I18N();
35 };
36
37
38 class DateFormat {
39  public:
40   // Create a formatter for the specificied locale and options. Returns the
41   // resolved settings for the locale / options.
42   static icu::SimpleDateFormat* InitializeDateTimeFormat(
43       Isolate* isolate,
44       Handle<String> locale,
45       Handle<JSObject> options,
46       Handle<JSObject> resolved);
47
48   // Unpacks date format object from corresponding JavaScript object.
49   static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate,
50                                                  Handle<JSObject> obj);
51
52   // Release memory we allocated for the DateFormat once the JS object that
53   // holds the pointer gets garbage collected.
54   static void DeleteDateFormat(
55       const v8::WeakCallbackData<v8::Value, void>& data);
56
57  private:
58   DateFormat();
59 };
60
61
62 class NumberFormat {
63  public:
64   // Create a formatter for the specificied locale and options. Returns the
65   // resolved settings for the locale / options.
66   static icu::DecimalFormat* InitializeNumberFormat(
67       Isolate* isolate,
68       Handle<String> locale,
69       Handle<JSObject> options,
70       Handle<JSObject> resolved);
71
72   // Unpacks number format object from corresponding JavaScript object.
73   static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate,
74                                                 Handle<JSObject> obj);
75
76   // Release memory we allocated for the NumberFormat once the JS object that
77   // holds the pointer gets garbage collected.
78   static void DeleteNumberFormat(
79       const v8::WeakCallbackData<v8::Value, void>& data);
80
81  private:
82   NumberFormat();
83 };
84
85
86 class Collator {
87  public:
88   // Create a collator for the specificied locale and options. Returns the
89   // resolved settings for the locale / options.
90   static icu::Collator* InitializeCollator(
91       Isolate* isolate,
92       Handle<String> locale,
93       Handle<JSObject> options,
94       Handle<JSObject> resolved);
95
96   // Unpacks collator object from corresponding JavaScript object.
97   static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj);
98
99   // Release memory we allocated for the Collator once the JS object that holds
100   // the pointer gets garbage collected.
101   static void DeleteCollator(
102       const v8::WeakCallbackData<v8::Value, void>& data);
103
104  private:
105   Collator();
106 };
107
108 class BreakIterator {
109  public:
110   // Create a BreakIterator for the specificied locale and options. Returns the
111   // resolved settings for the locale / options.
112   static icu::BreakIterator* InitializeBreakIterator(
113       Isolate* isolate,
114       Handle<String> locale,
115       Handle<JSObject> options,
116       Handle<JSObject> resolved);
117
118   // Unpacks break iterator object from corresponding JavaScript object.
119   static icu::BreakIterator* UnpackBreakIterator(Isolate* isolate,
120                                                  Handle<JSObject> obj);
121
122   // Release memory we allocated for the BreakIterator once the JS object that
123   // holds the pointer gets garbage collected.
124   static void DeleteBreakIterator(
125       const v8::WeakCallbackData<v8::Value, void>& data);
126
127  private:
128   BreakIterator();
129 };
130
131 } }  // namespace v8::internal
132
133 #endif  // V8_I18N_H_