123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #pragma once
- #include <nlohmann/detail/abi_macros.hpp>
- NLOHMANN_JSON_NAMESPACE_BEGIN
- namespace detail
- {
- template<typename StringType>
- inline void replace_substring(StringType& s, const StringType& f,
- const StringType& t)
- {
- JSON_ASSERT(!f.empty());
- for (auto pos = s.find(f);
- pos != StringType::npos;
- s.replace(pos, f.size(), t),
- pos = s.find(f, pos + t.size()))
- {}
- }
- template<typename StringType>
- inline StringType escape(StringType s)
- {
- replace_substring(s, StringType{"~"}, StringType{"~0"});
- replace_substring(s, StringType{"/"}, StringType{"~1"});
- return s;
- }
- template<typename StringType>
- static void unescape(StringType& s)
- {
- replace_substring(s, StringType{"~1"}, StringType{"/"});
- replace_substring(s, StringType{"~0"}, StringType{"~"});
- }
- }
- NLOHMANN_JSON_NAMESPACE_END
|