@@ -14,34 +14,88 @@ namespace utf8
14
14
std::istream& operator >>(std::istream& is, ustring& ustr)
15
15
{
16
16
// TODO: .............................................
17
+ throw std::runtime_error (" operator >> for utf8::ustring not implemented yet !" );
17
18
}
18
19
19
20
// -----------------------------------------------------------------------------------------------------------------
20
- constexpr ustring::ustring ()
21
+ ustring::ustring ()
21
22
{
22
23
Symbols_Info.reserve (100 );
23
24
String.reserve (100 );
24
25
}
25
26
26
27
// -----------------------------------------------------------------------------------------------------------------
27
- ustring::ustring (const char * utf8_str )
28
+ ustring::ustring (const std:: size_t bytes_reserve )
28
29
{
29
- Symbols_Info.reserve (100 );
30
- String.reserve (100 );
30
+ Symbols_Info.reserve (bytes_reserve);
31
+ String.reserve (bytes_reserve);
32
+ }
31
33
32
- // TODO: redo this part
33
- std::size_t next_symbol_position{}; // next symbol position in bytes
34
- for (std::size_t i{}; utf8_str[i] != ' \0 ' ; ++i)
35
- {
36
- String.push_back (utf8_str[i]);
37
- if (next_symbol_position == i) // if it`s beginning of a symbol
38
- {
39
- std::uint8_t symbol_size{ Get_Size_Of_Symbol (utf8_str[i]) };
40
- Symbols_Info.push_back (SSymbol_Info{ symbol_size, next_symbol_position });
34
+ // -----------------------------------------------------------------------------------------------------------------
35
+ ustring::ustring (const char * default_string) : ustring(100 )
36
+ {
37
+ Copy_With_Metadata_To_Internal_String (default_string);
38
+ }
41
39
42
- next_symbol_position += symbol_size;
43
- }
40
+ // -----------------------------------------------------------------------------------------------------------------
41
+ ustring::ustring (const char * default_string, const std::size_t bytes_reserve) : ustring(bytes_reserve)
42
+ {
43
+ Copy_With_Metadata_To_Internal_String (default_string);
44
+ }
45
+
46
+ // -----------------------------------------------------------------------------------------------------------------
47
+ ustring::ustring (const std::basic_string<char >& default_string) : ustring(default_string.c_str(), default_string.size() * 2 )
48
+ { }
49
+
50
+ // -----------------------------------------------------------------------------------------------------------------
51
+ ustring::ustring (const std::basic_string_view<char >& default_string) : ustring(default_string.data(), default_string.size() * 2 )
52
+ { }
53
+
54
+ // -----------------------------------------------------------------------------------------------------------------
55
+ ustring::ustring (const ustring& other)
56
+ {
57
+ String = other.String ;
58
+ Symbols_Info = other.Symbols_Info ;
59
+ }
60
+
61
+ // -----------------------------------------------------------------------------------------------------------------
62
+ ustring::ustring (ustring&& other) noexcept
63
+ {
64
+ String = std::move (other.String );
65
+ Symbols_Info = std::move (other.Symbols_Info );
66
+ }
67
+
68
+ // -----------------------------------------------------------------------------------------------------------------
69
+ ustring& ustring::operator =(const ustring& other)
70
+ {
71
+ if (this != &other)
72
+ {
73
+ String = other.String ;
74
+ Symbols_Info = other.Symbols_Info ;
44
75
}
76
+
77
+ return *this ;
78
+ }
79
+
80
+ // -----------------------------------------------------------------------------------------------------------------
81
+ ustring& ustring::operator =(ustring&& other) noexcept
82
+ {
83
+ String = std::move (other.String );
84
+ Symbols_Info = std::move (other.Symbols_Info );
85
+
86
+ return *this ;
87
+ }
88
+
89
+ // -----------------------------------------------------------------------------------------------------------------
90
+ bool ustring::operator ==(const ustring& other) const
91
+ {
92
+ return (String == other.String );
93
+ }
94
+
95
+ // -----------------------------------------------------------------------------------------------------------------
96
+ bool ustring::operator !=(const ustring& other) const
97
+ {
98
+ return (String != other.String );
45
99
}
46
100
47
101
// -----------------------------------------------------------------------------------------------------------------
@@ -80,6 +134,12 @@ namespace utf8
80
134
return String;
81
135
}
82
136
137
+ // -----------------------------------------------------------------------------------------------------------------
138
+ const std::basic_string<char >& ustring::get_c_str () const
139
+ {
140
+ return String;
141
+ }
142
+
83
143
// -----------------------------------------------------------------------------------------------------------------
84
144
std::uint8_t ustring::Get_Size_Of_Symbol (std::uint8_t symbol)
85
145
{
@@ -111,4 +171,21 @@ namespace utf8
111
171
Symbols_Info[i].Symbol_Offset += new_offset;
112
172
}
113
173
}
174
+
175
+ // -----------------------------------------------------------------------------------------------------------------
176
+ void ustring::Copy_With_Metadata_To_Internal_String (const char * default_string)
177
+ {
178
+ std::size_t next_symbol_position{}; // next symbol position in bytes
179
+ for (std::size_t i{}; default_string[i] != ' \0 ' ; ++i)
180
+ {
181
+ String.push_back (default_string[i]);
182
+ if (next_symbol_position == i) // if it`s beginning of a symbol
183
+ {
184
+ std::uint8_t symbol_size{ Get_Size_Of_Symbol (default_string[i]) };
185
+ Symbols_Info.push_back (SSymbol_Info{ symbol_size, next_symbol_position });
186
+
187
+ next_symbol_position += symbol_size;
188
+ }
189
+ }
190
+ }
114
191
}
0 commit comments