diff options
| author | mikhnenko <[email protected]> | 2023-10-25 20:25:30 +0300 |
|---|---|---|
| committer | mikhnenko <[email protected]> | 2023-10-25 20:54:14 +0300 |
| commit | 4e197a976205a88dd1de940b253acb2175dc47b8 (patch) | |
| tree | a9cfdcc08abde7dd5206d62d23ecadd22b69238b /contrib/libs/cxxsupp/libcxx/src/string.cpp | |
| parent | a2c311b015e4e9366b8da29d07f77cd4b92c1cb0 (diff) | |
Upd libc++ to 1 Jun 2022 10c4eec2785a68880c287d36c262d5be3a72a128
[libc++][format] Fixes string-literal formatting.
[libc++] Removes __cpp_lib_monadic_optional.
[libcxx] Temporarily skip Arm configs
[libc++] Reduce the verbosity when running the libc++ Lit configuration
[libc++] Adds __format_string as nasty macro.
[libc++] Use __enable_if_t and is_integral in cstddef
[libc++] Adds missing includes.
[libc++] Minor emscripten changes from downstream
[libc++] Granularize more of <type_traits>
[libc++] Remove unused __functional includes
[libc++] Add various missing _LIBCPP_HIDE_FROM_ABI
[libc++] Use __libcpp_clz for a tighter __log2i function
[libc++] Enable ranges_robust_against* and niebloid tests for implemented ranges algorithms
[libc++] Implement ranges::is_sorted{, _until}
[libc++] Time tests during CI
[libc++] Implement ranges::{all, any, none}_of
[libc++] Remove temporary workaround for existing CMake caches
[libc++] Implement ranges::equal
[libc++] Remove conditional include
[libc++] Use Python subprocess instead of libc++'s own utilities
[libc++] Implement ranges::fill{, _n}
[libc++] Make sure that all headers can be included with modules enabled
[libc++] Rename the generic-singlethreaded CI job to generic-no-threads for consistency
[libc++] Implement ranges::reverse
[libc++] Replace modulus operations in std::seed_seq::generate with conditional checks.
[libc++] type_traits: use __is_core_convertible in __invokable_r.
[libc++] Remove duplicate tests for callable concepts
[libc++] Add ranges::max_element to the synopsis and ADL-proof the __min_element_impl calls
[libc++] Add auto to the list of required extensions in C++03
[libc++] Assume that push_macro and pop_macro are available
[libc++] Always enable the ranges concepts
[libc++] Granularize parts of <type_traits>
[libc++] Improve error messages for disabled modes
[libc++] Override the value of LIBCXX_CXX_ABI in the cache
[libc++] Granularize algorithm benchmarks
[libc++] Enable move semantics for vector in C++03
[libc++][format][5/6] Improve format_to_n.
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src/string.cpp')
| -rw-r--r-- | contrib/libs/cxxsupp/libcxx/src/string.cpp | 294 |
1 files changed, 86 insertions, 208 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/string.cpp b/contrib/libs/cxxsupp/libcxx/src/string.cpp index 9d1de0cf6ca..8db129520ee 100644 --- a/contrib/libs/cxxsupp/libcxx/src/string.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/string.cpp @@ -56,42 +56,33 @@ void __basic_string_common<true>::__throw_out_of_range() const { #endif #undef _LIBCPP_EXTERN_TEMPLATE_DEFINE -template string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); +template string operator+<char, char_traits<char>, allocator<char>>(char const*, string const&); namespace { template<typename T> -inline -void throw_helper( const string& msg ) -{ +inline void throw_helper(const string& msg) { #ifndef _LIBCPP_NO_EXCEPTIONS - throw T( msg ); + throw T(msg); #else fprintf(stderr, "%s\n", msg.c_str()); _VSTD::abort(); #endif } -inline -void throw_from_string_out_of_range( const string& func ) -{ +inline void throw_from_string_out_of_range(const string& func) { throw_helper<out_of_range>(func + ": out of range"); } -inline -void throw_from_string_invalid_arg( const string& func ) -{ +inline void throw_from_string_invalid_arg(const string& func) { throw_helper<invalid_argument>(func + ": no conversion"); } // as_integer template<typename V, typename S, typename F> -inline -V -as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) -{ +inline V as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) { typename S::value_type* ptr = nullptr; const typename S::value_type* const p = str.c_str(); typename remove_reference<decltype(errno)>::type errno_save = errno; @@ -108,109 +99,77 @@ as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) } template<typename V, typename S> -inline -V -as_integer(const string& func, const S& s, size_t* idx, int base); +inline V as_integer(const string& func, const S& s, size_t* idx, int base); // string template<> -inline -int -as_integer(const string& func, const string& s, size_t* idx, int base ) -{ +inline int as_integer(const string& func, const string& s, size_t* idx, int base) { // Use long as no Standard string to integer exists. - long r = as_integer_helper<long>( func, s, idx, base, strtol ); + long r = as_integer_helper<long>(func, s, idx, base, strtol); if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) throw_from_string_out_of_range(func); return static_cast<int>(r); } template<> -inline -long -as_integer(const string& func, const string& s, size_t* idx, int base ) -{ - return as_integer_helper<long>( func, s, idx, base, strtol ); +inline long as_integer(const string& func, const string& s, size_t* idx, int base) { + return as_integer_helper<long>(func, s, idx, base, strtol); } template<> -inline -unsigned long -as_integer( const string& func, const string& s, size_t* idx, int base ) -{ - return as_integer_helper<unsigned long>( func, s, idx, base, strtoul ); +inline unsigned long as_integer(const string& func, const string& s, size_t* idx, int base) { + return as_integer_helper<unsigned long>(func, s, idx, base, strtoul); } template<> -inline -long long -as_integer( const string& func, const string& s, size_t* idx, int base ) -{ - return as_integer_helper<long long>( func, s, idx, base, strtoll ); +inline long long as_integer(const string& func, const string& s, size_t* idx, int base) { + return as_integer_helper<long long>(func, s, idx, base, strtoll); } template<> -inline -unsigned long long -as_integer( const string& func, const string& s, size_t* idx, int base ) -{ - return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull ); +inline unsigned long long as_integer(const string& func, const string& s, size_t* idx, int base) { + return as_integer_helper<unsigned long long>(func, s, idx, base, strtoull); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS // wstring template<> -inline -int -as_integer( const string& func, const wstring& s, size_t* idx, int base ) -{ +inline int as_integer(const string& func, const wstring& s, size_t* idx, int base) { // Use long as no Stantard string to integer exists. - long r = as_integer_helper<long>( func, s, idx, base, wcstol ); + long r = as_integer_helper<long>(func, s, idx, base, wcstol); if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) throw_from_string_out_of_range(func); return static_cast<int>(r); } template<> -inline -long -as_integer( const string& func, const wstring& s, size_t* idx, int base ) -{ - return as_integer_helper<long>( func, s, idx, base, wcstol ); +inline long as_integer(const string& func, const wstring& s, size_t* idx, int base) { + return as_integer_helper<long>(func, s, idx, base, wcstol); } template<> inline unsigned long -as_integer( const string& func, const wstring& s, size_t* idx, int base ) +as_integer(const string& func, const wstring& s, size_t* idx, int base) { - return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul ); + return as_integer_helper<unsigned long>(func, s, idx, base, wcstoul); } template<> -inline -long long -as_integer( const string& func, const wstring& s, size_t* idx, int base ) -{ - return as_integer_helper<long long>( func, s, idx, base, wcstoll ); +inline long long as_integer(const string& func, const wstring& s, size_t* idx, int base) { + return as_integer_helper<long long>(func, s, idx, base, wcstoll); } template<> -inline -unsigned long long -as_integer( const string& func, const wstring& s, size_t* idx, int base ) -{ - return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull ); +inline unsigned long long as_integer(const string& func, const wstring& s, size_t* idx, int base) { + return as_integer_helper<unsigned long long>(func, s, idx, base, wcstoull); } #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS // as_float template<typename V, typename S, typename F> -inline -V -as_float_helper(const string& func, const S& str, size_t* idx, F f ) -{ +inline V as_float_helper(const string& func, const S& str, size_t* idx, F f) { typename S::value_type* ptr = nullptr; const typename S::value_type* const p = str.c_str(); typename remove_reference<decltype(errno)>::type errno_save = errno; @@ -227,172 +186,107 @@ as_float_helper(const string& func, const S& str, size_t* idx, F f ) } template<typename V, typename S> -inline -V as_float( const string& func, const S& s, size_t* idx = nullptr ); +inline V as_float(const string& func, const S& s, size_t* idx = nullptr); template<> -inline -float -as_float( const string& func, const string& s, size_t* idx ) -{ - return as_float_helper<float>( func, s, idx, strtof ); +inline float as_float(const string& func, const string& s, size_t* idx) { + return as_float_helper<float>(func, s, idx, strtof); } template<> -inline -double -as_float(const string& func, const string& s, size_t* idx ) -{ - return as_float_helper<double>( func, s, idx, strtod ); +inline double as_float(const string& func, const string& s, size_t* idx) { + return as_float_helper<double>(func, s, idx, strtod); } template<> -inline -long double -as_float( const string& func, const string& s, size_t* idx ) -{ - return as_float_helper<long double>( func, s, idx, strtold ); +inline long double as_float(const string& func, const string& s, size_t* idx) { + return as_float_helper<long double>(func, s, idx, strtold); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template<> -inline -float -as_float( const string& func, const wstring& s, size_t* idx ) -{ - return as_float_helper<float>( func, s, idx, wcstof ); +inline float as_float(const string& func, const wstring& s, size_t* idx) { + return as_float_helper<float>(func, s, idx, wcstof); } template<> -inline -double -as_float( const string& func, const wstring& s, size_t* idx ) -{ - return as_float_helper<double>( func, s, idx, wcstod ); +inline double as_float(const string& func, const wstring& s, size_t* idx) { + return as_float_helper<double>(func, s, idx, wcstod); } template<> -inline -long double -as_float( const string& func, const wstring& s, size_t* idx ) -{ - return as_float_helper<long double>( func, s, idx, wcstold ); +inline long double as_float(const string& func, const wstring& s, size_t* idx) { + return as_float_helper<long double>(func, s, idx, wcstold); } #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS } // unnamed namespace -int -stoi(const string& str, size_t* idx, int base) -{ - return as_integer<int>( "stoi", str, idx, base ); +int stoi(const string& str, size_t* idx, int base) { + return as_integer<int>("stoi", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -int -stoi(const wstring& str, size_t* idx, int base) -{ - return as_integer<int>( "stoi", str, idx, base ); +long stol(const string& str, size_t* idx, int base) { + return as_integer<long>("stol", str, idx, base); } -#endif -long -stol(const string& str, size_t* idx, int base) -{ - return as_integer<long>( "stol", str, idx, base ); +unsigned long stoul(const string& str, size_t* idx, int base) { + return as_integer<unsigned long>("stoul", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -long -stol(const wstring& str, size_t* idx, int base) -{ - return as_integer<long>( "stol", str, idx, base ); +long long stoll(const string& str, size_t* idx, int base) { + return as_integer<long long>("stoll", str, idx, base); } -#endif -unsigned long -stoul(const string& str, size_t* idx, int base) -{ - return as_integer<unsigned long>( "stoul", str, idx, base ); +unsigned long long stoull(const string& str, size_t* idx, int base) { + return as_integer<unsigned long long>("stoull", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -unsigned long -stoul(const wstring& str, size_t* idx, int base) -{ - return as_integer<unsigned long>( "stoul", str, idx, base ); +float stof(const string& str, size_t* idx) { + return as_float<float>("stof", str, idx); } -#endif -long long -stoll(const string& str, size_t* idx, int base) -{ - return as_integer<long long>( "stoll", str, idx, base ); +double stod(const string& str, size_t* idx) { + return as_float<double>("stod", str, idx); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -long long -stoll(const wstring& str, size_t* idx, int base) -{ - return as_integer<long long>( "stoll", str, idx, base ); +long double stold(const string& str, size_t* idx) { + return as_float<long double>("stold", str, idx); } -#endif -unsigned long long -stoull(const string& str, size_t* idx, int base) -{ - return as_integer<unsigned long long>( "stoull", str, idx, base ); +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +int stoi(const wstring& str, size_t* idx, int base) { + return as_integer<int>("stoi", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -unsigned long long -stoull(const wstring& str, size_t* idx, int base) -{ - return as_integer<unsigned long long>( "stoull", str, idx, base ); +long stol(const wstring& str, size_t* idx, int base) { + return as_integer<long>("stol", str, idx, base); } -#endif -float -stof(const string& str, size_t* idx) -{ - return as_float<float>( "stof", str, idx ); +unsigned long stoul(const wstring& str, size_t* idx, int base) { + return as_integer<unsigned long>("stoul", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -float -stof(const wstring& str, size_t* idx) -{ - return as_float<float>( "stof", str, idx ); +long long stoll(const wstring& str, size_t* idx, int base) { + return as_integer<long long>("stoll", str, idx, base); } -#endif -double -stod(const string& str, size_t* idx) -{ - return as_float<double>( "stod", str, idx ); +unsigned long long stoull(const wstring& str, size_t* idx, int base) { + return as_integer<unsigned long long>("stoull", str, idx, base); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -double -stod(const wstring& str, size_t* idx) -{ - return as_float<double>( "stod", str, idx ); +float stof(const wstring& str, size_t* idx) { + return as_float<float>("stof", str, idx); } -#endif -long double -stold(const string& str, size_t* idx) -{ - return as_float<long double>( "stold", str, idx ); +double stod(const wstring& str, size_t* idx) { + return as_float<double>("stod", str, idx); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -long double -stold(const wstring& str, size_t* idx) -{ - return as_float<long double>( "stold", str, idx ); +long double stold(const wstring& str, size_t* idx) { + return as_float<long double>("stold", str, idx); } -#endif +#endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS // to_string @@ -402,21 +296,15 @@ namespace // as_string template<typename S, typename P, typename V > -inline -S -as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) -{ +inline S as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) { typedef typename S::size_type size_type; size_type available = s.size(); - while (true) - { + while (true) { int status = sprintf_like(&s[0], available + 1, fmt, a); - if ( status >= 0 ) - { + if (status >= 0) { size_type used = static_cast<size_type>(status); - if ( used <= available ) - { - s.resize( used ); + if (used <= available) { + s.resize(used); break; } available = used; // Assume this is advice of how much space we need. @@ -432,11 +320,8 @@ template <class S> struct initial_string; template <> -struct initial_string<string> -{ - string - operator()() const - { +struct initial_string<string> { + string operator()() const { string s; s.resize(s.capacity()); return s; @@ -445,11 +330,8 @@ struct initial_string<string> #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <> -struct initial_string<wstring> -{ - wstring - operator()() const - { +struct initial_string<wstring> { + wstring operator()() const { wstring s(20, wchar_t()); s.resize(s.capacity()); return s; @@ -458,10 +340,7 @@ struct initial_string<wstring> typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...); -inline -wide_printf -get_swprintf() -{ +inline wide_printf get_swprintf() { #ifndef _LIBCPP_MSVCRT return swprintf; #else @@ -471,8 +350,7 @@ get_swprintf() #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS template <typename S, typename V> -S i_to_string(V v) -{ +S i_to_string(V v) { // numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. // For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), // so we need +1 here. |
