[libcxx-commits] [libcxx] 6325184 - [libc++][NFC] Whitespace refactoring of string.cpp for consistency and legibility

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 24 08:32:13 PDT 2022


Author: Louis Dionne
Date: 2022-05-24T11:32:00-04:00
New Revision: 63251840494216af0d063503faee21f58a915c3c

URL: https://github.com/llvm/llvm-project/commit/63251840494216af0d063503faee21f58a915c3c
DIFF: https://github.com/llvm/llvm-project/commit/63251840494216af0d063503faee21f58a915c3c.diff

LOG: [libc++][NFC] Whitespace refactoring of string.cpp for consistency and legibility

Added: 
    

Modified: 
    libcxx/src/string.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp
index d847ad506845..8db129520ee5 100644
--- a/libcxx/src/string.cpp
+++ b/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,156 +186,105 @@ 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);
 }
 
-long
-stol(const string& str, size_t* idx, int base)
-{
-    return as_integer<long>( "stol", str, idx, base );
+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 );
+unsigned long stoul(const string& str, size_t* idx, int base) {
+    return as_integer<unsigned long>("stoul", str, idx, base);
 }
 
-long long
-stoll(const string& str, size_t* idx, int base)
-{
-    return as_integer<long long>( "stoll", str, idx, base );
+long long stoll(const string& str, size_t* idx, int base) {
+    return as_integer<long long>("stoll", 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 );
+unsigned long long stoull(const string& str, size_t* idx, int base) {
+    return as_integer<unsigned long long>("stoull", str, idx, base);
 }
 
-float
-stof(const string& str, size_t* idx)
-{
-    return as_float<float>( "stof", str, idx );
+float stof(const string& str, size_t* idx) {
+    return as_float<float>("stof", str, idx);
 }
 
-double
-stod(const string& str, size_t* idx)
-{
-    return as_float<double>( "stod", str, idx );
+double stod(const string& str, size_t* idx) {
+    return as_float<double>("stod", str, idx);
 }
 
-long double
-stold(const string& str, size_t* idx)
-{
-    return as_float<long double>( "stold", str, idx );
+long double stold(const string& str, size_t* idx) {
+    return as_float<long double>("stold", str, idx);
 }
 
 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-int
-stoi(const wstring& str, size_t* idx, int base)
-{
-    return as_integer<int>( "stoi", str, idx, base );
+int stoi(const wstring& str, size_t* idx, int base) {
+    return as_integer<int>("stoi", str, idx, base);
 }
 
-long
-stol(const wstring& str, size_t* idx, int base)
-{
-    return as_integer<long>( "stol", str, idx, base );
+long stol(const wstring& str, size_t* idx, int base) {
+    return as_integer<long>("stol", str, idx, base);
 }
 
-unsigned long
-stoul(const wstring& str, size_t* idx, int base)
-{
-    return as_integer<unsigned long>( "stoul", str, idx, base );
+unsigned long stoul(const wstring& str, size_t* idx, int base) {
+    return as_integer<unsigned long>("stoul", str, idx, base);
 }
 
-long long
-stoll(const wstring& str, size_t* idx, int base)
-{
-    return as_integer<long long>( "stoll", str, idx, base );
+long long stoll(const wstring& str, size_t* idx, int base) {
+    return as_integer<long long>("stoll", str, idx, base);
 }
 
-unsigned long long
-stoull(const wstring& str, size_t* idx, int base)
-{
-    return as_integer<unsigned long long>( "stoull", str, idx, base );
+unsigned long long stoull(const wstring& str, size_t* idx, int base) {
+    return as_integer<unsigned long long>("stoull", str, idx, base);
 }
 
-float
-stof(const wstring& str, size_t* idx)
-{
-    return as_float<float>( "stof", str, idx );
+float stof(const wstring& str, size_t* idx) {
+    return as_float<float>("stof", str, idx);
 }
 
-double
-stod(const wstring& str, size_t* idx)
-{
-    return as_float<double>( "stod", str, idx );
+double stod(const wstring& str, size_t* idx) {
+    return as_float<double>("stod", str, idx);
 }
 
-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 // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
 
@@ -388,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.
@@ -418,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;
@@ -431,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;
@@ -444,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
@@ -457,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.


        


More information about the libcxx-commits mailing list