Sha256: 14a609e18645460445dd34dd268b526c1cadfa13111ec217a95dae7f69374e05

Contents?: true

Size: 1.47 KB

Versions: 34

Compression:

Stored size: 1.47 KB

Contents

// Copyright (c) 2017-2020 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

34 entries across 34 versions & 1 rubygems

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