about summary refs log tree commit diff
path: root/absl/strings
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-02-25T16·48-0800
committerCJ Johnson <johnsoncj@google.com>2020-02-25T18·12-0500
commit0d5ce2797eb695aee7e019e25323251ef6ffc277 (patch)
treee8f17f3202cce51bcb9f25175349b7a61e7ba664 /absl/strings
parentb69c7d880caddfc25bf348dbcfe9d45fdd8bc6e6 (diff)
Export of internal Abseil changes
--
20405fc394419d434d3ea09b2e62e4edcb282421 by Christian Blichmann <cblichmann@google.com>:

Include `status` subdirectory in main `CMakeLists.txt`

PiperOrigin-RevId: 297125966

--
101087af9689612bdda679ee0869e5cde4472244 by Matt Kulukundis <kfm@google.com>:

Fix typo

PiperOrigin-RevId: 296991360

--
55ff5bc6970d46214c0459d3a7a23973c7dc69b9 by Andy Getzendanner <durandal@google.com>:

Extract logging's ErrnoSaver to absl::base_internal and use it in a couple other places.

PiperOrigin-RevId: 296969168

--
b7cd7550297d53766576f751436617200c65831b by Abseil Team <absl-team@google.com>:

Internal change

PiperOrigin-RevId: 296951474

--
8c04c73fc53f9a09c3e2400812b931157f35fe07 by Andy Soffer <asoffer@google.com>:

Auto-generate list of files in the DLL, and add new build targets to the DLL.

PiperOrigin-RevId: 296932061

--
2f77829e196094f1addefd8ac2ac9e398c5b6100 by Andy Soffer <asoffer@google.com>:

Fix bug introduced by DLL where we couldn't build shared libraries on
non-windows platforms.

Fixes #623

PiperOrigin-RevId: 296919347

--
b768163dbbff0c561b9dff0218a699e5e4fd33f3 by Abseil Team <absl-team@google.com>:

typo: microprosessor

PiperOrigin-RevId: 296904933

--
b185da0dac44c91855373f0723df9242cbfb3db3 by Matthew Brown <matthewbr@google.com>:

Internal cleanup

PiperOrigin-RevId: 296509711
GitOrigin-RevId: 20405fc394419d434d3ea09b2e62e4edcb282421
Change-Id: I55c8eba6f353ceb337455ae144ab743ea21edbef
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/internal/str_format/checker_test.cc2
-rw-r--r--absl/strings/internal/str_format/extension.h119
2 files changed, 72 insertions, 49 deletions
diff --git a/absl/strings/internal/str_format/checker_test.cc b/absl/strings/internal/str_format/checker_test.cc
index c309e20310a1..ea2a7681a62a 100644
--- a/absl/strings/internal/str_format/checker_test.cc
+++ b/absl/strings/internal/str_format/checker_test.cc
@@ -13,7 +13,7 @@ std::string ConvToString(Conv conv) {
   std::string out;
 #define CONV_SET_CASE(c) \
   if (Contains(conv, Conv::c)) out += #c;
-  ABSL_CONVERSION_CHARS_EXPAND_(CONV_SET_CASE, )
+  ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(CONV_SET_CASE, )
 #undef CONV_SET_CASE
   if (Contains(conv, Conv::star)) out += "*";
   return out;
diff --git a/absl/strings/internal/str_format/extension.h b/absl/strings/internal/str_format/extension.h
index 16f6c0a4b205..d1665753d182 100644
--- a/absl/strings/internal/str_format/extension.h
+++ b/absl/strings/internal/str_format/extension.h
@@ -137,7 +137,7 @@ struct Flags {
 };
 
 // clang-format off
-#define ABSL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP) \
+#define ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP) \
   /* text */ \
   X_VAL(c) X_SEP X_VAL(C) X_SEP X_VAL(s) X_SEP X_VAL(S) X_SEP \
   /* ints */ \
@@ -161,11 +161,11 @@ enum class FormatConversionChar : uint8_t {
 
 inline FormatConversionChar FormatConversionCharFromChar(char c) {
   switch (c) {
-#define X_VAL(id) \
-  case #id[0]:    \
+#define ABSL_INTERNAL_X_VAL(id) \
+  case #id[0]:                  \
     return FormatConversionChar::id;
-    ABSL_CONVERSION_CHARS_EXPAND_(X_VAL, )
-#undef X_VAL
+    ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_X_VAL, )
+#undef ABSL_INTERNAL_X_VAL
   }
   return FormatConversionChar::kNone;
 }
@@ -240,15 +240,16 @@ inline bool FormatConversionCharIsFloat(FormatConversionChar c) {
 
 inline char FormatConversionCharToChar(FormatConversionChar c) {
   switch (c) {
-#define X_VAL(e)                \
+#define ABSL_INTERNAL_X_VAL(e)  \
   case FormatConversionChar::e: \
     return #e[0];
-#define X_SEP
-    ABSL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP)
+#define ABSL_INTERNAL_X_SEP
+    ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_X_VAL,
+                                           ABSL_INTERNAL_X_SEP)
     case FormatConversionChar::kNone:
       return '\0';
-#undef X_VAL
-#undef X_SEP
+#undef ABSL_INTERNAL_X_VAL
+#undef ABSL_INTERNAL_X_SEP
   }
   return '\0';
 }
