Lolly 1.4.28
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
lolly::data Namespace Reference

Classes

class  lolly_tree
 
class  lolly_tree_rep
 
class  string_u16
 
class  string_u16_rep
 
class  string_view
 

Typedefs

using string_u16_view = lolly::data::string_view<char16_t>
 

Functions

static string encode_base64 (char c1, char c2, char c3)
 
string encode_base64 (string s)
 
string decode_base64 (array< int > ac)
 
string decode_base64 (string s)
 
template<typename T >
int N (lolly_tree< T > t)
 
template<typename T >
int arity (lolly_tree< T > t)
 
template<typename T >
array< lolly_tree< T > > A (lolly_tree< T > t)
 
template<typename T >
array< lolly_tree< T > > & AR (lolly_tree< T > t)
 
template<typename T >
bool is_atomic (lolly_tree< T > t)
 
template<typename T >
bool is_compound (lolly_tree< T > t)
 
template<typename T >
bool is_generic (lolly_tree< T > t)
 
template<typename T >
bool operator== (lolly_tree< T > t, int lab)
 
template<typename T >
bool operator!= (lolly_tree< T > t, int lab)
 
template<typename T >
bool operator== (lolly_tree< T > t, string s)
 
template<typename T >
bool operator!= (lolly_tree< T > t, string s)
 
template<typename T >
bool operator== (lolly_tree< T > t, const char *s)
 
template<typename T >
bool operator!= (lolly_tree< T > t, const char *s)
 
template<typename T >
bool operator== (lolly_tree< T > t, lolly_tree< T > u)
 
template<typename T >
bool operator!= (lolly_tree< T > t, lolly_tree< T > u)
 
template<typename T >
bool strong_equal (lolly_tree< T > t, lolly_tree< T > u)
 
template<typename T >
bool is_func (lolly_tree< T > t, int l)
 
template<typename T >
bool is_func (lolly_tree< T > t, int l, int i)
 
template<typename T >
bool is_bool (lolly_tree< T > t)
 
template<typename T >
bool is_int (lolly_tree< T > t)
 
template<typename T >
bool is_double (lolly_tree< T > t)
 
template<typename T >
bool is_string (lolly_tree< T > t)
 
template<typename T >
bool as_bool (lolly_tree< T > t)
 
template<typename T >
int as_int (lolly_tree< T > t)
 
template<typename T >
long int as_long_int (lolly_tree< T > t)
 
template<typename T >
double as_double (lolly_tree< T > t)
 
template<typename T >
string to_string (lolly_tree< T > t)
 
template<typename T >
lolly_tree< T > copy (lolly_tree< T > t)
 
template<typename T >
lolly_tree< T > operator* (lolly_tree< T > t1, lolly_tree< T > t2)
 
template<typename T >
lolly_tree< T > & operator<< (lolly_tree< T > &t, lolly_tree< T > t2)
 
template<typename T >
lolly_tree< T > & operator<< (lolly_tree< T > &t, array< lolly_tree< T > > a)
 
template<typename T >
tm_ostreamoperator<< (tm_ostream &out, lolly_tree< T > t)
 
string to_roman (int32_t nr)
 Generates a Roman numeral string for an integer.
 
string to_Roman (int32_t nr)
 Generates an uppercase Roman numeral string for an integer.
 
string hanzi_sub (int16_t nr, bool leading_zero)
 
string to_hanzi (int32_t nr)
 Generates a Chinese numeral for a given integer.
 
string to_padded_Hex (uint8_t i)
 
string to_padded_hex (uint8_t i)
 Converts an 8-bit unsigned integer to a fixed-length (2) hex string.
 
template<typename T >
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, voidto_Hex_positive (T i, string &s)
 Handle positive number separately to avoid unnecessary check of sign. string is passed into the function as reference, thus no reference counting is performed.
 
string to_Hex (int32_t i)
 
string to_hex (int32_t i)
 
string to_Hex (pointer ptr)
 
string to_hex (pointer ptr)
 Converts a pointer to a hexadecimal string.
 
int from_hex (string s)
 Converts a hexadecimal string to an integer.
 
template<unsigned int cur, typename T >
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, voidas_hexadecimal_sub (T i, string &s)
 Handle positive number separately to avoid unnecessary check of sign. string is passed into the function as reference, thus no reference counting is performed. Because length of string s is known here, use index instead of appending operator can avoid cost of reallocation. Firstly a string of given length is constructed, then digits is filled according to index rather than appending to the tail.
 
string as_hexadecimal (int i, int length)
 Converts an unsigned integer to a hexadecimal string with a fixed length.
 
string uint32_to_Hex (uint32_t i)
 Converts an unsigned integer to a hexadecimal string.
 
string binary_to_hexadecimal (string bin)
 Converts a binary stream to its hexadecimal represention.
 
string to_hex (int i)
 Converts an integer to a hexadecimal string.
 
string to_Hex (int i)
 
static constexpr int round_length (int n)
 
string_u16 copy (const string_u16_view &a)
 
string_u16 copy (string_u16 a)
 
string_u16operator<< (string_u16 &a, char16_t ch)
 
string_u16operator<< (string_u16 &a, string_u16 b)
 
string_u16 operator* (string_u16 a, const string_u16_view &b)
 
 CONCRETE_CODE (string_u16)
 
int N (string_u16 a)
 
int hash (string_u16 s)
 
bool operator== (string_u16 a, string_u16 b)
 
bool operator== (string_u16 a, string_u16_view b)
 
bool operator== (string_u16_view a, string_u16 b)
 
template<size_t Nb>
bool operator== (string_u16 a, const char16_t(&b)[Nb])
 
template<size_t Na>
bool operator== (const char16_t(&a)[Na], string_u16 b)
 
bool operator!= (string_u16 a, string_u16 b)
 
bool operator!= (string_u16 a, string_u16_view b)
 
bool operator!= (string_u16_view a, string_u16 b)
 
template<size_t Nb>
bool operator!= (string_u16 a, const char16_t(&b)[Nb])
 
template<size_t Na>
bool operator!= (const char16_t(&a)[Na], string_u16 b)
 
bool operator< (string_u16 a, string_u16 b)
 
bool operator<= (string_u16 a, string_u16 b)
 
template<typename T >
bool operator== (const string_view< T > &a, const string_view< T > &b)
 
template<typename T , size_t Na>
bool operator== (const T(&a)[Na], const string_view< T > &b)
 
template<typename T , size_t Nb>
bool operator== (const string_view< T > &a, const T(&b)[Nb])
 
template<typename T >
bool operator!= (const string_view< T > &a, const string_view< T > &b)
 
template<typename T , size_t Nb>
bool operator!= (const string_view< T > &a, const T(&b)[Nb])
 
template<typename T , size_t Na>
bool operator!= (const T(&a)[Na], const string_view< T > &b)
 
template<typename T >
bool operator< (const string_view< T > &a, const string_view< T > &b)
 
template<typename T , size_t Nb>
bool operator< (const string_view< T > &a, const T(&b)[Nb])
 
template<typename T , size_t Na>
bool operator< (const T(&a)[Na], const string_view< T > &b)
 
