Sha256: de10a5bd806b5a682cbb2535e0d50324f80957410a916f344a22cabd34958efb

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

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

#ifndef TAO_JSON_UTF8_HPP
#define TAO_JSON_UTF8_HPP

#include <tao/pegtl/memory_input.hpp>
#include <tao/pegtl/parse_error.hpp>
#include <tao/pegtl/utf8.hpp>

namespace tao::json
{
   enum class utf8_mode : bool
   {
      check,
      trust
   };

   namespace internal
   {
      template< typename Input >
      bool consume_utf8_impl( Input& in, const std::size_t todo )
      {
         std::size_t i = 0;
         while( i < todo ) {
            const auto p = pegtl::internal::peek_utf8::peek( in ).size;
            if( ( p == 0 ) || ( ( i += p ) > todo ) ) {
               return false;
            }
            in.bump_in_this_line( p );
         }
         return true;
      }

      template< utf8_mode M, typename Input >
      void consume_utf8_throws( Input& in, const std::size_t todo )
      {
         if constexpr( M == utf8_mode::trust ) {
            in.bump_in_this_line( todo );
         }
         else if( !consume_utf8_impl( in, todo ) ) {
            throw pegtl::parse_error( "invalid utf8", in );
         }
      }

      inline bool validate_utf8_nothrow( const std::string_view sv ) noexcept
      {
         pegtl::memory_input in( sv, "validate_utf8" );
         return consume_utf8_impl( in, sv.size() );
      }

   }  // namespace internal

}  // namespace tao::json

#endif

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
couchbase-3.4.5 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.4.4 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.4.3 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.4.2 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.4.1 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.4.0 ext/couchbase/third_party/json/include/tao/json/utf8.hpp
couchbase-3.3.0 ext/couchbase/third_party/json/include/tao/json/utf8.hpp