Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef builtin_intl_Collator_h
8
#define builtin_intl_Collator_h
9
10
#include "mozilla/Attributes.h"
11
12
#include <stdint.h>
13
14
#include "builtin/SelfHostingDefines.h"
15
#include "js/Class.h"
16
#include "vm/NativeObject.h"
17
18
struct UCollator;
19
20
namespace js {
21
22
/******************** Collator ********************/
23
24
class CollatorObject : public NativeObject {
25
public:
26
static const JSClass class_;
27
static const JSClass& protoClass_;
28
29
static constexpr uint32_t INTERNALS_SLOT = 0;
30
static constexpr uint32_t UCOLLATOR_SLOT = 1;
31
static constexpr uint32_t SLOT_COUNT = 2;
32
33
static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
34
"INTERNALS_SLOT must match self-hosting define for internals "
35
"object slot");
36
37
// Estimated memory use for UCollator.
38
static constexpr size_t EstimatedMemoryUse = 1128;
39
40
UCollator* getCollator() const {
41
const auto& slot = getFixedSlot(UCOLLATOR_SLOT);
42
if (slot.isUndefined()) {
43
return nullptr;
44
}
45
return static_cast<UCollator*>(slot.toPrivate());
46
}
47
48
void setCollator(UCollator* collator) {
49
setFixedSlot(UCOLLATOR_SLOT, PrivateValue(collator));
50
}
51
52
private:
53
static const JSClassOps classOps_;
54
static const ClassSpec classSpec_;
55
56
static void finalize(JSFreeOp* fop, JSObject* obj);
57
};
58
59
/**
60
* Returns a new instance of the standard built-in Collator constructor.
61
* Self-hosted code cannot cache this constructor (as it does for others in
62
* Utilities.js) because it is initialized after self-hosted code is compiled.
63
*
64
* Usage: collator = intl_Collator(locales, options)
65
*/
66
extern MOZ_MUST_USE bool intl_Collator(JSContext* cx, unsigned argc,
67
JS::Value* vp);
68
69
/**
70
* Returns an array with the collation type identifiers per Unicode
71
* Technical Standard 35, Unicode Locale Data Markup Language, for the
72
* collations supported for the given locale. "standard" and "search" are
73
* excluded.
74
*
75
* Usage: collations = intl_availableCollations(locale)
76
*/
77
extern MOZ_MUST_USE bool intl_availableCollations(JSContext* cx, unsigned argc,
78
JS::Value* vp);
79
80
/**
81
* Compares x and y (which must be String values), and returns a number less
82
* than 0 if x < y, 0 if x = y, or a number greater than 0 if x > y according
83
* to the sort order for the locale and collation options of the given
84
* Collator.
85
*
86
* Spec: ECMAScript Internationalization API Specification, 10.3.2.
87
*
88
* Usage: result = intl_CompareStrings(collator, x, y)
89
*/
90
extern MOZ_MUST_USE bool intl_CompareStrings(JSContext* cx, unsigned argc,
91
JS::Value* vp);
92
93
/**
94
* Returns true if the given locale sorts upper-case before lower-case
95
* characters.
96
*
97
* Usage: result = intl_isUpperCaseFirst(locale)
98
*/
99
extern MOZ_MUST_USE bool intl_isUpperCaseFirst(JSContext* cx, unsigned argc,
100
JS::Value* vp);
101
102
} // namespace js
103
104
#endif /* builtin_intl_Collator_h */