added ASCII character validation; added ASCII-only superscripts, scientific notation, dot product
This commit is contained in:
1 parent
c610b04904
commit
e0263c554d
5 files changed
+67
-19
No files matched your search
@@ -45,7 +45,7 @@ constexpr auto operator_text()
|
||||
return basic_fixed_string("/");
|
||||
}
|
||||
else {
|
||||
return basic_fixed_string("⋅");
|
||||
return basic_symbol_text("⋅", ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-9
@@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <units/bits/external/fixed_string.h>
|
||||
#include <units/symbol_text.h>
|
||||
|
||||
namespace units::detail {
|
||||
|
||||
@@ -41,26 +42,34 @@ template<> inline constexpr basic_fixed_string superscript_number<7> = "\u2077";
|
||||
template<> inline constexpr basic_fixed_string superscript_number<8> = "\u2078";
|
||||
template<> inline constexpr basic_fixed_string superscript_number<9> = "\u2079";
|
||||
|
||||
inline constexpr basic_fixed_string superscript_minus = "\u207b";
|
||||
inline constexpr basic_symbol_text superscript_minus("\u207b", "-");
|
||||
|
||||
inline constexpr basic_symbol_text superscript_prefix("", "^");
|
||||
|
||||
template<std::intmax_t Value>
|
||||
constexpr auto superscript_helper()
|
||||
{
|
||||
if constexpr(Value < 0)
|
||||
return superscript_minus + superscript_helper<-Value>();
|
||||
else if constexpr(Value < 10)
|
||||
return basic_symbol_text(superscript_number<Value>, basic_fixed_string(static_cast<char>('0' + Value)));
|
||||
else
|
||||
return superscript_helper<Value / 10>() + superscript_helper<Value % 10>();
|
||||
}
|
||||
|
||||
template<std::intmax_t Value>
|
||||
constexpr auto superscript()
|
||||
{
|
||||
if constexpr(Value < 0)
|
||||
return superscript_minus + superscript<-Value>();
|
||||
else if constexpr(Value < 10)
|
||||
return superscript_number<Value>;
|
||||
else
|
||||
return superscript<Value / 10>() + superscript<Value % 10>();
|
||||
return superscript_prefix + superscript_helper<Value>();
|
||||
}
|
||||
|
||||
template<std::intmax_t Value>
|
||||
constexpr auto regular()
|
||||
{
|
||||
if constexpr (Value < 0)
|
||||
return basic_fixed_string("-") + superscript<-Value>();
|
||||
return basic_fixed_string("-") + superscript_helper<-Value>();
|
||||
else if constexpr (Value < 10)
|
||||
return basic_fixed_string(static_cast<char>('0' + Value));
|
||||
return basic_symbol_text(static_cast<char>('0' + Value));
|
||||
else
|
||||
return regular<Value / 10>() + regular<Value % 10>();
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
|
||||
namespace units::detail {
|
||||
|
||||
inline constexpr basic_symbol_text base_multiplier("\u00D7 10", "x 10");
|
||||
|
||||
template<typename Ratio>
|
||||
constexpr auto ratio_text()
|
||||
{
|
||||
if constexpr(Ratio::num == 1 && Ratio::den == 1 && Ratio::exp != 0) {
|
||||
return basic_fixed_string("\u00D7 10") + superscript<Ratio::exp>() + basic_fixed_string(" ");
|
||||
return base_multiplier + superscript<Ratio::exp>() + basic_fixed_string(" ");
|
||||
}
|
||||
else if constexpr(Ratio::num != 1 || Ratio::den != 1 || Ratio::exp != 0) {
|
||||
auto txt = basic_fixed_string("[") + regular<Ratio::num>();
|
||||
@@ -43,7 +45,7 @@ constexpr auto ratio_text()
|
||||
return txt + basic_fixed_string("] ");
|
||||
}
|
||||
else {
|
||||
return txt + basic_fixed_string(" \u00D7 10") + superscript<Ratio::exp>() +
|
||||
return txt + " " + base_multiplier + superscript<Ratio::exp>() +
|
||||
basic_fixed_string("] ");
|
||||
}
|
||||
}
|
||||
@@ -54,7 +56,7 @@ constexpr auto ratio_text()
|
||||
}
|
||||
else {
|
||||
return txt + basic_fixed_string("/") + regular<Ratio::den>() +
|
||||
basic_fixed_string(" \u00D7 10") + superscript<Ratio::exp>() +
|
||||
" " + base_multiplier + superscript<Ratio::exp>() +
|
||||
basic_fixed_string("] ");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user