From 4651c61be4317ae7b5c9b19c2468a2807c34b58e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 28 Oct 2024 16:03:09 +0100 Subject: [PATCH] refactor: Unicode symbols description reworked based on the latest SG16 recommendations --- .../framework_basics/systems_of_units.md | 2 +- src/core/include/mp-units/bits/text_tools.h | 22 +++++++++---------- .../include/mp-units/framework/magnitude.h | 11 +++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/users_guide/framework_basics/systems_of_units.md b/docs/users_guide/framework_basics/systems_of_units.md index de2b562d..8d60560a 100644 --- a/docs/users_guide/framework_basics/systems_of_units.md +++ b/docs/users_guide/framework_basics/systems_of_units.md @@ -196,7 +196,7 @@ For some units, a magnitude might also be irrational. The best example here is a is defined using a floating-point magnitude having a factor of the number π (Pi): ```cpp -inline constexpr struct pi final : mag_constant> {} pi; +inline constexpr struct pi final : mag_constant> { inline constexpr auto π = pi; ``` diff --git a/src/core/include/mp-units/bits/text_tools.h b/src/core/include/mp-units/bits/text_tools.h index 45203d27..dcc42b96 100644 --- a/src/core/include/mp-units/bits/text_tools.h +++ b/src/core/include/mp-units/bits/text_tools.h @@ -43,27 +43,27 @@ template constexpr basic_fixed_string superscript_number = u8""; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<0> = u8"\u2070"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<0> = u8"⁰" /* U+2070 SUPERSCRIPT ZERO */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<1> = u8"\u00b9"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<1> = u8"¹" /* U+00B9 SUPERSCRIPT ONE */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<2> = u8"\u00b2"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<2> = u8"²" /* U+00B2 SUPERSCRIPT TWO */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<3> = u8"\u00b3"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<3> = u8"³" /* U+00B3 SUPERSCRIPT THREE */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<4> = u8"\u2074"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<4> = u8"⁴" /* U+2074 SUPERSCRIPT FOUR */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<5> = u8"\u2075"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<5> = u8"⁵" /* U+2075 SUPERSCRIPT FIVE */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<6> = u8"\u2076"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<6> = u8"⁶" /* U+2076 SUPERSCRIPT SIX */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<7> = u8"\u2077"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<7> = u8"⁷" /* U+2077 SUPERSCRIPT SEVEN */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<8> = u8"\u2078"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<8> = u8"⁸" /* U+2078 SUPERSCRIPT EIGHT */; template<> -MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<9> = u8"\u2079"; +MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<9> = u8"⁹" /* U+2079 SUPERSCRIPT NINE */; -inline constexpr symbol_text superscript_minus(u8"\u207b", "-"); +inline constexpr symbol_text superscript_minus(u8"⁻" /* U+207B SUPERSCRIPT MINUS */, "-"); inline constexpr symbol_text superscript_prefix(u8"", "^"); diff --git a/src/core/include/mp-units/framework/magnitude.h b/src/core/include/mp-units/framework/magnitude.h index ff2981d8..36592d59 100644 --- a/src/core/include/mp-units/framework/magnitude.h +++ b/src/core/include/mp-units/framework/magnitude.h @@ -326,7 +326,7 @@ constexpr Out print_separator(Out out, const unit_symbol_formatting& fmt) if (fmt.encoding != text_encoding::utf8) MP_UNITS_THROW( std::invalid_argument("'unit_symbol_separator::half_high_dot' can be only used with 'text_encoding::utf8'")); - const std::string_view dot = "\u22C5"; + const std::string_view dot = "⋅" /* U+22C5 DOT OPERATOR */; out = detail::copy(dot.begin(), dot.end(), out); } else { *out++ = ' '; @@ -406,7 +406,7 @@ constexpr Out magnitude_symbol_impl(Out out, const unit_symbol_formatting& fmt) if constexpr (Exp10 != 0) { if (numerator || denominator) { - constexpr auto mag_multiplier = symbol_text(u8" \u00D7 ", " x "); + constexpr auto mag_multiplier = symbol_text(u8" × " /* U+00D7 MULTIPLICATION SIGN */, " x "); out = copy_symbol(mag_multiplier, fmt.encoding, negative_power, out); } constexpr auto exp = symbol_text("10") + detail::superscript(); @@ -703,13 +703,14 @@ constexpr Magnitude auto mag_power = _pow(mag); * @brief A convenient Magnitude constant for pi, which we can manipulate like a regular number. */ #if defined MP_UNITS_COMP_CLANG || MP_UNITS_COMP_CLANG < 18 -inline constexpr struct pi final : mag_constant { +inline constexpr struct pi final : mag_constant { static constexpr auto _value_ = std::numbers::pi_v; #else -inline constexpr struct pi final : mag_constant> { +inline constexpr struct pi final : + mag_constant> { #endif } pi; -inline constexpr auto π = pi; +inline constexpr auto π /* U+03C0 GREEK SMALL LETTER PI */ = pi; [[deprecated("Use `mag` instead")]] inline constexpr Magnitude auto mag_pi = mag;