Lolly 1.4.27
Loading...
Searching...
No Matches
string_u16.cpp
Go to the documentation of this file.
1
2/** \file string_u16.cpp
3 * \copyright GPLv3
4 * \details Strings with different type of char, and corresponding readonly
5 * view of string. Zero-characters are allowed in strings.
6 * \author jingkaimori
7 * \date 2024
8 */
9
10#include "string_u16.hpp"
11#include "minmax.hpp"
12
13namespace lolly {
14namespace data {
15
16static inline constexpr int
17round_length (int n) {
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}
25
27 : n (n2), a_N (round_length (n)),
28 a ((n == 0) ? ((char16_t*) NULL) : tm_new_array<char16_t> (a_N)) {}
29
30void
32 int nn= round_length (n);
33 int mm= round_length (m);
34 if (mm != nn) {
35 if (mm != 0) {
36 if (nn != 0) {
37 a_N= mm;
39 }
40 else {
41 a_N= mm;
43 }
44 }
45 else if (nn != 0) {
47 a_N= 0;
48 a = NULL;
49 };
50 }
51 n= m;
52}
53
54int
56 int old_n= n;
57 n+= delta;
58 reserve (n);
59 return old_n;
60}
61
62void
64 int old_size= a_N;
65 if (new_n != 0) {
66 if (old_size == 0) {
69 }
70 else if (old_size < new_n) {
73 }
74 }
75 else {
76 if (old_size != 0) {
78 a = NULL;
79 a_N= 0;
80 };
81 }
82}
83
85 rep->a[0]= c;
86};
87
89 : rep (tm_new<string_u16_rep> (c.N)) {
90 for (int i= 0; i < c.N; i++)
91 rep->a[i]= c.a[i];
92};
93
94string_u16::string_u16 (char16_t c, int n) : rep (tm_new<string_u16_rep> (n)) {
95 for (int i= 0; i < n; i++)
96 rep->a[i]= c;
97};
98
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};
107
108string_u16
110 return copy ((string_u16_view) a);
111};
112
114operator<< (string_u16& a, char16_t ch) {
115 int old_a_N= a->expand_or_shrink_by (1);
116 a[old_a_N] = ch;
117 return a;
118};
119
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};
128
129string_u16
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};
141
142} // namespace data
143} // namespace lolly
blackbox b[13]
The list class represents a linked list.
Definition list.hpp:48
void resize(int n)
expand (or shrink) string to given length n, and try to release memory when string is shrinked.
void reserve(int n)
reserve memory space to contain at least n word in the whole string. Do not affect length of string,...
int expand_or_shrink_by(int delta)
expand (or shrink) string by delta, but do not release memory when string is shrinked.
C * tm_new_array(int n)
C * tm_new()
void tm_delete_array(C *Ptr)
int N(lolly_tree< T > t)
lolly_tree< T > operator*(lolly_tree< T > t1, lolly_tree< T > t2)
static constexpr int round_length(int n)
lolly_tree< T > copy(lolly_tree< T > t)
lolly_tree< T > & operator<<(lolly_tree< T > &t, lolly_tree< T > t2)
base class of resources
Definition resource.hpp:23
url delta(url base, url u)
Definition url.cpp:469