Sha256: e2f2af947a38e9f30681d3fab2429fdd125520f256dd0aa413f0ccabb1e05a5c

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 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_EVENTS_KEY_SNAKE_CASE_TO_CAMEL_CASE_HPP
#define TAO_JSON_EVENTS_KEY_SNAKE_CASE_TO_CAMEL_CASE_HPP

#include <cctype>
#include <string>
#include <string_view>

namespace tao::json::events
{
   template< typename Consumer >
   struct key_snake_case_to_camel_case
      : Consumer
   {
      using Consumer::Consumer;

      void key( const std::string_view v )
      {
         std::string r;
         r.reserve( v.size() );
         bool active = false;
         for( const auto c : v ) {
            if( active ) {
               if( c == '_' ) {
                  r += c;
               }
               else if( std::isupper( c ) != 0 ) {
                  r += '_';
                  r += c;
                  active = false;
               }
               else {
                  r += static_cast< char >( std::toupper( c ) );
                  active = false;
               }
            }
            else {
               if( c == '_' ) {
                  active = true;
               }
               else {
                  r += c;
               }
            }
         }
         if( active ) {
            r += '_';
         }
         Consumer::key( std::move( r ) );
      }
   };

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