template<typename T >
bool operator<= (const string_view< T > &a, const string_view< T > &b)
 
template<typename T , size_t Nb>
bool operator<= (const string_view< T > &a, const T(&b)[Nb])
 
template<typename T , size_t Na>
bool operator<= (const T(&a)[Na], const string_view< T > &b)
 
string_u8 encode_as_utf8 (uint32_t code)
 Encode 4 bytes as string_u8.
 
uint32_t decode_from_utf8 (string_u8 s, int &i)
 Decode string_u8 string as 4 bytes at position i.
 
string unicode_get_range (int code)
 
bool is_cjk_unified_ideographs (string s)
 Checks if a string contains only CJK Unified Ideographs.
 
bool has_cjk_unified_ideographs (string s)
 Checks if a string contains any CJK Unified Ideographs.
 
string utf16_to_utf8 (string s_u16)
 Convert UTF-16 string to UTF-8 string.
 
string utf8_to_utf16 (string s_u8)
 Convert UTF-8 string to UTF-16 string.
 
string uri_host (url u)
 
string uri_path (url u)
 

Variables

static const char int_to_b64 []
 
static const char b64_to_int []
 
static const string roman_ones [10]
 
static const string roman_tens [10]
 
static const string roman_hundreds [10]
 
static const string roman_thousands [4] = {"", "m", "mm", "mmm"}
 
static const string chars_han [10]
 
static const charhex_string = "0123456789ABCDEF"
 

Typedef Documentation

◆ string_u16_view

Definition at line 19 of file string_u16.hpp.

Function Documentation

◆ encode_base64() [1/2]

static string lolly::data::encode_base64 ( char c1,
char c2,
char c3 )
inlinestatic

Definition at line 24 of file base64.cpp.

24 {
25 string r (4);
26 int idx0, idx1, idx2, idx3;
27
28 idx0= ((c1 >> 2) & 0x3F);
29 idx1= (((c1 << 4) & 0x30) + ((c2 >> 4) & 0x0F));
30 idx2= (((c2 << 2) & 0x3C) + ((c3 >> 6) & 0x03));
31 idx3= (c3 & 0x3F);
32
33 r[0]= int_to_b64[idx0];
34 r[1]= int_to_b64[idx1];
35 r[2]= int_to_b64[idx2];
36 r[3]= int_to_b64[idx3];
37 return r;
38}
The list class represents a linked list.
Definition list.hpp:48
static const char int_to_b64[]
Definition base64.cpp:20

◆ encode_base64() [2/2]

string lolly::data::encode_base64 ( string s)

Definition at line 41 of file base64.cpp.

41 {
42 string r;
43 int i, n= N (s);
44 for (i= 0; i + 2 < n; i+= 3) {
45 if (i > 0 && i % 60 == 0) r << "\n";
46 r << encode_base64 (s[i], s[i + 1], s[i + 2]);
47 }
48
49 if (i == n - 1) {
50 if (i > 0 && i % 60 == 0) r << "\n";
51 r << encode_base64 (s[i], '\0', '\0') (0, 2) << "==";
52 }
53 else if (i == n - 2) {
54 if (i > 0 && i % 60 == 0) r << "\n";
55 r << encode_base64 (s[i], s[i + 1], '\0') (0, 3) << "=";
56 }
57 return r;
58}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170

◆ decode_base64() [1/2]

string lolly::data::decode_base64 ( array< int > ac)

Definition at line 67 of file base64.cpp.

67 {
68 string r (3);
69 int n= N (ac), n1, n2, n3, n4;
70
71 n1= b64_to_int[(int) ac[0]] - 64;
72 n2= b64_to_int[(int) ac[1]] - 64;
73 n3= (n > 2) ? b64_to_int[(int) ac[2]] - 64 : 0;
74 n4= (n > 3) ? b64_to_int[(int) ac[3]] - 64 : 0;
75
76 r[0]= ((n1 << 2) & 0xFC) + ((n2 >> 4) & 0x03);
77 r[1]= ((n2 << 4) & 0xF0) + ((n3 >> 2) & 0x0F);
78 r[2]= ((n3 << 6) & 0xC0) + (n4 & 0x3F);
79
80 return r (0, n - 1);
81}
static const char b64_to_int[]
Definition base64.cpp:62

◆ decode_base64() [2/2]

string lolly::data::decode_base64 ( string s)

Definition at line 84 of file base64.cpp.

84 {
85 string r;
86 bool end= false;
88 int i, n= N (s), cnt= 0;
89 for (i= 0; i < n && !end; i++) {
90 if (b64_to_int[(int) s[i]] != '?') {
91 tmp << (int) s[i];
92 cnt++;
93 }
94 else if (s[i] == '=') {
95 end= true;
96 }
97
98 if (cnt == 4 || end) {
99 r << decode_base64 (tmp);
100 cnt= 0;
101 tmp= array<int> ();
102 }
103 }
104 return r;
105}

◆ N() [1/2]

template<typename T >
int lolly::data::N ( lolly_tree< T > t)
inline

Definition at line 165 of file lolly_tree.hpp.

165 {
167 return N (t->a);
168}
blackbox t[13]
#define CHECK_COMPOUND(t)

◆ arity()

template<typename T >
int lolly::data::arity ( lolly_tree< T > t)
inline

Definition at line 172 of file lolly_tree.hpp.

172 {
173 if (t->op == /*STRING*/ 0) return 0;
174 else return N (t->a);
175}

◆ A()

template<typename T >
array< lolly_tree< T > > lolly::data::A ( lolly_tree< T > t)
inline

Definition at line 179 of file lolly_tree.hpp.

179 {
181 return t->a;
182}

◆ AR()

template<typename T >
array< lolly_tree< T > > & lolly::data::AR ( lolly_tree< T > t)
inline

Definition at line 186 of file lolly_tree.hpp.

186 {
188 return t->a;
189}

◆ is_atomic()

template<typename T >
bool lolly::data::is_atomic ( lolly_tree< T > t)
inline

Definition at line 193 of file lolly_tree.hpp.

193 {
194 return (t->op == 0);
195}

◆ is_compound()

template<typename T >
bool lolly::data::is_compound ( lolly_tree< T > t)
inline

Definition at line 199 of file lolly_tree.hpp.

199 {
200 return ((t->op) > /*STRING*/ 0);
201}

◆ is_generic()

template<typename T >
bool lolly::data::is_generic ( lolly_tree< T > t)
inline

Definition at line 205 of file lolly_tree.hpp.

205 {
206 return (t->op) < 0;
207}

◆ operator==() [1/12]

template<typename T >
bool lolly::data::operator== ( lolly_tree< T > t,
int lab )
inline

Definition at line 211 of file lolly_tree.hpp.

211 {
212 return (t->op == lab) && (N (t) == 0);
213}

◆ operator!=() [1/12]

template<typename T >
bool lolly::data::operator!= ( lolly_tree< T > t,
int lab )
inline

Definition at line 217 of file lolly_tree.hpp.

217 {
218 return (t->op != lab) || (N (t) != 0);
219}

