Sha256: e310c68ff6a57af62aaf6096982b615caffc457ffd25ae590e8f29e4eb29071d

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

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

#ifndef TAO_JSON_JAXN_EVENTS_TO_PRETTY_STREAM_HPP
#define TAO_JSON_JAXN_EVENTS_TO_PRETTY_STREAM_HPP

#include "../../internal/hexdump.hpp"

#include "../../external/ryu.hpp"

#include "../../events/to_pretty_stream.hpp"

#include "../is_identifier.hpp"

namespace tao::json::jaxn::events
{
   // Events consumer to build a JAXN string representation.

   struct to_pretty_stream
      : json::events::to_pretty_stream
   {
      using json::events::to_pretty_stream::to_pretty_stream;

      using json::events::to_pretty_stream::number;

      void number( const double v )
      {
         next();
         if( !std::isfinite( v ) ) {
            if( std::isnan( v ) ) {
               os.write( "NaN", 3 );
            }
            else if( v < 0 ) {
               os.write( "-Infinity", 9 );
            }
            else {
               os.write( "Infinity", 8 );
            }
         }
         else {
            ryu::d2s_stream( os, v );
         }
      }

      void binary( const tao::binary_view v )
      {
         next();
         os.put( '$' );
         json::internal::hexdump( os, v );
      }

      void key( const std::string_view v )
      {
         if( jaxn::is_identifier( v ) ) {
            next();
            os.write( v.data(), v.size() );
         }
         else {
            string( v );
         }
         os.write( ": ", 2 );
         first = true;
         after_key = true;
      }
   };

}  // namespace tao::json::jaxn::events

#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/jaxn/events/to_pretty_stream.hpp
couchbase-3.4.4 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp
couchbase-3.4.3 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp
couchbase-3.4.2 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp
couchbase-3.4.1 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp
couchbase-3.4.0 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp
couchbase-3.3.0 ext/couchbase/third_party/json/include/tao/json/jaxn/events/to_pretty_stream.hpp