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_String_h
8 #define builtin_String_h
9 
10 #include "NamespaceImports.h"
11 
12 #include "js/RootingAPI.h"
13 #include "js/Value.h"
14 
15 namespace js {
16 
17 class ArrayObject;
18 class GlobalObject;
19 
20 /* Initialize the String class, returning its prototype object. */
21 extern JSObject* InitStringClass(JSContext* cx, Handle<GlobalObject*> global);
22 
23 extern bool str_fromCharCode(JSContext* cx, unsigned argc, Value* vp);
24 
25 extern bool str_fromCharCode_one_arg(JSContext* cx, HandleValue code,
26                                      MutableHandleValue rval);
27 
28 extern bool str_fromCodePoint(JSContext* cx, unsigned argc, Value* vp);
29 
30 extern bool str_fromCodePoint_one_arg(JSContext* cx, HandleValue code,
31                                       MutableHandleValue rval);
32 
33 // String methods exposed so they can be installed in the self-hosting global.
34 
35 extern bool str_includes(JSContext* cx, unsigned argc, Value* vp);
36 
37 extern bool str_indexOf(JSContext* cx, unsigned argc, Value* vp);
38 
39 extern bool str_startsWith(JSContext* cx, unsigned argc, Value* vp);
40 
41 extern bool str_toString(JSContext* cx, unsigned argc, Value* vp);
42 
43 extern bool str_charCodeAt_impl(JSContext* cx, HandleString string,
44                                 HandleValue index, MutableHandleValue res);
45 
46 extern bool str_charCodeAt(JSContext* cx, unsigned argc, Value* vp);
47 
48 extern bool str_endsWith(JSContext* cx, unsigned argc, Value* vp);
49 
50 #if JS_HAS_INTL_API
51 /**
52  * Returns the input string converted to lower case based on the language
53  * specific case mappings for the input locale.
54  *
55  * Usage: lowerCase = intl_toLocaleLowerCase(string, locale)
56  */
57 [[nodiscard]] extern bool intl_toLocaleLowerCase(JSContext* cx, unsigned argc,
58                                                  Value* vp);
59 
60 /**
61  * Returns the input string converted to upper case based on the language
62  * specific case mappings for the input locale.
63  *
64  * Usage: upperCase = intl_toLocaleUpperCase(string, locale)
65  */
66 [[nodiscard]] extern bool intl_toLocaleUpperCase(JSContext* cx, unsigned argc,
67                                                  Value* vp);
68 #endif
69 
70 ArrayObject* StringSplitString(JSContext* cx, HandleString str,
71                                HandleString sep, uint32_t limit);
72 
73 JSString* StringFlatReplaceString(JSContext* cx, HandleString string,
74                                   HandleString pattern,
75                                   HandleString replacement);
76 
77 JSString* str_replace_string_raw(JSContext* cx, HandleString string,
78                                  HandleString pattern,
79                                  HandleString replacement);
80 
81 JSString* str_replaceAll_string_raw(JSContext* cx, HandleString string,
82                                     HandleString pattern,
83                                     HandleString replacement);
84 
85 extern JSString* StringToLowerCase(JSContext* cx, HandleString string);
86 
87 extern JSString* StringToUpperCase(JSContext* cx, HandleString string);
88 
89 extern bool StringConstructor(JSContext* cx, unsigned argc, Value* vp);
90 
91 extern bool FlatStringMatch(JSContext* cx, unsigned argc, Value* vp);
92 
93 extern bool FlatStringSearch(JSContext* cx, unsigned argc, Value* vp);
94 
95 } /* namespace js */
96 
97 #endif /* builtin_String_h */
98