These types are imported from the c4core library into the ryml namespace You may have noticed above the use of a csubstr class. This class is defined in another library, c4core, which is imported by ryml. This is a library I use with my projects consisting of multiplatform low-level utilities. One of these is c4::csubstr (the name comes from "constant substring") which is a non-owning read-only string view, with many methods that make it practical to use (I would certainly argue more practical than std::string). In fact, c4::csubstr and its writeable counterpart c4::substr are the workhorses of the ryml parsing and serialization code.
1153 const char foobar_str[] =
"foobar";
1155 CHECK(s ==
"foobar");
1156 CHECK(s.size() == 6);
1157 CHECK(s.data() == foobar_str);
1158 CHECK(s.size() == s.len);
1159 CHECK(s.data() == s.str);
1164 const char foobar_str[] =
"foobar";
1166 CHECK(s ==
"foobar");
1167 CHECK(s !=
"foobar0");
1176 CHECK(s ==
"foobar");
1177 CHECK(s !=
"foobar0");
1189 const char *foobar_str =
"foobar";
1191 CHECK(s ==
"foobar");
1192 CHECK(s !=
"foobar0");
1206 std::string foobar_str =
"foobar";
1208 CHECK(s ==
"foobar");
1209 CHECK(s !=
"foobar0");
1222 CHECK(cfoo.data() == buf);
1231 char const foobar_str_ro[] =
"foobar";
1232 char foobar_str_rw[] =
"foobar";
1233 static_assert(std::is_array<decltype(foobar_str_ro)>::value,
"this is an array");
1234 static_assert(std::is_array<decltype(foobar_str_rw)>::value,
"this is an array");
1239 CHECK(foobar.
size() == strlen(foobar_str_ro));
1240 CHECK(foobar ==
"foobar");
1246 CHECK(foobar.
size() == strlen(foobar_str_rw));
1247 CHECK(foobar ==
"foobar");
1253 CHECK(foobar.
size() == strlen(foobar_str_rw));
1254 CHECK(foobar ==
"foobar");
1265 char const* foobar_str_ro =
"foobar";
1266 char foobar_str_rw_[] =
"foobar";
1267 char * foobar_str_rw = foobar_str_rw_;
1268 static_assert(!std::is_array<decltype(foobar_str_ro)>::value,
"this is a decayed pointer");
1269 static_assert(!std::is_array<decltype(foobar_str_rw)>::value,
"this is a decayed pointer");
1275 CHECK(foobar.
size() == strlen(foobar_str_ro));
1276 CHECK(foobar ==
"foobar");
1282 CHECK(foobar.
size() == strlen(foobar_str_rw));
1283 CHECK(foobar ==
"foobar");
1289 CHECK(foobar.
size() == strlen(foobar_str_rw));
1290 CHECK(foobar ==
"foobar");
1300 char buf[] =
"foobar";
1302 CHECK(foobar ==
"foobar");
1303 foobar[0] =
'F';
CHECK(foobar ==
"Foobar");
1304 foobar.
back() =
'R';
CHECK(foobar ==
"FoobaR");
1316 foobar.
fill(
'.');
CHECK(foobar ==
"......");
1328 CHECK(s.
sub(0, 12) ==
"fooFOObarBAR");
1388 CHECK(some ==
"some");
1389 CHECK(s ==
"some substring");
1392 char result[32] = {0};
1393 std::snprintf(result,
sizeof(result),
"%.*s", (
int)some.
len, some.
str);
1394 printf(
"~~~%s~~~\n", result);
1404 char result[32] = {0};
1405 std::snprintf(result,
sizeof(result),
"%s", some.
str);
1415 CHECK(some ==
"some");
1416 CHECK(s ==
"some substring");
1419 std::stringstream ss;
1421 CHECK(ss.str() ==
"some substring");
1422 CHECK(ss.str() == s);
1430 std::stringstream ss;
1432 CHECK(ss.str() ==
"some substring");
1433 CHECK(ss.str() == s);
1437 std::stringstream ss;
1439 CHECK(ss.str() ==
"some substring");
1440 CHECK(ss.str() == s);
1444 std::stringstream ss;
1446 CHECK(ss.str() ==
"some");
1447 CHECK(ss.str() == some);
1484 CHECK(
ryml::csubstr(
" \t\n\rcontents without whitespace\t \n\r").trim(
"\t \n\r") ==
"contents without whitespace");
1505 CHECK(aaa___bbb.
trim (
'c') == aaa___bbb);
1524 CHECK(aaa___bbb.
trim (
"cd") == aaa___bbb);
1529 CHECK(
ryml::csubstr(
"'this is is single quoted'" ).unquoted() ==
"this is is single quoted");
1530 CHECK(
ryml::csubstr(
"\"this is is double quoted\"").unquoted() ==
"this is is double quoted");
1848 CHECK(
ryml::csubstr(
"/path/to/file.tar.gz").name_wo_extshort() ==
"/path/to/file.tar");
1854 using namespace ryml;
1855 csubstr parts[] = {
"aa",
"bb",
"cc",
"dd",
"ee",
"ff"};
1859 CHECK(part == parts[count++]);
1865 CHECK(part == parts[count++]);
1871 CHECK(part == parts[count++]);
1880 const bool skip_empty =
true;
basic_substring trimr(const C c) const
trim the character c from the right
bool begins_with_any(ro_substr chars) const noexcept
true if the first character of the string is any of the given chars
basic_substring trim(const C c) const
trim the character c left and right
bool is_super(ro_substr const that) const noexcept
true if that is a substring of *this (ie, from the same buffer)
basic_substring stripr(ro_substr pattern) const
remove a pattern from the right
bool overlaps(ro_substr const that) const noexcept
true if there is overlap of at least one element between that and *this
C * str
a restricted pointer to the first character of the substring
size_t first_of(const C c, size_t start=0) const
auto fill(C val) -> typename std::enable_if< !std::is_const< U >::value, void >::type
fill the entire contents with the given val
bool ends_with(const C c) const noexcept
true if the last character of the string is c
substr to_substr(char(&s)[N]) noexcept
basic_substring right_of(size_t pos) const noexcept
return [pos+1, len[
auto replace(C value, C repl, size_t pos=0) -> typename std::enable_if< !std::is_const< U >::value, size_t >::type
replace every occurrence of character value with the character repl
basic_substring first(size_t num) const noexcept
return the first num elements: [0,num[
size_t last_not_of(const C c) const
size_t last_of(const C c, size_t start=npos) const
size_t size() const noexcept
basic_substring stripl(ro_substr pattern) const
remove a pattern from the left
auto reverse() -> typename std::enable_if< !std::is_const< U >::value, void >::type
reverse in place
size_t count(const C c, size_t pos=0) const
count the number of occurrences of c
auto reverse_sub(size_t ifirst, size_t num) -> typename std::enable_if< !std::is_const< U >::value, void >::type
revert a subpart in place
basic_substring sub(size_t first) const noexcept
return [first,len[
csubstr to_csubstr(const char(&s)[N]) noexcept
basic_substring< const char > csubstr
an immutable string view
#define CHECK(predicate)
a testing assertion, used only in this quickstart
basic_substring offs(size_t left, size_t right) const noexcept
offset from the ends: return [left,len-right[ ; ie, trim a number of characters from the left and rig...
auto toupper() -> typename std::enable_if< !std::is_const< U >::value, void >::type
convert the string to upper-case
basic_substring range(size_t first, size_t last=npos) const noexcept
return [first,last[.
basic_substring triml(const C c) const
trim left
auto reverse_range(size_t ifirst, size_t ilast) -> typename std::enable_if< !std::is_const< U >::value, void >::type
revert a range in place
size_t len
the length of the substring
basic_substring select(const C c, size_t pos=0) const
get the substr consisting of the first occurrence of c after pos, or an empty substr if none occurs ...
auto tolower() -> typename std::enable_if< !std::is_const< U >::value, void >::type
convert the string to lower-case
basic_substring last(size_t num) const noexcept
return the last num elements: [len-num,len[
size_t find(const C c, size_t start_pos=0) const
size_t first_not_of(const C c) const
bool begins_with(const C c) const noexcept
true if the first character of the string is c
bool ends_with_any(ro_substr chars) const noexcept
true if the last character of the string is any of the given chars
basic_substring left_of(size_t pos) const noexcept
return [0, pos[ .
bool is_sub(ro_substr const that) const noexcept
true if *this is a substring of that (ie, from the same buffer)