Sha256: 71bb6fbcd0299276dd67f9da90d5c1fcbcc8ff647b7308ac661a806905fbbdc4

Contents?: true

Size: 1.5 KB

Versions: 24

Compression:

Stored size: 1.5 KB

Contents

// Copyright (c) 2018-2020 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 "external/pegtl/memory_input.hpp"
#include "external/pegtl/parse.hpp"
#include "external/pegtl/rules.hpp"
#include "external/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, pegtl::internal::peek_utf8::max_input_size ).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

24 entries across 24 versions & 1 rubygems

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