◆ operator==() [2/12]

template<typename T >
bool lolly::data::operator== ( lolly_tree< T > t,
string s )
inline

Definition at line 223 of file lolly_tree.hpp.

223 {
224 return (t->op == /*STRING*/ 0) && (t->label == s);
225}

◆ operator!=() [2/12]

template<typename T >
bool lolly::data::operator!= ( lolly_tree< T > t,
string s )
inline

Definition at line 229 of file lolly_tree.hpp.

229 {
230 return (t->op != /*STRING*/ 0) || (t->label != s);
231}

◆ operator==() [3/12]

template<typename T >
bool lolly::data::operator== ( lolly_tree< T > t,
const char * s )
inline

Definition at line 235 of file lolly_tree.hpp.

235 {
236 return (t->op == /*STRING*/ 0) && (t->label == s);
237}

◆ operator!=() [3/12]

template<typename T >
bool lolly::data::operator!= ( lolly_tree< T > t,
const char * s )
inline

Definition at line 241 of file lolly_tree.hpp.

241 {
242 return (t->op != /*STRING*/ 0) || (t->label != s);
243}

◆ operator==() [4/12]

template<typename T >
bool lolly::data::operator== ( lolly_tree< T > t,
lolly_tree< T > u )
inline

Definition at line 247 of file lolly_tree.hpp.

247 {
248 if (strong_equal (t, u)) return true;
249 return (t->op == u->op) &&
250 (is_atomic (t) ? (t->label == u->label) : (A (t) == A (u)));
251}
T * A(array< T > a)
Get a pointer to the first element of the array.
Definition array.hpp:174
bool strong_equal(list< T > l1, list< T > l2)
Check if two lists are strongly equal (i.e., have the same items in the same order).
Definition list.ipp:110
bool is_atomic(url u)
Definition url.cpp:664

◆ operator!=() [4/12]

template<typename T >
bool lolly::data::operator!= ( lolly_tree< T > t,
lolly_tree< T > u )
inline

Definition at line 255 of file lolly_tree.hpp.

255 {
256 if (strong_equal (t, u)) return false;
257 return (t->op != u->op) ||
258 (is_atomic (t) ? (t->label != u->label) : (A (t) != A (u)));
259}

◆ strong_equal()

template<typename T >
bool lolly::data::strong_equal ( lolly_tree< T > t,
lolly_tree< T > u )
inline

Definition at line 263 of file lolly_tree.hpp.

263 {
264 return t.operator->() == u.operator->();
265}

◆ is_func() [1/2]

template<typename T >
bool lolly::data::is_func ( lolly_tree< T > t,
int l )
inline

Definition at line 269 of file lolly_tree.hpp.

269 {
270 return (t->op == l) && (N (t) != 0);
271}

◆ is_func() [2/2]

template<typename T >
bool lolly::data::is_func ( lolly_tree< T > t,
int l,
int i )
inline

Definition at line 275 of file lolly_tree.hpp.

275 {
276 return (t->op == l) && (N (t) == i);
277}

◆ is_bool()

template<typename T >
bool lolly::data::is_bool ( lolly_tree< T > t)
inline

Definition at line 281 of file lolly_tree.hpp.

281 {
282 return is_atomic (t) && is_bool (t->label);
283}
bool is_bool(string s)
Definition string.cpp:321

◆ is_int()

template<typename T >
bool lolly::data::is_int ( lolly_tree< T > t)
inline

Definition at line 287 of file lolly_tree.hpp.

287 {
288 return is_atomic (t) && is_int (t->label);
289}
bool is_int(string s)
Definition string.cpp:326

◆ is_double()

template<typename T >
bool lolly::data::is_double ( lolly_tree< T > t)
inline

Definition at line 293 of file lolly_tree.hpp.

293 {
294 return is_atomic (t) && is_double (t->label);
295}
bool is_double(string s)
Definition string.cpp:338

◆ is_string()

template<typename T >
bool lolly::data::is_string ( lolly_tree< T > t)
inline

Definition at line 299 of file lolly_tree.hpp.

299 {
300 return is_atomic (t);
301}

◆ as_bool()

template<typename T >
bool lolly::data::as_bool ( lolly_tree< T > t)
inline

Definition at line 305 of file lolly_tree.hpp.

305 {
306 if (is_atomic (t)) return as_bool (t->label);
307 else return false;
308}
bool as_bool(string s)
Definition string.cpp:201

◆ as_int()

template<typename T >
int lolly::data::as_int ( lolly_tree< T > t)
inline

Definition at line 312 of file lolly_tree.hpp.

312 {
313 if (is_atomic (t)) return as_int (t->label);
314 else return 0;
315}
SI as_int(double x)
Converts a double to a signed integer, rounding to the nearest integer.
Definition basic.hpp:261

◆ as_long_int()

template<typename T >
long int lolly::data::as_long_int ( lolly_tree< T > t)
inline

Definition at line 319 of file lolly_tree.hpp.

319 {
320 if (is_atomic (t)) return as_long_int (t->label);
321 else return 0;
322}
long int as_long_int(string s)
Definition string.cpp:223

◆ as_double()

template<typename T >
double lolly::data::as_double ( lolly_tree< T > t)
inline

Definition at line 326 of file lolly_tree.hpp.

326 {
327 if (is_atomic (t)) return as_double (t->label);
328 else return 0.0;
329}
double as_double(string s)
Definition string.cpp:241

◆ to_string()

template<typename T >
string lolly::data::to_string ( lolly_tree< T > t)
inline

Definition at line 333 of file lolly_tree.hpp.

333 {
334 if (is_atomic (t)) return t->label;
335 else return "";
336}

◆ copy() [1/3]

template<typename T >
lolly_tree< T > lolly::data::copy ( lolly_tree< T > t)
inline

Definition at line 389 of file lolly_tree.hpp.

389 {
390 if (is_atomic (t)) return lolly_tree<T> (copy (t->label));
391 else {
392 int i, n= N (t);
393 lolly_tree<T> t2 (t, n);
394 for (i= 0; i < n; i++)
395 t2[i]= copy (t[i]);
396 return t2;
397 }
398}
int copy(int x)
Returns a copy of an integer.
Definition basic.hpp:249
blackbox t2

◆ operator*() [1/2]

template<typename T >
lolly_tree< T > lolly::data::operator* ( lolly_tree< T > t1,
lolly_tree< T > t2 )
inline

Definition at line 342 of file lolly_tree.hpp.

342 {
343 int i;
344 if (is_atomic (t1)) t1= lolly_tree<T> (t2->op, t1);
345 if (is_atomic (t2)) t2= lolly_tree<T> (t1->op, t2);
346 lolly_tree<T> r (t1, N (t1) + N (t2));
347 for (i= 0; i < N (t1); i++)
348 r[i]= t1[i];
349 for (i= 0; i < N (t2); i++)
350 r[i + N (t1)]= t2[i];
351 return r;
352}
blackbox t1

◆ operator<<() [1/5]

template<typename T >
lolly_tree< T > & lolly::data::operator<< ( lolly_tree< T > & t,
lolly_tree< T > t2 )
inline

