Sha256: 6a62cf7dcefc283ba0300a495cd090454f39ec24360e34e8d4b12aaf4a162b66

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/

#ifndef TAO_JSON_EVENTS_INVALID_STRING_TO_BINARY_HPP
#define TAO_JSON_EVENTS_INVALID_STRING_TO_BINARY_HPP

#include <utility>
#include <vector>

#include "../binary_view.hpp"
#include "../utf8.hpp"

namespace tao::json::events
{
   template< typename Consumer >
   struct invalid_string_to_binary
      : Consumer
   {
      using Consumer::Consumer;

      void string( const char* v )
      {
         string( std::string_view( v ) );
      }

      void string( std::string&& v )
      {
         if( internal::validate_utf8_nothrow( v ) ) {
            Consumer::string( std::move( v ) );
         }
         else {
            const auto* const data = reinterpret_cast< const std::byte* >( v.data() );
            Consumer::binary( std::vector< std::byte >( data, data + v.size() ) );
         }
      }

      void string( const std::string_view v )
      {
         if( internal::validate_utf8_nothrow( v ) ) {
            Consumer::string( v );
         }
         else {
            Consumer::binary( tao::binary_view( reinterpret_cast< const std::byte* >( v.data() ), v.size() ) );
         }
      }
   };

}  // namespace tao::json::events

#endif

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
couchbase-3.2.0-universal-darwin-20 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.2.0 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.1.1 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.1.1-universal-darwin-20 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.1.0 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.3 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.3-universal-darwin-20 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.2 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.1-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.1 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp