Move i18n collator code to runtime.
[platform/upstream/v8.git] / src / i18n.h
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // limitations under the License.
28
29 #ifndef V8_I18N_H_
30 #define V8_I18N_H_
31
32 #include "unicode/uversion.h"
33 #include "v8.h"
34
35 namespace U_ICU_NAMESPACE {
36 class Collator;
37 class DecimalFormat;
38 class SimpleDateFormat;
39 }
40
41 namespace v8 {
42 namespace internal {
43
44 class I18N {
45  public:
46   // Creates an ObjectTemplate with one internal field.
47   static Handle<ObjectTemplateInfo> GetTemplate(Isolate* isolate);
48
49   // Creates an ObjectTemplate with two internal fields.
50   static Handle<ObjectTemplateInfo> GetTemplate2(Isolate* isolate);
51
52  private:
53   I18N();
54 };
55
56
57 class DateFormat {
58  public:
59   // Create a formatter for the specificied locale and options. Returns the
60   // resolved settings for the locale / options.
61   static icu::SimpleDateFormat* InitializeDateTimeFormat(
62       Isolate* isolate,
63       Handle<String> locale,
64       Handle<JSObject> options,
65       Handle<JSObject> resolved);
66
67   // Unpacks date format object from corresponding JavaScript object.
68   static icu::SimpleDateFormat* UnpackDateFormat(Isolate* isolate,
69                                                  Handle<JSObject> obj);
70
71   // Release memory we allocated for the DateFormat once the JS object that
72   // holds the pointer gets garbage collected.
73   static void DeleteDateFormat(v8::Isolate* isolate,
74                                Persistent<v8::Object>* object,
75                                void* param);
76  private:
77   DateFormat();
78 };
79
80
81 class NumberFormat {
82  public:
83   // Create a formatter for the specificied locale and options. Returns the
84   // resolved settings for the locale / options.
85   static icu::DecimalFormat* InitializeNumberFormat(
86       Isolate* isolate,
87       Handle<String> locale,
88       Handle<JSObject> options,
89       Handle<JSObject> resolved);
90
91   // Unpacks number format object from corresponding JavaScript object.
92   static icu::DecimalFormat* UnpackNumberFormat(Isolate* isolate,
93                                                 Handle<JSObject> obj);
94
95   // Release memory we allocated for the NumberFormat once the JS object that
96   // holds the pointer gets garbage collected.
97   static void DeleteNumberFormat(v8::Isolate* isolate,
98                                  Persistent<v8::Object>* object,
99                                  void* param);
100  private:
101   NumberFormat();
102 };
103
104
105 class Collator {
106  public:
107   // Create a collator for the specificied locale and options. Returns the
108   // resolved settings for the locale / options.
109   static icu::Collator* InitializeCollator(
110       Isolate* isolate,
111       Handle<String> locale,
112       Handle<JSObject> options,
113       Handle<JSObject> resolved);
114
115   // Unpacks collator object from corresponding JavaScript object.
116   static icu::Collator* UnpackCollator(Isolate* isolate, Handle<JSObject> obj);
117
118   // Release memory we allocated for the Collator once the JS object that holds
119   // the pointer gets garbage collected.
120   static void DeleteCollator(v8::Isolate* isolate,
121                              Persistent<v8::Object>* object,
122                              void* param);
123  private:
124   Collator();
125 };
126
127 } }  // namespace v8::internal
128
129 #endif  // V8_I18N_H_