File indexing completed on 2025-01-18 09:52:46
0001 #ifndef BOOST_THREAD_DETAIL_STRING_TO_UNSIGNED_HPP_INCLUDED
0002 #define BOOST_THREAD_DETAIL_STRING_TO_UNSIGNED_HPP_INCLUDED
0003
0004
0005
0006
0007
0008 #include <string>
0009 #include <climits>
0010
0011 namespace boost
0012 {
0013 namespace thread_detail
0014 {
0015
0016 inline bool string_to_unsigned( std::string const& s, unsigned& v )
0017 {
0018 v = 0;
0019
0020 if( s.empty() )
0021 {
0022 return false;
0023 }
0024
0025 for( char const* p = s.c_str(); *p; ++p )
0026 {
0027 unsigned char ch = static_cast<unsigned char>( *p );
0028
0029 if( ch < '0' || ch > '9' )
0030 {
0031 return false;
0032 }
0033
0034 if( v > UINT_MAX / 10 )
0035 {
0036 return false;
0037 }
0038
0039 unsigned q = static_cast<unsigned>( ch - '0' );
0040
0041 if( v == UINT_MAX / 10 && q > UINT_MAX % 10 )
0042 {
0043 return false;
0044 }
0045
0046 v = v * 10 + q;
0047 }
0048
0049 return true;
0050 }
0051
0052 }
0053 }
0054
0055 #endif