Definition at line 342 of file lolly_tree.hpp.

356 {
358 t->a << t2;
359 return t;
360}

◆ operator<<() [2/5]

template<typename T >
lolly_tree< T > & lolly::data::operator<< ( lolly_tree< T > & t,
array< lolly_tree< T > > a )
inline

Definition at line 342 of file lolly_tree.hpp.

364 {
366 t->a << a;
367 return t;
368}

◆ operator<<() [3/5]

template<typename T >
tm_ostream & lolly::data::operator<< ( tm_ostream & out,
lolly_tree< T > t )
inline

Definition at line 371 of file lolly_tree.hpp.

372 {
373 if (is_atomic (t)) return out << t->label;
374 else if (is_compound (t)) {
375 int i, n= N (t);
376 out << as_string (t->op);
377 if (n == 0) return out << "()";
378 out << " (";
379 for (i= 0; i < n - 1; i++)
380 out << t[i] << ", ";
381 out << t[i] << ")";
382 return out;
383 }
384 return out;
385}
string as_string(int16_t i)
Definition string.cpp:272

◆ to_roman()

string lolly::data::to_roman ( int32_t nr)

Generates a Roman numeral string for an integer.

Parameters
nrThe integer to be converted to Roman numeral.
Returns
A string representing the Roman numeral.

Definition at line 34 of file numeral.cpp.

34 {
35 if (nr == 0) return "o";
36 if (nr > 3999 || nr < -3999) return "?";
37 if (nr < 0) return "-" * to_roman (-nr);
38 return roman_thousands[(nr / 1000) % 10] * roman_hundreds[(nr / 100) % 10] *
39 roman_tens[(nr / 10) % 10] * roman_ones[nr % 10];
40}
string to_roman(int32_t nr)
Generates a Roman numeral string for an integer.
Definition numeral.cpp:34
static const string roman_thousands[4]
Definition numeral.cpp:24
static const string roman_tens[10]
Definition numeral.cpp:20

◆ to_Roman()

string lolly::data::to_Roman ( int32_t nr)

Generates an uppercase Roman numeral string for an integer.

Parameters
nrThe integer to be converted to Roman numeral.
Returns
A string representing the uppercase Roman numeral.

Definition at line 43 of file numeral.cpp.

43 {
44 return upcase_all (to_roman (nr));
45}
string upcase_all(string s)
Converts all lowercase characters in a string to uppercase.
Definition analyze.cpp:127

◆ hanzi_sub()

string lolly::data::hanzi_sub ( int16_t nr,
bool leading_zero )

Definition at line 48 of file numeral.cpp.

48 {
49 short thousand= (nr % 10000) / 1000, hundred= (nr % 1000) / 100,
50 ten= (nr % 100) / 10, one= nr % 10;
51 short cases= (leading_zero << 4) | ((thousand == 0) << 3) |
52 ((hundred == 0) << 2) | ((ten == 0) << 1) | (one == 0);
53 switch (cases) {
54 case 0x0:
55 case 0x10:
56 return chars_han[thousand] * "千" * chars_han[hundred] * "百" *
57 chars_han[ten] * "十" * chars_han[one];
58 case 0x1:
59 case 0x11:
60 return chars_han[thousand] * "千" * chars_han[hundred] * "百" *
61 chars_han[ten] * "十";
62 case 0x2:
63 case 0x12:
64 return chars_han[thousand] * "千" * chars_han[hundred] * "百零" *
66 case 0x3:
67 case 0x13:
68 return chars_han[thousand] * "千" * chars_han[hundred] * "百";
69 case 0x4:
70 case 0x14:
71 return chars_han[thousand] * "千零" * chars_han[ten] * "十" *
73 case 0x5:
74 case 0x15:
75 return chars_han[thousand] * "千零" * chars_han[ten] * "十";
76 case 0x6:
77 case 0x16:
78 return chars_han[thousand] * "千零" * chars_han[one];
79 case 0x7:
80 case 0x17:
81 return chars_han[thousand] * "千";
82 case 0x8:
83 return chars_han[hundred] * "百" * chars_han[ten] * "十" * chars_han[one];
84 case 0x18:
85 return "零" * chars_han[hundred] * "百" * chars_han[ten] * "十" *
87 case 0x9:
88 return chars_han[hundred] * "百" * chars_han[ten] * "十";
89 case 0x19:
90 return "零" * chars_han[hundred] * "百" * chars_han[ten] * "十";
91 case 0xA:
92 return chars_han[hundred] * "百零" * chars_han[one];
93 case 0x1A:
94 return "零" * chars_han[hundred] * "百零" * chars_han[one];
95 case 0xB:
96 return chars_han[hundred] * "百";
97 case 0x1B:
98 return "零" * chars_han[hundred] * "百";
99 case 0xC:
100 if (ten == 1) {
101 return "十" * chars_han[one];
102 }
103 else {
104 return chars_han[ten] * "十" * chars_han[one];
105 }
106 case 0x1C:
107 return "零" * chars_han[ten] * "十" * chars_han[one];
108 case 0xD:
109 if (ten == 1) {
110 return "十";
111 }
112 else {
113 return chars_han[ten] * "十";
114 }
115 case 0x1D:
116 return "零" * chars_han[ten] * "十";
117 case 0xE:
118 return chars_han[one];
119 case 0x1E:
120 return "零" * chars_han[one];
121 case 0xF:
122 case 0x1F:
123 return "";
124 default:
125 return "?" * as_string (cases);
126 }
127}
static const string chars_han[10]
Definition numeral.cpp:28

◆ to_hanzi()

string lolly::data::to_hanzi ( int32_t nr)

Generates a Chinese numeral for a given integer.

Parameters
nrThe integer to be converted to a Chinese numeral.
Returns
A string representing the Chinese numeral.

Definition at line 130 of file numeral.cpp.

130 {
131 if (nr == 0) return "零";
132 if (nr == 0x80000000) return "负二十一亿四千七百四十八万三千六百四十八";
133 if (nr < 0) return "负" * to_hanzi (-nr);
134 if (nr >= 100000000) {
135 return hanzi_sub (nr / 100000000, false) * "亿" *
136 hanzi_sub ((nr / 10000) % 10000, true) * "万" *
137 hanzi_sub (nr % 10000, true);
138 }
139 if (nr >= 10000) {
140 return hanzi_sub (nr / 10000, false) * "万" * hanzi_sub (nr % 10000, true);
141 }
142 return hanzi_sub (nr, false);
143}
string to_hanzi(int32_t nr)
Generates a Chinese numeral for a given integer.
Definition numeral.cpp:130
string hanzi_sub(int16_t nr, bool leading_zero)
Definition numeral.cpp:48

◆ to_padded_Hex()

string lolly::data::to_padded_Hex ( uint8_t i)

Definition at line 146 of file numeral.cpp.

146 {
147 uint8_t i_low = i & 15;
148 uint8_t i_high= i >> 4;
149 return string (hex_string[i_high]) * string (hex_string[i_low]);
150}

◆ to_padded_hex()

string lolly::data::to_padded_hex ( uint8_t i)

