[libcxx-commits] [libcxx] ed86610 - [libc++][nfc] Move functions to a generic place.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 19 07:41:12 PST 2021
Author: Mark de Wever
Date: 2021-11-19T16:38:35+01:00
New Revision: ed86610c7bcd5346d05db6a62fce6fb16eb83659
URL: https://github.com/llvm/llvm-project/commit/ed86610c7bcd5346d05db6a62fce6fb16eb83659
DIFF: https://github.com/llvm/llvm-project/commit/ed86610c7bcd5346d05db6a62fce6fb16eb83659.diff
LOG: [libc++][nfc] Move functions to a generic place.
This allows the floating-point formatter to use the same functions as
the integral formatter. This was tested in D114001.
Added:
Modified:
libcxx/include/__format/formatter.h
libcxx/include/__format/formatter_integral.h
Removed:
################################################################################
diff --git a/libcxx/include/__format/formatter.h b/libcxx/include/__format/formatter.h
index 38fd88e855fd..1adce75a8611 100644
--- a/libcxx/include/__format/formatter.h
+++ b/libcxx/include/__format/formatter.h
@@ -60,6 +60,49 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter {
}
};
+namespace __format_spec {
+
+_LIBCPP_HIDE_FROM_ABI inline char* __insert_sign(char* __buf, bool __negative,
+ _Flags::_Sign __sign) {
+ if (__negative)
+ *__buf++ = '-';
+ else
+ switch (__sign) {
+ case _Flags::_Sign::__default:
+ case _Flags::_Sign::__minus:
+ // No sign added.
+ break;
+ case _Flags::_Sign::__plus:
+ *__buf++ = '+';
+ break;
+ case _Flags::_Sign::__space:
+ *__buf++ = ' ';
+ break;
+ }
+
+ return __buf;
+}
+
+_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char c) {
+ switch (c) {
+ case 'a':
+ return 'A';
+ case 'b':
+ return 'B';
+ case 'c':
+ return 'C';
+ case 'd':
+ return 'D';
+ case 'e':
+ return 'E';
+ case 'f':
+ return 'F';
+ }
+ return c;
+}
+
+} // namespace __format_spec
+
namespace __formatter {
/** The character types that formatters are specialized for. */
diff --git a/libcxx/include/__format/formatter_integral.h b/libcxx/include/__format/formatter_integral.h
index 6a232f21fa8e..5f1353effd77 100644
--- a/libcxx/include/__format/formatter_integral.h
+++ b/libcxx/include/__format/formatter_integral.h
@@ -133,45 +133,6 @@ _LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
+ 1; // Reserve space for the sign.
}
-_LIBCPP_HIDE_FROM_ABI inline char* __insert_sign(char* __buf, bool __negative,
- _Flags::_Sign __sign) {
- if (__negative)
- *__buf++ = '-';
- else
- switch (__sign) {
- case _Flags::_Sign::__default:
- case _Flags::_Sign::__minus:
- // No sign added.
- break;
- case _Flags::_Sign::__plus:
- *__buf++ = '+';
- break;
- case _Flags::_Sign::__space:
- *__buf++ = ' ';
- break;
- }
-
- return __buf;
-}
-
-_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char c) {
- switch (c) {
- case 'a':
- return 'A';
- case 'b':
- return 'B';
- case 'c':
- return 'C';
- case 'd':
- return 'D';
- case 'e':
- return 'E';
- case 'f':
- return 'F';
- }
- return c;
-}
-
/**
* Determines the required grouping based on the size of the input.
*
More information about the libcxx-commits
mailing list