Sha256: fc18a3b0b9f9a21a691703fce0acd878c15b0b910f3065eb7c0d44c8ce0f3cde

Contents?: true

Size: 1.26 KB

Versions: 24

Compression:

Stored size: 1.26 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 std::byte* 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

24 entries across 24 versions & 1 rubygems

Version Path
couchbase-3.0.0-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.beta.1-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.beta.1 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.5-x86_64-linux ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.5-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.5-x86_64-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.5 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.4-x86_64-linux ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.4-x86_64-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.4-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.4 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.3-x86_64-linux ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.3-x86_64-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.3-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.3 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.2-x86_64-linux ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.2-x86_64-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.2-universal-darwin-19 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp
couchbase-3.0.0.alpha.2 ext/third_party/json/include/tao/json/events/invalid_string_to_binary.hpp