Converts an 8-bit unsigned integer to a fixed-length (2) hex string.

Parameters
iThe integer to be converted to a fixed-length hex string.
Returns
The fixed-length (2) hexadecimal string representation of the input integer.

Definition at line 153 of file numeral.cpp.

153 {
154 return locase_all (to_padded_Hex (i));
155}
string locase_all(string s)
Converts all uppercase characters in a string to lowercase.
Definition analyze.cpp:137

◆ to_Hex_positive()

template<typename T >
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, void > lolly::data::to_Hex_positive ( T i,
string & s )

Handle positive number separately to avoid unnecessary check of sign. string is passed into the function as reference, thus no reference counting is performed.

Template Parameters
Tunsigned integral type is expected.

Definition at line 166 of file numeral.cpp.

166 {
167 if (i >= 16) {
168 to_Hex_positive (i >> 4, s);
169 }
170 s << hex_string[i & 15];
171}
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, void > to_Hex_positive(T i, string &s)
Handle positive number separately to avoid unnecessary check of sign. string is passed into the funct...
Definition numeral.cpp:166

◆ to_Hex() [1/3]

string lolly::data::to_Hex ( int32_t i)

Definition at line 174 of file numeral.cpp.

174 {
175 if (i == INT32_MIN) return "-80000000";
176 if (i < 0) {
177 string result ("-");
179 return result;
180 }
181 else {
182 string result;
183 to_Hex_positive ((uint32_t) (i), result);
184 return result;
185 };
186}

◆ to_hex() [1/3]

string lolly::data::to_hex ( int32_t i)

Definition at line 189 of file numeral.cpp.

189 {
190 return locase_all (to_Hex (i));
191}

◆ to_Hex() [2/3]

string lolly::data::to_Hex ( pointer ptr)

Definition at line 194 of file numeral.cpp.

194 {
195 intptr_t i= (intptr_t) ptr;
196 if (i < 0) {
197 string result ("-");
198 to_Hex_positive ((uintptr_t) (-i), result);
199 return result;
200 }
201 else {
202 string result;
203 to_Hex_positive ((uintptr_t) (i), result);
204 return result;
205 };
206}

◆ to_hex() [2/3]

string lolly::data::to_hex ( pointer ptr)

Converts a pointer to a hexadecimal string.

Parameters
ptrThe pointer to be converted to a hexadecimal string.
Returns
The hexadecimal string representation of the input pointer.

Definition at line 209 of file numeral.cpp.

209 {
210 return locase_all (to_Hex (ptr));
211}

◆ from_hex()

int lolly::data::from_hex ( string s)

Converts a hexadecimal string to an integer.

This function takes a hexadecimal string as input and converts it into its integer representation.

Parameters
sThe hexadecimal string to be converted to an integer.
Returns
The integer representation of the input hexadecimal string.

Definition at line 214 of file numeral.cpp.

214 {
215 int i, n= N (s), res= 0;
216 if ((n > 0) && (s[0] == '-')) return -from_hex (s (1, n));
217 for (i= 0; i < n; i++) {
218 res= res << 4;
219 if (is_digit (s[i])) res+= (int) (s[i] - '0');
220 if ((s[i] >= 'A') && (s[i] <= 'F')) res+= (int) (s[i] + 10 - 'A');
221 if ((s[i] >= 'a') && (s[i] <= 'f')) res+= (int) (s[i] + 10 - 'a');
222 }
223 return res;
224}
bool is_digit(char c)
Definition analyze.hpp:37
int from_hex(string s)
Converts a hexadecimal string to an integer.
Definition numeral.cpp:214

◆ as_hexadecimal_sub()

template<unsigned int cur, typename T >
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, void > lolly::data::as_hexadecimal_sub ( T i,
string & s )

Handle positive number separately to avoid unnecessary check of sign. string is passed into the function as reference, thus no reference counting is performed. Because length of string s is known here, use index instead of appending operator can avoid cost of reallocation. Firstly a string of given length is constructed, then digits is filled according to index rather than appending to the tail.

Template Parameters
Tunsigned integral type is expected.

Definition at line 239 of file numeral.cpp.

239 {
240 if constexpr (cur > 0) {
241 as_hexadecimal_sub<cur - 1> (i >> 4, s);
242 }
243 s[cur]= hex_string[i & 15];
244}
std::enable_if_t< std::conjunction_v< std::is_integral< T >, std::is_unsigned< T > >, void > as_hexadecimal_sub(T i, string &s)
Handle positive number separately to avoid unnecessary check of sign. string is passed into the funct...
Definition numeral.cpp:239

◆ as_hexadecimal()

string lolly::data::as_hexadecimal ( int i,
int length )

Converts an unsigned integer to a hexadecimal string with a fixed length.

Parameters
iThe integer to be converted to a hexadecimal string.
lenThe length of the output hexadecimal string.
Returns
The fixed-length hexadecimal string representation of the input integer.

Definition at line 247 of file numeral.cpp.

247 {
248 string result (len);
249 switch (len) {
250 case 1:
251 as_hexadecimal_sub<0> ((unsigned int) i, result);
252 break;
253 case 2:
254 as_hexadecimal_sub<1> ((unsigned int) i, result);
255 break;
256 case 3:
257 as_hexadecimal_sub<2> ((unsigned int) i, result);
258 break;
259 case 4:
260 as_hexadecimal_sub<3> ((unsigned int) i, result);
261 break;
262 case 5:
263 as_hexadecimal_sub<4> ((unsigned int) i, result);
264 break;
265 case 6:
266 as_hexadecimal_sub<5> ((unsigned int) i, result);
267 break;
268 case 7:
269 as_hexadecimal_sub<6> ((unsigned int) i, result);
270 break;
271 case 8:
272 as_hexadecimal_sub<7> ((unsigned int) i, result);
273 break;
274 case 9:
275 as_hexadecimal_sub<8> ((unsigned int) i, result);
276 break;
277 case 10:
278 as_hexadecimal_sub<9> ((unsigned int) i, result);
279 break;
280 case 11:
281 as_hexadecimal_sub<10> ((unsigned int) i, result);
282 break;
283 case 12:
284 as_hexadecimal_sub<11> ((unsigned int) i, result);
285 break;
286 case 13:
287 as_hexadecimal_sub<12> ((unsigned int) i, result);
288 break;
289 case 14:
290 as_hexadecimal_sub<13> ((unsigned int) i, result);
291 break;
292 case 15:
293 as_hexadecimal_sub<14> ((unsigned int) i, result);
294 break;
295 case 16:
296 as_hexadecimal_sub<15> ((unsigned int) i, result);
297 break;
298 default:
299 TM_FAILED ("len is too large");
300 break;
301 }
302 return result;
303}
#define TM_FAILED(msg)
Macro used to throw an exception with a specified error message.
Definition basic.hpp:93

◆ uint32_to_Hex()

string lolly::data::uint32_to_Hex ( uint32_t i)

Converts an unsigned integer to a hexadecimal string.

Parameters
iThe integer to be converted to a hexadecimal string.
Returns
The hexadecimal string representation of the input integer.

