@@ -20,7 +20,46 @@ namespace tao
2020 {
2121 namespace internal
2222 {
23- std::size_t token_to_index ( const std::string& key ) noexcept ;
23+ template < std::size_t = sizeof ( std::size_t ) >
24+ struct token_to_index ;
25+
26+ template <>
27+ struct token_to_index < 4 >
28+ {
29+ static std::size_t convert ( const std::string& key ) noexcept
30+ {
31+ if ( !key.empty () && key.size () <= 10 ) {
32+ if ( key == " 0" ) {
33+ return 0 ;
34+ }
35+ else if ( ( key[ 0 ] != ' 0' ) && ( key.find_first_not_of ( " 0123456789" ) == std::string::npos ) ) {
36+ if ( key.size () < 10 || key < " 4294967296" ) {
37+ return static_cast < std::size_t >( std::stoul ( key ) );
38+ }
39+ }
40+ }
41+ return std::string::npos;
42+ }
43+ };
44+
45+ template <>
46+ struct token_to_index < 8 >
47+ {
48+ static std::size_t convert ( const std::string& key ) noexcept
49+ {
50+ if ( !key.empty () && key.size () <= 20 ) {
51+ if ( key == " 0" ) {
52+ return 0 ;
53+ }
54+ else if ( ( key[ 0 ] != ' 0' ) && ( key.find_first_not_of ( " 0123456789" ) == std::string::npos ) ) {
55+ if ( key.size () < 20 || key < " 18446744073709551616" ) {
56+ return static_cast < std::size_t >( std::stoull ( key ) );
57+ }
58+ }
59+ }
60+ return std::string::npos;
61+ }
62+ };
2463
2564 } // namespace internal
2665
@@ -33,13 +72,13 @@ namespace tao
3372
3473 public:
3574 explicit token ( const std::string& in_key )
36- : m_index( internal::token_to_index( in_key ) ),
75+ : m_index( internal::token_to_index<>::convert ( in_key ) ),
3776 m_key( in_key )
3877 {
3978 }
4079
4180 explicit token ( std::string&& in_key ) noexcept
42- : m_index( internal::token_to_index( in_key ) ),
81+ : m_index( internal::token_to_index<>::convert ( in_key ) ),
4382 m_key( std::move( in_key ) )
4483 {
4584 }
@@ -222,21 +261,6 @@ namespace tao
222261
223262 namespace internal
224263 {
225- inline std::size_t token_to_index ( const std::string& key ) noexcept
226- {
227- if ( !key.empty () && key.size () <= 20 ) {
228- if ( key == " 0" ) {
229- return 0 ;
230- }
231- else if ( ( key[ 0 ] != ' 0' ) && ( key.find_first_not_of ( " 0123456789" ) == std::string::npos ) ) {
232- if ( key.size () < 20 || key < " 18446744073709551616" ) {
233- return std::stoull ( key );
234- }
235- }
236- }
237- return std::string::npos;
238- }
239-
240264 inline std::string tokens_to_string ( std::vector< token >::const_iterator it, const std::vector< token >::const_iterator& end )
241265 {
242266 std::string result;
0 commit comments