2323
2424#include < jsoncons/config/compiler_support.hpp>
2525#include < jsoncons/config/jsoncons_config.hpp>
26- #include < jsoncons/conversion_result.hpp>
26+ // #include <jsoncons/conversion_result.hpp>
2727#include < jsoncons/utility/more_type_traits.hpp>
28- #include < jsoncons/utility/read_number.hpp>
2928
3029namespace jsoncons {
3130
@@ -58,11 +57,10 @@ class bigint_storage : private std::allocator_traits<Allocator>:: template rebin
5857 {
5958 ValueType* data_;
6059 size_type size_;
61- size_type capacity_;
6260
6361 public:
64- storage_view (ValueType* data, size_type size, size_type capacity )
65- : data_(data), size_(size), capacity_(capacity)
62+ storage_view (ValueType* data, size_type size)
63+ : data_(data), size_(size)
6664 {
6765 }
6866
@@ -85,12 +83,6 @@ class bigint_storage : private std::allocator_traits<Allocator>:: template rebin
8583 {
8684 return size_;
8785 }
88-
89- size_type capacity () const
90- {
91- return capacity_;
92- }
93-
9486 ValueType* begin ()
9587 {
9688 return data_;
@@ -512,15 +504,15 @@ class bigint_storage : private std::allocator_traits<Allocator>:: template rebin
512504 storage_view<word_type> get_storage_view ()
513505 {
514506 return common_.is_allocated_ ?
515- storage_view<word_type>{allocated_.data_ , allocated_.size_ , allocated_. capacity_ } :
516- storage_view<word_type>{inlined_.values_ , inlined_.size_ , inlined_capacity };
507+ storage_view<word_type>{allocated_.data_ , allocated_.size_ } :
508+ storage_view<word_type>{inlined_.values_ , inlined_.size_ };
517509 }
518510
519511 storage_view<const word_type> get_storage_view () const
520512 {
521513 return common_.is_allocated_ ?
522- storage_view<const word_type>{allocated_.data_ , allocated_.size_ , allocated_. capacity_ } :
523- storage_view<const word_type>{inlined_.values_ , inlined_.size_ , inlined_capacity };
514+ storage_view<const word_type>{allocated_.data_ , allocated_.size_ } :
515+ storage_view<const word_type>{inlined_.values_ , inlined_.size_ };
524516 }
525517
526518 void resize (size_type new_length)
@@ -581,11 +573,11 @@ template <typename Allocator>
581573class basic_bigint ;
582574
583575template <typename CharT, typename Allocator>
584- utility::to_number_result <CharT> to_bigint (const CharT* data, std::size_t length,
576+ to_bigint_result <CharT> to_bigint (const CharT* data, std::size_t length,
585577 basic_bigint<Allocator>& value, const Allocator& alloc);
586578
587579template <typename CharT>
588- utility::to_number_result <CharT> to_bigint (const CharT* data, std::size_t length,
580+ to_bigint_result <CharT> to_bigint (const CharT* data, std::size_t length,
589581 basic_bigint<std::allocator<uint64_t >>& value);
590582
591583/*
@@ -728,13 +720,13 @@ class basic_bigint
728720 }
729721
730722 template <typename CharT>
731- static utility::to_number_result <CharT> parse (const std::basic_string<CharT>& s, basic_bigint<Allocator>& value)
723+ static to_bigint_result <CharT> parse (const std::basic_string<CharT>& s, basic_bigint<Allocator>& value)
732724 {
733725 return parse<CharT>(s.data (), s.size (), value);
734726 }
735727
736728 template <typename CharT>
737- static utility::to_number_result <CharT> parse (const CharT* s, basic_bigint<Allocator>& value)
729+ static to_bigint_result <CharT> parse (const CharT* s, basic_bigint<Allocator>& value)
738730 {
739731 auto r = parse (s, std::char_traits<CharT>::length (s), value);
740732 if (r.ec != std::errc{})
@@ -1986,57 +1978,15 @@ basic_bigint<Allocator> bsqrt(const basic_bigint<Allocator>& a)
19861978 return x < q ? x : q;
19871979}
19881980
1989- template <typename CharT, typename Allocator>
1990- utility::to_number_result<CharT> to_bigint (const CharT* data, std::size_t length,
1991- basic_bigint<Allocator>& value, const Allocator& alloc)
1992- {
1993- if (JSONCONS_UNLIKELY (length == 0 ))
1994- {
1995- return utility::to_number_result<CharT>(data, std::errc::invalid_argument);
1996- }
1997-
1998- if (*data == ' -' )
1999- {
2000- return to_bigint (data+1 , length-1 , true , value, alloc);
2001- }
2002- else
2003- {
2004- return to_bigint (data, length, false , value, alloc);
2005- }
2006- }
2007-
2008- template <typename CharT>
2009- utility::to_number_result<CharT> to_bigint (const CharT* s, basic_bigint<std::allocator<uint64_t >>& value)
2010- {
2011- return to_bigint (s, std::char_traits<CharT>::length (s), value);
2012- }
2013-
2014- template <typename CharT>
2015- utility::to_number_result<CharT> to_bigint (const CharT* data, std::size_t length,
2016- basic_bigint<std::allocator<uint64_t >>& value)
2017- {
2018- if (JSONCONS_UNLIKELY (length == 0 ))
2019- {
2020- return utility::to_number_result<CharT>(data, std::errc::invalid_argument);
2021- }
2022-
2023- if (*data == ' -' )
2024- {
2025- return to_bigint (data+1 , length-1 , true , value, std::allocator<uint64_t >{});
2026- }
2027- else
2028- {
2029- return to_bigint (data, length, false , value, std::allocator<uint64_t >{});
2030- }
2031- }
1981+ namespace detail {
20321982
20331983template <typename CharT, typename Allocator>
2034- utility::to_number_result <CharT> to_bigint (const CharT* data, std::size_t length,
1984+ to_bigint_result <CharT> to_bigint (const CharT* data, std::size_t length,
20351985 bool neg, basic_bigint<Allocator>& value, const Allocator& alloc)
20361986{
20371987 if (JSONCONS_UNLIKELY (length == 0 ))
20381988 {
2039- return utility::to_number_result <CharT>(data, std::errc::invalid_argument);
1989+ return to_bigint_result <CharT>(data, std::errc::invalid_argument);
20401990 }
20411991
20421992 using word_type = typename basic_bigint<Allocator>::word_type;
@@ -2051,7 +2001,7 @@ utility::to_number_result<CharT> to_bigint(const CharT* data, std::size_t length
20512001 if (p == last)
20522002 {
20532003 value = std::move (basic_bigint<Allocator>{0 , alloc});
2054- return utility::to_number_result <CharT>(last, std::errc{});
2004+ return to_bigint_result <CharT>(last, std::errc{});
20552005 }
20562006 std::size_t num_digits = last - data;
20572007 std::size_t num_words;
@@ -2061,8 +2011,8 @@ utility::to_number_result<CharT> to_bigint(const CharT* data, std::size_t length
20612011 }
20622012 else
20632013 {
2064- std::size_t num_bits = (std::size_t )(((num_digits* detail::bits_per_digit[10 ]) >> 10 ) + 1 );
2065- num_words = (num_bits+ 63 ) >> 6 ;
2014+ std::size_t num_bits = (std::size_t )(((num_digits * detail::bits_per_digit[10 ]) >> 10 ) + 1 );
2015+ num_words = (num_bits + 63 ) >> 6 ;
20662016 }
20672017
20682018 basic_bigint<Allocator> v (0 , alloc);
@@ -2076,7 +2026,7 @@ utility::to_number_result<CharT> to_bigint(const CharT* data, std::size_t length
20762026 v = (v * 10u ) + (word_type)(c - ' 0' );
20772027 break ;
20782028 default :
2079- return utility::to_number_result <CharT>(data+ i, std::errc::invalid_argument);
2029+ return to_bigint_result <CharT>(data + i, std::errc::invalid_argument);
20802030 }
20812031 }
20822032
@@ -2092,7 +2042,53 @@ utility::to_number_result<CharT> to_bigint(const CharT* data, std::size_t length
20922042 }
20932043
20942044 value = std::move (v);
2095- return utility::to_number_result<CharT>(last, std::errc{});
2045+ return to_bigint_result<CharT>(last, std::errc{});
2046+ }
2047+
2048+ } // namespace detail
2049+
2050+ template <typename CharT, typename Allocator>
2051+ to_bigint_result<CharT> to_bigint (const CharT* data, std::size_t length,
2052+ basic_bigint<Allocator>& value, const Allocator& alloc)
2053+ {
2054+ if (JSONCONS_UNLIKELY (length == 0 ))
2055+ {
2056+ return to_bigint_result<CharT>(data, std::errc::invalid_argument);
2057+ }
2058+
2059+ if (*data == ' -' )
2060+ {
2061+ return jsoncons::detail::to_bigint (data + 1 , length - 1 , true , value, alloc);
2062+ }
2063+ else
2064+ {
2065+ return jsoncons::detail::to_bigint (data, length, false , value, alloc);
2066+ }
2067+ }
2068+
2069+ template <typename CharT>
2070+ to_bigint_result<CharT> to_bigint (const CharT* s, basic_bigint<std::allocator<uint64_t >>& value)
2071+ {
2072+ return to_bigint (s, std::char_traits<CharT>::length (s), value);
2073+ }
2074+
2075+ template <typename CharT>
2076+ to_bigint_result<CharT> to_bigint (const CharT* data, std::size_t length,
2077+ basic_bigint<std::allocator<uint64_t >>& value)
2078+ {
2079+ if (JSONCONS_UNLIKELY (length == 0 ))
2080+ {
2081+ return to_bigint_result<CharT>(data, std::errc::invalid_argument);
2082+ }
2083+
2084+ if (*data == ' -' )
2085+ {
2086+ return jsoncons::detail::to_bigint (data+1 , length-1 , true , value, std::allocator<uint64_t >{});
2087+ }
2088+ else
2089+ {
2090+ return jsoncons::detail::to_bigint (data, length, false , value, std::allocator<uint64_t >{});
2091+ }
20962092}
20972093
20982094using bigint = basic_bigint<std::allocator<uint64_t >>;
0 commit comments