Definition at line 306 of file numeral.cpp.

306 {
307 string result;
309 return result;
310}

◆ binary_to_hexadecimal()

string lolly::data::binary_to_hexadecimal ( string bin)

Converts a binary stream to its hexadecimal represention.

Parameters
binThe binary data to be converted to a hexadecimal string.
Returns
The hexadecimal string representation of the input binary.

Definition at line 313 of file numeral.cpp.

313 {
314 string res ((int) (N (bin) * 2));
315 int cur= 0;
316 for (unsigned char ch : bin) {
317 res[cur] = hex_string[ch >> 4];
318 res[cur + 1]= hex_string[ch & 0x0f];
319 cur+= 2;
320 }
321 return res;
322}
static const char * hex_string
Definition numeral.cpp:31

◆ to_hex() [3/3]

string lolly::data::to_hex ( int i)

Converts an integer to a hexadecimal string.

Parameters
iThe integer to be converted to a hexadecimal string.
Returns
The hexadecimal string representation of the input integer.

◆ to_Hex() [3/3]

string lolly::data::to_Hex ( int i)

◆ round_length()

static constexpr int lolly::data::round_length ( int n)
inlinestaticconstexpr

Definition at line 17 of file string_u16.cpp.

17 {
18 n= (n + 3) & (0xfffffffc);
19 if (n < 24) return n;
20 int i= 32;
21 while (n > i)
22 i<<= 1;
23 return i;
24}

◆ copy() [2/3]

string_u16 lolly::data::copy ( const string_u16_view & a)

Definition at line 100 of file string_u16.cpp.

100 {
101 int i;
102 string_u16 r (a.N);
103 for (i= 0; i < a.N; i++)
104 r[i]= a.a[i];
105 return r;
106};

◆ copy() [3/3]

string_u16 lolly::data::copy ( string_u16 a)

Definition at line 109 of file string_u16.cpp.

109 {
110 return copy ((string_u16_view) a);
111};

◆ operator<<() [4/5]

string_u16 & lolly::data::operator<< ( string_u16 & a,
char16_t ch )

Definition at line 113 of file string_u16.cpp.

114 {
115 int old_a_N= a->expand_or_shrink_by (1);
116 a[old_a_N] = ch;
117 return a;
118};

◆ operator<<() [5/5]

string_u16 & lolly::data::operator<< ( string_u16 & a,
string_u16 b )

Definition at line 120 of file string_u16.cpp.

121 {
122 int b_N = N (b);
123 int old_a_N= a->expand_or_shrink_by (b_N);
124 for (int i= 0; i < b_N; i++)
125 a[i + old_a_N]= b[i];
126 return a;
127};
blackbox b[13]

◆ operator*() [2/2]

string_u16 lolly::data::operator* ( string_u16 a,
const string_u16_view & b )

Definition at line 130 of file string_u16.cpp.

130 {
131 int a_N= N (a), b_N= b.N;
132 string_u16 c (a_N + b_N);
133 for (int i= 0; i < a_N; i++) {
134 c[i]= a[i];
135 }
136 for (int i= 0; i < b_N; i++) {
137 c[i + a_N]= b.a[i];
138 }
139 return c;
140};

◆ CONCRETE_CODE()

lolly::data::CONCRETE_CODE ( string_u16 )

◆ N() [2/2]

int lolly::data::N ( string_u16 a)
inline

Definition at line 98 of file string_u16.hpp.

98 {
99 return a->n;
100}

◆ hash()

int lolly::data::hash ( string_u16 s)
inline

Definition at line 103 of file string_u16.hpp.

103 {
104 int i, h= 0, n= N (s);
105 for (i= 0; i < n; i++) {
106 h= (h << 9) + (h >> 23);
107 h= h + ((int) s[i]);
108 }
109 return h;
110};

◆ operator==() [5/12]

bool lolly::data::operator== ( string_u16 a,
string_u16 b )
inline

Definition at line 113 of file string_u16.hpp.

113 {
114 return ((string_u16_view) a) == ((string_u16_view) b);
115};

◆ operator==() [6/12]

bool lolly::data::operator== ( string_u16 a,
string_u16_view b )
inline

Definition at line 118 of file string_u16.hpp.

118 {
119 return ((string_u16_view) a) == b;
120}

◆ operator==() [7/12]

bool lolly::data::operator== ( string_u16_view a,
string_u16 b )
inline

Definition at line 123 of file string_u16.hpp.

123 {
124 return a == ((string_u16_view) b);
125}

◆ operator==() [8/12]

template<size_t Nb>
bool lolly::data::operator== ( string_u16 a,
const char16_t(&) b[Nb] )

Definition at line 129 of file string_u16.hpp.

129 {
130 return ((string_u16_view) a) == string_u16_view (b);
131}

◆ operator==() [9/12]

template<size_t Na>
bool lolly::data::operator== ( const char16_t(&) a[Na],
string_u16 b )

Definition at line 135 of file string_u16.hpp.

135 {
136 return string_u16_view (a) == ((string_u16_view) b);
137}

◆ operator!=() [5/12]

bool lolly::data::operator!= ( string_u16 a,
string_u16 b )
inline

Definition at line 140 of file string_u16.hpp.

140 {
141 return ((string_u16_view) a) != ((string_u16_view) b);
142};

◆ operator!=() [6/12]

bool lolly::data::operator!= ( string_u16 a,
string_u16_view b )
inline

Definition at line 145 of file string_u16.hpp.

145 {
146 return ((string_u16_view) a) != b;
147}

◆ operator!=() [7/12]

bool lolly::data::operator!= ( string_u16_view a,
string_u16 b )
inline

Definition at line 150 of file string_u16.hpp.

150 {
151 return a != ((string_u16_view) b);
152}

◆ operator!=() [8/12]

template<size_t Nb>
bool lolly::data::operator!= ( string_u16 a,
const char16_t(&) b[Nb] )

Definition at line 156 of file string_u16.hpp.

156 {
157 return ((string_u16_view) a) != string_u16_view (b);
158}

◆ operator!=() [9/12]

template<size_t Na>
bool lolly::data::operator!= ( const char16_t(&) a[Na],
string_u16 b )

Definition at line 162 of file string_u16.hpp.

162 {
163 return string_u16_view (a) != ((string_u16_view) b);
164}

◆ operator<() [1/4]

bool lolly::data::operator< ( string_u16 a,
string_u16 b )
inline

Definition at line 166 of file string_u16.hpp.

167 {
168 return ((string_u16_view) a) < ((string_u16_view) b);
169}

◆ operator<=() [1/4]

bool lolly::data::operator<= ( string_u16 a,
string_u16 b )
inline

Definition at line 171 of file string_u16.hpp.

172 {
173 return ((string_u16_view) a) <= ((string_u16_view) b);
174}

◆ operator==() [10/12]

template<typename T >
bool lolly::data::operator== ( const string_view< T > & a,
const string_view< T > & b )

Definition at line 70 of file string_view.hpp.

70 {
71 if (a.N != b.N) return false;
72 const T *Sa= a.a, *Sb= b.a;
73 int n= a.N;
74 for (int i= 0; i < n; i++)
75 if (Sa[i] != Sb[i]) return false;
76 return true;
77};

