1 #ifndef _C4_YML_EXTRA_STRING_HPP_
2 #define _C4_YML_EXTRA_STRING_HPP_
4 #ifndef RYML_SINGLE_HEADER
5 #ifndef _C4_YML_COMMON_HPP_
12 C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
13 C4_SUPPRESS_WARNING_GCC_CLANG(
"-Wold-style-cast")
14 C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")
16 #ifndef RYML_STRING_SSO_SIZE
17 #define RYML_STRING_SSO_SIZE 128
20 #ifndef RYML_STRING_LIST_SSO_SIZE
21 #define RYML_STRING_LIST_SSO_SIZE 66
79 C4_ALWAYS_INLINE C4_HOT
operator csubstr() const noexcept {
return {
m_str,
m_size}; }
80 C4_ALWAYS_INLINE C4_HOT
operator substr() noexcept {
return {
m_str,
m_size}; }
104 cap = cap > sz ? cap : sz;
108 char *buf = (
char*) _RYML_CB_ALLOC(cb,
char, cap);
121 C4_ALWAYS_INLINE C4_HOT
void append(
char c)
127 C4_ALWAYS_INLINE C4_HOT
void append(csubstr cs)
140 RYML_ASSERT(pos <=
m_size);
145 char *C4_RESTRICT src =
m_str + pos;
146 memmove(src + 1, src,
m_size - pos);
157 RYML_ASSERT(pos <=
m_size);
165 char *C4_RESTRICT src =
m_str + pos;
166 memmove(src + cs.len, src,
m_size - pos);
167 memcpy(src, cs.str, cs.len);
178 RYML_ASSERT(pattern.len);
181 for(
size_t i =
m_size - pattern.len; i != (
size_t)-1; --i)
183 if(
m_str[i] == pattern[0])
186 for(
size_t j = 1; j < pattern.len; ++j)
188 if(
m_str[i + j] != pattern[j])
206 RYML_ASSERT(
m_str !=
nullptr);
217 void _cp(
string const* C4_RESTRICT that)
220 if(that->m_str != that->m_buf)
222 RYML_ASSERT(that->m_capacity >
sso_size);
223 RYML_ASSERT(that->m_size <= that->m_capacity);
227 RYML_ASSERT(that->m_capacity <=
sso_size);
228 RYML_ASSERT(that->m_size <= that->m_capacity);
231 memcpy(
m_str, that->m_str, that->m_size);
236 void _mv(
string *C4_RESTRICT that)
238 if(that->m_str != that->m_buf)
240 RYML_ASSERT(that->m_capacity >
sso_size);
241 RYML_ASSERT(that->m_size <= that->m_capacity);
246 RYML_ASSERT(that->m_capacity <=
sso_size);
247 RYML_ASSERT(that->m_size <= that->m_capacity);
248 memcpy(
m_buf, that->m_buf, that->m_size);
254 RYML_ASSERT(that->m_str != this->m_buf);
255 that->m_str = that->m_buf;
295 for(
id_type i = 0; i < that.m_size; ++i)
303 for(
id_type i = 0; i < that.m_size; ++i)
304 new ((
void*)(
m_arr+i))
string(std::move(that.m_arr[i]));
305 that.~string_vector();
312 for(
id_type i = 0; i < that.m_size; ++i)
313 m_arr[i].
operator=(that.m_arr[i]);
322 for(
id_type i = 0; i < that.m_size; ++i)
323 m_arr[i].
operator=(std::move(that.m_arr[i]));
325 that.~string_vector();
331 RYML_ASSERT(
m_arr !=
nullptr);
375 cap = cap > sz ? cap : sz;
379 string *buf = (
string*) _RYML_CB_ALLOC(cb,
string, cap);
381 new ((
void*)(buf + i))
string(std::move(
m_arr[i]));
398 new ((
void*)&ret)
string();
419 C4_SUPPRESS_WARNING_GCC_POP
Common utilities and infrastructure used by ryml.
#define RYML_NOEXCEPT
Conditionally expands to noexcept when RYML_USE_ASSERT is 0 and is empty otherwise.
Callbacks const & get_callbacks()
get the global callbacks
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
@ npos
a null string position
a c-style callbacks class.