Sha256: d10637545f03c1f8b52685393a3ac2689704d483f701d867f50ab8bb8c6d110c

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 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_STREAM_HPP
#define TAO_JSON_JAXN_EVENTS_TO_STREAM_HPP

#include "../../events/to_stream.hpp"

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

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

#include "../is_identifier.hpp"

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

   struct to_stream
      : json::events::to_stream
   {
      using json::events::to_stream::number;
      using json::events::to_stream::to_stream;

      void number( const double v )
      {
         next();
         if( !std::isfinite( v ) ) {
            if( std::isnan( v ) ) {
               os << "NaN";
            }
            else if( v < 0 ) {
               os << "-Infinity";
            }
            else {
               os << "Infinity";
            }
         }
         else {
            ryu::d2s_stream( 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.put( ':' );
         first = true;
      }

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

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