◆ operator==() [11/12]

template<typename T , size_t Na>
bool lolly::data::operator== ( const T(&) a[Na],
const string_view< T > & b )

Definition at line 81 of file string_view.hpp.

81 {
82 return string_view<T> (a) == b;
83}

◆ operator==() [12/12]

template<typename T , size_t Nb>
bool lolly::data::operator== ( const string_view< T > & a,
const T(&) b[Nb] )

Definition at line 87 of file string_view.hpp.

87 {
88 return a == string_view<T> (b);
89};

◆ operator!=() [10/12]

template<typename T >
bool lolly::data::operator!= ( const string_view< T > & a,
const string_view< T > & b )

Definition at line 93 of file string_view.hpp.

93 {
94 if (a.N != b.N) return true;
95 const T *Sa= a.a, *Sb= b.a;
96 int n= a.N;
97 for (int i= 0; i < n; i++)
98 if (Sa[i] != Sb[i]) return true;
99 return false;
100};

◆ operator!=() [11/12]

template<typename T , size_t Nb>
bool lolly::data::operator!= ( const string_view< T > & a,
const T(&) b[Nb] )

Definition at line 104 of file string_view.hpp.

104 {
105 return a != string_view<T> (b);
106};

◆ operator!=() [12/12]

template<typename T , size_t Na>
bool lolly::data::operator!= ( const T(&) a[Na],
const string_view< T > & b )

Definition at line 110 of file string_view.hpp.

110 {
111 return string_view<T> (a) != b;
112};

◆ operator<() [2/4]

template<typename T >
bool lolly::data::operator< ( const string_view< T > & a,
const string_view< T > & b )

Definition at line 115 of file string_view.hpp.

116 {
117 int i, na= a.N, nb= b.N, nmin= min (na, nb);
118 const T *Sa= a.a, *Sb= b.a;
119 for (i= 0; i < nmin; i++) {
120 if (Sa[i] < Sb[i]) return true;
121 if (Sb[i] < Sa[i]) return false;
122 }
123 return na < nb;
124};
SI min(SI i, SI j)
Returns the minimum of two signed integers.
Definition minmax.hpp:27

◆ operator<() [3/4]

template<typename T , size_t Nb>
bool lolly::data::operator< ( const string_view< T > & a,
const T(&) b[Nb] )

Definition at line 127 of file string_view.hpp.

128 {
129 return a < string_view<T> (b);
130};

◆ operator<() [4/4]

template<typename T , size_t Na>
bool lolly::data::operator< ( const T(&) a[Na],
const string_view< T > & b )

Definition at line 133 of file string_view.hpp.

134 {
135 return string_view<T> (a);
136};

◆ operator<=() [2/4]

template<typename T >
bool lolly::data::operator<= ( const string_view< T > & a,
const string_view< T > & b )

Definition at line 139 of file string_view.hpp.

140 {
141 int i, na= a.N, nb= b.N, nmin= min (na, nb);
142 const T *Sa= a.a, *Sb= b.a;
143 for (i= 0; i < nmin; i++) {
144 if (Sa[i] < Sb[i]) return true;
145 if (Sb[i] < Sa[i]) return false;
146 }
147 return na <= nb;
148};

◆ operator<=() [3/4]

template<typename T , size_t Nb>
bool lolly::data::operator<= ( const string_view< T > & a,
const T(&) b[Nb] )

Definition at line 151 of file string_view.hpp.

152 {
153 return a <= string_view<T> (b);
154};

◆ operator<=() [4/4]

template<typename T , size_t Na>
bool lolly::data::operator<= ( const T(&) a[Na],
const string_view< T > & b )

Definition at line 157 of file string_view.hpp.

158 {
159 return string_view<T> (a) <= b;
160};

◆ encode_as_utf8()

string_u8 lolly::data::encode_as_utf8 ( uint32_t code)

Encode 4 bytes as string_u8.

Parameters
codeThe 4 bytes to encode
Returns
The UTF-8 string in string_u8

Definition at line 19 of file unicode.cpp.

19 {
20 if (/* 0x0 <= code && */ code <= 0x7F) {
21 // 0x0ddddddd
22 return string ((char) code);
23 }
24 else if (0x80 <= code && code <= 0x7FF) {
25 // 0x110ddddd 0x10dddddd
26 string str (2);
27 str[0]= ((code >> 6) & 0x1F) | 0xC0;
28 str[1]= (code & 0x3F) | 0x80;
29 return str;
30 }
31 else if (0x800 <= code && code <= 0xFFFF) {
32 // 0x1110dddd 0x10dddddd 0x10dddddd
33 string str (3);
34 str[0]= ((code >> 12) & 0x0F) | 0xE0;
35 str[1]= ((code >> 6) & 0x3F) | 0x80;
36 str[2]= (code & 0x3F) | 0x80;
37 return str;
38 }
39 else if (0x10000 <= code && code <= 0x1FFFFF) {
40 // 0x11110uuu 0x10zzzzzz 0x10yyyyyy 0x10xxxxxx
41 string str (4);
42 str[0]= ((code >> 18) & 0x07) | 0xF0;
43 str[1]= ((code >> 12) & 0x3F) | 0x80;
44 str[2]= ((code >> 6) & 0x3F) | 0x80;
45 str[3]= (code & 0x3F) | 0x80;
46 return str;
47 }
48 else return "";
49}

◆ decode_from_utf8()

uint32_t lolly::data::decode_from_utf8 ( string_u8 s,
int & i )

Decode string_u8 string as 4 bytes at position i.

Parameters
sThe string_u8 string
iThe position
Returns
The 4 bytes in uint32_t

Definition at line 52 of file unicode.cpp.

52 {
53 unsigned char c= s[i];
54 if ((0x80 & c) == 0) {
55 // 0x0ddddddd
56 i++;
57 return (uint32_t) c;
58 }
59 uint32_t code;
60 int trail;
61 if ((0xE0 & c) == 0xC0) {
62 // 0x110ddddd 0x10dddddd
63 trail= 1;
64 code = c & 0x1F;
65 }
66 else if ((0xF0 & c) == 0xE0) {
67 // 0x1110dddd 0x10dddddd 0x10dddddd
68 trail= 2;
69 code = c & 0x0F;
70 }
71 else if ((0xF8 & c) == 0xF0) {
72 // 0x11110dddd 0x10dddddd 0x10dddddd 0x10dddddd
73 trail= 3;
74 code = c & 0x07;
75 }
76 else {
77 // failsafe
78 // cout << "failsafe: " << c << " (" << (unsigned int)(c) << ")\n";
79 i++;
80 return (uint32_t) c;
81 }
82 int start= i - 1;
83 for (; trail > 0; trail--) {
84 i++;
85 if (i >= N (s)) i= N (s) - 1;
86 c= s[i];
87 if ((0xC0 & c) == 0x80) code= (code << 6) | (c & 0x3F);
88 else {
89 i= start + 1;
90 c= s[i++];
91 return c;
92 }
93 }
94 i++;
95 return code;
96}

