TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ split()

template<typename BasicJsonType >
static std::vector< std::string > nlohmann::json_pointer< BasicJsonType >::split ( const std::string &  reference_string)
inlinestaticprivate

split the string input to reference tokens

Note
This function is only called by the json_pointer constructor. All exceptions below are documented there.
Exceptions
parse_error.107if the pointer is not empty or begins with '/'
parse_error.108if character '~' is not followed by '0' or '1'

Definition at line 13337 of file json.hpp.

13338 {
13339 std::vector<std::string> result;
13340
13341 // special case: empty reference string -> no reference tokens
13342 if (reference_string.empty())
13343 {
13344 return result;
13345 }
13346
13347 // check if nonempty reference string begins with slash
13348 if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
13349 {
13350 JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
13351 }
13352
13353 // extract the reference tokens:
13354 // - slash: position of the last read slash (or end of string)
13355 // - start: position after the previous slash
13356 for (
13357 // search for the first slash after the first character
13358 std::size_t slash = reference_string.find_first_of('/', 1),
13359 // set the beginning of the first reference token
13360 start = 1;
13361 // we can stop if start == 0 (if slash == std::string::npos)
13362 start != 0;
13363 // set the beginning of the next reference token
13364 // (will eventually be 0 if slash == std::string::npos)
13365 start = (slash == std::string::npos) ? 0 : slash + 1,
13366 // find next slash
13367 slash = reference_string.find_first_of('/', start))
13368 {
13369 // use the text between the beginning of the reference token
13370 // (start) and the last slash (slash).
13371 auto reference_token = reference_string.substr(start, slash - start);
13372
13373 // check reference tokens are properly escaped
13374 for (std::size_t pos = reference_token.find_first_of('~');
13375 pos != std::string::npos;
13376 pos = reference_token.find_first_of('~', pos + 1))
13377 {
13378 JSON_ASSERT(reference_token[pos] == '~');
13379
13380 // ~ must be followed by 0 or 1
13381 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
13382 (reference_token[pos + 1] != '0' &&
13383 reference_token[pos + 1] != '1')))
13384 {
13385 JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
13386 }
13387 }
13388
13389 // finally, store the reference token
13390 detail::unescape(reference_token);
13391 result.push_back(reference_token);
13392 }
13393
13394 return result;
13395 }
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: json.hpp:2800
static void unescape(std::string &s)
string unescaping as described in RFC 6901 (Sect. 4)
Definition: json.hpp:2572