21 #ifndef _CHEERP_TYPES_H_2043d438 22 #define _CHEERP_TYPES_H_2043d438 27 #include <cheerpintrin.h> 30 namespace [[cheerp::genericjs]]
client 43 static String* fromCharPtr(
const C* s)
48 ret=ret->concat(*String::fromCharCode(*s));
52 template<
typename... Args>
60 String(
unsigned long a)
throw();
62 String(
unsigned int a)
throw();
65 String(
const char* s) __attribute__((noinline)) :
String(fromCharPtr<char>(s))
68 String(
const wchar_t* s) __attribute__((noinline)) :
String(fromCharPtr<wchar_t>(s))
71 template<
typename... Args>
74 return concat(static_cast<const String&>(static_cast<Args&&>(args))...);
76 String* substr(
int start)
const;
78 String* substring(
int start)
const;
79 String* substring(
int start,
int end)
const;
84 int charCodeAt(
int index)
const;
85 String* charAt(
int index)
const;
86 int get_length()
const;
87 int indexOf(
const String&)
const;
88 int indexOf(
const String&,
int)
const;
89 int lastIndexOf(
const String&)
const;
90 int lastIndexOf(
const String&,
int)
const;
95 static String* fromCharCode(
int c) [[cheerp::static]];
96 bool startsWith(
const String&)
const;
97 bool endsWith(
const String&)
const;
98 int localeCompare(
const String&)
const;
101 int search(
const String&)
const;
102 int search(
RegExp*)
const;
103 String* slice(
int start)
const;
104 String* slice(
int start,
int end)
const;
105 String* toLowerCase()
const;
106 String* toLocaleLowerCase()
const;
107 String* toUpperCase()
const;
108 String* toLocaleUpperCase()
const;
110 String* padEnd(
int)
const;
112 String* padStart(
int)
const;
114 explicit operator std::string()
const 119 ret.resize(get_length());
121 for(
int i=0;i<get_length();i++)
122 ptr[i] = charCodeAt(i);
128 unsigned int codepoint;
129 while (len > 0 && *in != 0)
131 unsigned char ch =
static_cast<unsigned char>(*in);
137 codepoint = (codepoint << 6) | (ch & 0x3f);
140 codepoint = ch & 0x1f;
143 codepoint = ch & 0x0f;
146 codepoint = ch & 0x07;
151 if (len == 0 || ((*in & 0xc0) != 0x80))
153 if (codepoint <= 0xffff)
154 out = out->concat(client::String::fromCharCode(codepoint));
158 codepoint -= 0x10000;
159 unsigned int highSurrogate = (codepoint >> 10) + 0xd800;
160 unsigned int lowSurrogate = (codepoint & 0x3ff) + 0xdc00;
161 out = out->concat(client::String::fromCharCode(highSurrogate));
162 out = out->concat(client::String::fromCharCode(lowSurrogate));
174 template<
typename... Args>
178 return __builtin_cheerp_make_regular<Object*>(
this, 0)[index];
182 return __builtin_cheerp_make_regular<Object*>(
this, 0)[index];
184 int indexOf(
Object* searchElement)
const;
185 int indexOf(
Object* searchElement,
int fromIndex)
const;
186 int indexOf(
double searchElement)
const;
187 int indexOf(
double searchElement,
int fromIndex)
const;
188 int lastIndexOf(
Object* searchElement)
const;
189 int lastIndexOf(
Object* searchElement,
int fromIndex)
const;
190 int lastIndexOf(
double searchElement)
const;
191 int lastIndexOf(
double searchElement,
int fromIndex)
const;
192 template<
typename... Args>
193 int push(Args... args);
194 int get_length()
const;
195 Array* splice(
int start);
196 template<
typename... Args>
197 Array* splice(
int start,
int deleteCount, Args... args);
198 Array* slice()
const;
199 Array* slice(
int start)
const;
200 Array* slice(
int start,
int end)
const;
205 String* toLocaleString()
const;
206 template<
typename... Args>
207 Array* concat(Args&&... args)
const;
218 static bool isArray(
Object*) [[cheerp::static]];
225 template<
typename... Args>
231 return (T*&)Array::operator[](index);
235 return (T*)Array::operator[](index);
244 template<
typename K,
typename V,
typename std::enable_if<
245 (std::is_arithmetic<K>::value || std::is_pointer<K>::value) &&
246 (std::is_arithmetic<V>::value || std::is_pointer<V>::value),
int>::type = 0>
248 template<
typename K,
typename V,
typename std::enable_if<
249 (std::is_arithmetic<K>::value || std::is_pointer<K>::value) &&
250 (std::is_arithmetic<V>::value || std::is_pointer<V>::value),
int>::type = 0>
252 template<
typename K,
typename std::enable_if<
253 (std::is_arithmetic<K>::value || std::is_pointer<K>::value),
int>::type = 0>
255 template<
typename K,
typename std::enable_if<
256 (std::is_arithmetic<K>::value || std::is_pointer<K>::value),
int>::type = 0>
260 __asm__(
"%1.delete(%2)" :
"=r"(res) :
"r"(
this),
"r"(k));
267 template<
typename K,
typename V>
269 static_assert(std::is_arithmetic<V>::value || std::is_pointer<V>::value,
"Value has to be pointer or arithmetic");
270 static_assert(std::is_arithmetic<K>::value || std::is_pointer<K>::value,
"Key has to be pointer or arithmetic");
281 return Map::get<K,V>(k);
285 return Map::has<K>(k);
289 return Map::delete_<K>(k);
303 template<
typename... Args>
TMap()
Definition: types.h:272
unsigned int UnsignedLong
Definition: types.h:309
T * operator[](int index) const
Definition: types.h:233
TArray(Args... args)
Definition: types.h:226
static client::String * fromUtf8(const char *in, size_t len=std::numeric_limits< size_t >::max())
Definition: types.h:125
void Void
Definition: types.h:312
bool has(K k)
Definition: types.h:283
bool delete_(K k)
Definition: types.h:287
Definition: clientlib.h:1245
Definition: jsobject.h:32
__attribute__((always_inline)) String *concat(Args &&... args)
Definition: types.h:72
T *& operator[](int index)
Definition: types.h:229
unsigned int UnsignedShort
Definition: types.h:308
Definition: clientlib.h:4724
Definition: clientlib.h:27
Object * operator[](int index) const
Definition: types.h:180
double Double
Definition: types.h:314
unsigned int Boolean
Definition: types.h:313
String(const char *s) __attribute__((noinline))
Definition: types.h:65
bool delete_(K k)
Definition: types.h:257
double UnsignedLongLong
Definition: types.h:311
Object *& operator[](int index)
Definition: types.h:176
String(const wchar_t *s) __attribute__((noinline))
Definition: types.h:68
signed int Long
Definition: types.h:310