Sha256: 25871b8b8f940c6b6c8a20667e9e442628afa6eaaed0ea9ad36fa46b3f4ec252
Contents?: true
Size: 1.7 KB
Versions: 7
Compression:
Stored size: 1.7 KB
Contents
// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/json/ #ifndef TAO_JSON_INTERNAL_ESCAPE_HPP #define TAO_JSON_INTERNAL_ESCAPE_HPP #include <ostream> #include <sstream> #include <string> #include <string_view> #include <utility> namespace tao::json::internal { inline void escape( std::ostream& os, const std::string_view s ) { static const char* h = "0123456789abcdef"; const char* p = s.data(); const char* l = p; const char* const e = p + s.size(); while( p != e ) { const unsigned char c = *p; if( c == '\\' || c == '"' ) { os.write( l, p - l ); l = ++p; os.put( '\\' ); os.put( c ); } else if( c < 32 || c == 127 ) { os.write( l, p - l ); l = ++p; switch( c ) { case '\b': os << "\\b"; break; case '\f': os << "\\f"; break; case '\n': os << "\\n"; break; case '\r': os << "\\r"; break; case '\t': os << "\\t"; break; default: os << "\\u00" << h[ ( c & 0xf0 ) >> 4 ] << h[ c & 0x0f ]; } } else { ++p; } } os.write( l, p - l ); } [[nodiscard]] inline std::string escape( const std::string_view s ) { std::ostringstream oss; escape( oss, s ); return std::move( oss ).str(); } } // namespace tao::json::internal #endif
Version data entries
7 entries across 7 versions & 1 rubygems