@@ -262,11 +263,8 @@ inline std::ostream& operator<<(std::ostream& os, FormatConversionChar v) {
 
 struct FormatConversionSpecImplFriend;
 
-class ConversionSpec {
+class FormatConversionSpec {
  public:
-  // Deprecated (use has_x_flag() instead).
-  Flags flags() const { return flags_; }
-
   // Width and precison are not specified, no flags are set.
   bool is_basic() const { return flags_.basic; }
   bool has_left_flag() const { return flags_.left; }
@@ -275,10 +273,10 @@ class ConversionSpec {
   bool has_alt_flag() const { return flags_.alt; }
   bool has_zero_flag() const { return flags_.zero; }
 
-  FormatConversionChar conv() const {
+  FormatConversionChar conversion_char() const {
     // Keep this field first in the struct . It generates better code when
     // accessing it when ConversionSpec is passed by value in registers.
-    static_assert(offsetof(ConversionSpec, conv_) == 0, "");
+    static_assert(offsetof(FormatConversionSpec, conv_) == 0, "");
     return conv_;
   }
 
@@ -289,6 +287,11 @@ class ConversionSpec {
   // negative value.
   int precision() const { return precision_; }
 
+  // Deprecated (use has_x_flag() instead).
+  Flags flags() const { return flags_; }
+  // Deprecated
+  FormatConversionChar conv() const { return conversion_char(); }
+
  private:
   friend struct str_format_internal::FormatConversionSpecImplFriend;
   FormatConversionChar conv_ = FormatConversionChar::kNone;
@@ -298,46 +301,57 @@ class ConversionSpec {
 };
 
 struct FormatConversionSpecImplFriend final {
-  static void SetFlags(Flags f, ConversionSpec* conv) { conv->flags_ = f; }
-  static void SetConversionChar(FormatConversionChar c, ConversionSpec* conv) {
+  static void SetFlags(Flags f, FormatConversionSpec* conv) {
+    conv->flags_ = f;
+  }
+  static void SetConversionChar(FormatConversionChar c,
+                                FormatConversionSpec* conv) {
     conv->conv_ = c;
   }
-  static void SetWidth(int w, ConversionSpec* conv) { conv->width_ = w; }
-  static void SetPrecision(int p, ConversionSpec* conv) {
+  static void SetWidth(int w, FormatConversionSpec* conv) { conv->width_ = w; }
+  static void SetPrecision(int p, FormatConversionSpec* conv) {
     conv->precision_ = p;
   }
-  static std::string FlagsToString(const ConversionSpec& spec) {
+  static std::string FlagsToString(const FormatConversionSpec& spec) {
     return spec.flags_.ToString();
   }
 };
 
 constexpr uint64_t FormatConversionCharToConvValue(char conv) {
   return
-#define CONV_SET_CASE(c)                                                     \
+#define ABSL_INTERNAL_CHAR_SET_CASE(c)                                       \
   conv == #c[0]                                                              \
       ? (uint64_t{1} << (1 + static_cast<uint8_t>(FormatConversionChar::c))) \
       :
-      ABSL_CONVERSION_CHARS_EXPAND_(CONV_SET_CASE, )
-#undef CONV_SET_CASE
+      ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_CHAR_SET_CASE, )
+#undef ABSL_INTERNAL_CHAR_SET_CASE
                   conv == '*'
           ? 1
           : 0;
 }
 
-enum class Conv : uint64_t {
-#define CONV_SET_CASE(c) c = FormatConversionCharToConvValue(#c[0]),
-  ABSL_CONVERSION_CHARS_EXPAND_(CONV_SET_CASE, )
-#undef CONV_SET_CASE
+enum class FormatConversionCharSet : uint64_t {
+#define ABSL_INTERNAL_CHAR_SET_CASE(c) \
+  c = FormatConversionCharToConvValue(#c[0]),
+  ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_CHAR_SET_CASE, )
+#undef ABSL_INTERNAL_CHAR_SET_CASE
 
   // Used for width/precision '*' specification.
-  star = FormatConversionCharToConvValue('*'),
-
+  kStar = FormatConversionCharToConvValue('*'),
   // Some predefined values:
-  integral = d | i | u | o | x | X,
-  floating = a | e | f | g | A | E | F | G,
-  numeric = integral | floating,
-  string = s,
-  pointer = p
+  kIntegral = d | i | u | o | x | X,
+  kFloating = a | e | f | g | A | E | F | G,
+  kNumeric = kIntegral | kFloating,
+  kString = s,
+  kPointer = p,
+
+  // The following are deprecated
+  star = kStar,
+  integral = kIntegral,
+  floating = kFloating,
+  numeric = kNumeric,
+  string = kString,
+  pointer = kPointer
 };
 
 // Type safe OR operator.
@@ -345,36 +359,41 @@ enum class Conv : uint64_t {
 //  1. operator| on enums makes them decay to integers and the result is an
 //     integer. We need the result to stay as an enum.
 //  2. We use "enum class" which would not work even if we accepted the decay.
-constexpr Conv operator|(Conv a, Conv b) {
-  return Conv(static_cast<uint64_t>(a) | static_cast<uint64_t>(b));
+constexpr FormatConversionCharSet operator|(FormatConversionCharSet a,
+                                            FormatConversionCharSet b) {
+  return FormatConversionCharSet(static_cast<uint64_t>(a) |
+                                 static_cast<uint64_t>(b));
 }
 
 // Get a conversion with a single character in it.
-constexpr Conv ConversionCharToConv(char c) {
-  return Conv(FormatConversionCharToConvValue(c));
+constexpr FormatConversionCharSet ConversionCharToConv(char c) {
+  return FormatConversionCharSet(FormatConversionCharToConvValue(c));
 }
 
 // Checks whether `c` exists in `set`.
-constexpr bool Contains(Conv set, char c) {
+constexpr bool Contains(FormatConversionCharSet set, char c) {
   return (static_cast<uint64_t>(set) & FormatConversionCharToConvValue(c)) != 0;
 }
 
 // Checks whether all the characters in `c` are contained in `set`
-constexpr bool Contains(Conv set, Conv c) {
+constexpr bool Contains(FormatConversionCharSet set,
+                        FormatConversionCharSet c) {
   return (static_cast<uint64_t>(set) & static_cast<uint64_t>(c)) ==
          static_cast<uint64_t>(c);
 }
 
 // Return type of the AbslFormatConvert() functions.
-// The Conv template parameter is used to inform the framework of what
-// conversion characters are supported by that AbslFormatConvert routine.
-template <Conv C>
-struct ConvertResult {
-  static constexpr Conv kConv = C;
+// The FormatConversionCharSet template parameter is used to inform the
+// framework of what conversion characters are supported by that
+// AbslFormatConvert routine.
+template <FormatConversionCharSet C>
+struct FormatConvertResult {
+  static constexpr FormatConversionCharSet kConv = C;
   bool value;
 };
-template <Conv C>
-constexpr Conv ConvertResult<C>::kConv;
+
+template <FormatConversionCharSet C>
+constexpr FormatConversionCharSet FormatConvertResult<C>::kConv;
 
 // Return capacity - used, clipped to a minimum of 0.
 inline size_t Excess(size_t used, size_t capacity) {
@@ -383,6 +402,10 @@ inline size_t Excess(size_t used, size_t capacity) {
 
 // Type alias for use during migration.
 using ConversionChar = FormatConversionChar;
+using ConversionSpec = FormatConversionSpec;
+using Conv = FormatConversionCharSet;
+template <FormatConversionCharSet C>
+using ConvertResult = FormatConvertResult<C>;
 
 }  // namespace str_format_internal