◆ unicode_get_range()

string lolly::data::unicode_get_range ( int code)

Definition at line 99 of file unicode.cpp.

99 {
100 if (code <= 0x7f) return "ascii";
101 else if (code >= 0x80 && code <= 0x37f) return "latin";
102 else if (code >= 0x370 && code <= 0x3ff) return "greek";
103 else if (code >= 0x400 && code <= 0x4ff) return "cyrillic";
104 else if (code >= 0x2460 && code <= 0x24ff) return "enclosed_alphanumerics";
105 else if (code >= 0x3000 && code <= 0x303f) return "cjk";
106 else if (code >= 0x4e00 && code <= 0x9fcc) return "cjk";
107 else if (code >= 0xff00 && code <= 0xffef) return "cjk";
108 else if (code >= 0x3040 && code <= 0x309F) return "hiragana";
109 else if (code >= 0xac00 && code <= 0xd7af) return "hangul";
110 else if (code >= 0x2000 && code <= 0x23ff) return "mathsymbols";
111 else if (code >= 0x2900 && code <= 0x2e7f) return "mathextra";
112 else if (code >= 0x1d400 && code <= 0x1d7ff) return "mathletters";
113 else return "";
114}

◆ is_cjk_unified_ideographs()

bool lolly::data::is_cjk_unified_ideographs ( string s)

Checks if a string contains only CJK Unified Ideographs.

Parameters
sThe string to check.
Returns
True if all characters in the string are CJK Unified Ideographs, otherwise false.
Note
This function expects the CJK Unified Ideographs to be in a specific encoded format.

Definition at line 117 of file unicode.cpp.

117 {
118 int n= N (s);
119 for (int i= 0; i < n; i++)
120 if (s[i] == '<' && i + 1 < n && s[i + 1] == '#') {
121 int start= i + 2;
122 i = i + 2;
123 while (i < n && s[i] != '>')
124 i++;
125 string r= s (start, i);
126 if ("4E00" <= r && r <= "9FBF") continue;
127 else return false;
128 }
129 else {
130 return false;
131 }
132 return true;
133}

◆ has_cjk_unified_ideographs()

bool lolly::data::has_cjk_unified_ideographs ( string s)

Checks if a string contains any CJK Unified Ideographs.

Parameters
sThe string to check.
Returns
True if the string contains at least one CJK Unified Ideograph, otherwise false.
Note
This function expects the CJK Unified Ideographs to be in a specific encoded format.

Definition at line 136 of file unicode.cpp.

136 {
137 int n= N (s);
138 for (int i= 0; i < n; i++)
139 if (s[i] == '<' && i + 1 < n && s[i + 1] == '#') {
140 int start= i + 2;
141 i = i + 2;
142 while (i < n && s[i] != '>')
143 i++;
144 string r= s (start, i);
145 if ("4E00" <= r && r <= "9FBF") return true;
146 else continue;
147 }
148 else {
149 continue;
150 }
151 return false;
152}

◆ utf16_to_utf8()

string lolly::data::utf16_to_utf8 ( string s_u16)

Convert UTF-16 string to UTF-8 string.

Parameters
s_u16the string using the UTF-16 encoding
Returns
the string using the UTF-8 encoding
Note
For invalid UTF-16 string, only the valid part will be converted

Definition at line 155 of file unicode.cpp.

155 {
158 tb_long_t osize= (tb_long_t) (isize << 2);
160
161 for (tb_size_t i= 0; i < isize; i++) {
162 idata[i]= (tb_byte_t) s_u16[i];
163 }
164
167
168 string ret ((int) osize);
169 for (tb_size_t i= 0; i < osize; i++) {
170 ret[i]= (char) odata[i];
171 }
172 if (idata) tb_free (idata);
173 if (odata) tb_free (odata);
174 return ret;
175}

◆ utf8_to_utf16()

string lolly::data::utf8_to_utf16 ( string s_u8)

Convert UTF-8 string to UTF-16 string.

Parameters
s_u8the string using the UTF-8 encoding
Returns
the string using the UTF-16 encoding
Note
For invalid UTF-8 string, only the valid part will be converted

Definition at line 208 of file unicode.cpp.

208 {
209 tb_long_t osize= (tb_long_t) (N (s_u8) << 2);
211
214
215 string ret ((int) osize);
216 for (tb_size_t i= 0; i < osize; i++) {
217 ret[i]= odata[i];
218 }
219 if (odata) tb_free (odata);
220 return ret;
221}

◆ uri_host()

string lolly::data::uri_host ( url u)

Definition at line 18 of file uri.cpp.

18 {
19 return as_string (u[2][1]);
20}

◆ uri_path()

string lolly::data::uri_path ( url u)

Definition at line 23 of file uri.cpp.

23 {
24 return string ("/") * as_string (u[2][2], URL_STANDARD);
25}
#define URL_STANDARD
Definition url.hpp:17

Variable Documentation

◆ int_to_b64

const char lolly::data::int_to_b64[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 20 of file base64.cpp.

◆ b64_to_int

const char lolly::data::b64_to_int[]
static
Initial value:
=
"???????????????????????????????????????????~???\177tuvwxyz{|}??\
?????@ABCDEFGHIJKLMNOPQRSTUVWXY??????Z[\\]^_`abcdefghijklmnopqrs?????"

Definition at line 62 of file base64.cpp.

◆ roman_ones

const string lolly::data::roman_ones[10]
static
Initial value:
= {"", "i", "ii", "iii", "iv",
"v", "vi", "vii", "viii", "ix"}

Definition at line 18 of file numeral.cpp.

18 {"", "i", "ii", "iii", "iv",
19 "v", "vi", "vii", "viii", "ix"};

◆ roman_tens

const string lolly::data::roman_tens[10]
static
Initial value:
= {"", "x", "xx", "xxx", "xl",
"l", "lx", "lxx", "lxxx", "xc"}

Definition at line 20 of file numeral.cpp.

20 {"", "x", "xx", "xxx", "xl",
21 "l", "lx", "lxx", "lxxx", "xc"};

◆ roman_hundreds

const string lolly::data::roman_hundreds[10]
static
Initial value:
= {"", "c", "cc", "ccc", "cd",
"d", "dc", "dcc", "dccc", "cm"}

Definition at line 22 of file numeral.cpp.

22 {"", "c", "cc", "ccc", "cd",
23 "d", "dc", "dcc", "dccc", "cm"};

◆ roman_thousands

const string lolly::data::roman_thousands[4] = {"", "m", "mm", "mmm"}
static

Definition at line 24 of file numeral.cpp.

24{"", "m", "mm", "mmm"};

◆ chars_han

const string lolly::data::chars_han[10]
static
Initial value:
= {"?", "一", "二", "三", "四",
"五", "六", "七", "八", "九"}

Definition at line 28 of file numeral.cpp.

28 {"?", "一", "二", "三", "四",
29 "五", "六", "七", "八", "九"};

◆ hex_string

const char* lolly::data::hex_string = "0123456789ABCDEF"
static

Definition at line 31 of file numeral.cpp.