2 #include "utf8_strings.h"
5 static std::vector
<char> latin_lower
= { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
6 static std::vector
<char> latin_upper
= { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
7 static std::vector
<std::wstring
> greek_lower
= { L
"α", L
"β", L
"γ", L
"δ", L
"ε", L
"ζ", L
"η", L
"θ", L
"ι", L
"κ", L
"λ", L
"μ", L
"ν", L
"ξ", L
"ο", L
"π", L
"ρ", L
"σ", L
"τ", L
"υ", L
"φ", L
"χ", L
"ψ", L
"ω" };
9 static litehtml::string
to_mapped_alpha(int num
, const std::vector
<char>& map
)
17 modulo
= (dividend
- 1) % map
.size();
18 out
= map
[modulo
] + out
;
19 dividend
= (int)((dividend
- modulo
) / map
.size());
25 static litehtml::string
to_mapped_alpha(int num
, const std::vector
<std::wstring
>& map
)
33 modulo
= (dividend
- 1) % map
.size();
34 out
= litehtml_from_wchar(map
[modulo
]).c_str() + out
;
35 dividend
= (int)((dividend
- modulo
) / map
.size());
41 litehtml::string
litehtml::num_cvt::to_latin_lower(int val
)
43 return to_mapped_alpha(val
, latin_lower
);
46 litehtml::string
litehtml::num_cvt::to_latin_upper(int val
)
48 return to_mapped_alpha(val
, latin_upper
);
51 litehtml::string
litehtml::num_cvt::to_greek_lower(int val
)
53 return to_mapped_alpha(val
, greek_lower
);
56 litehtml::string
litehtml::num_cvt::to_roman_lower(int value
)
58 struct romandata_t
{ int value
; const char* numeral
; };
59 const struct romandata_t romandata
[] =
61 { 1000, "m" }, { 900, "cm" },
62 { 500, "d" }, { 400, "cd" },
63 { 100, "c" }, { 90, "xc" },
64 { 50, "l" }, { 40, "xl" },
65 { 10, "x" }, { 9, "ix" },
66 { 5, "v" }, { 4, "iv" },
68 { 0, nullptr } // end marker
71 litehtml::string result
;
72 for (const romandata_t
* current
= romandata
; current
->value
> 0; ++current
)
74 while (value
>= current
->value
)
76 result
+= current
->numeral
;
77 value
-= current
->value
;
83 litehtml::string
litehtml::num_cvt::to_roman_upper(int value
)
85 struct romandata_t
{ int value
; const char* numeral
; };
86 const struct romandata_t romandata
[] =
88 { 1000, "M" }, { 900, "CM" },
89 { 500, "D" }, { 400, "CD" },
90 { 100, "C" }, { 90, "XC" },
91 { 50, "L" }, { 40, "XL" },
92 { 10, "X" }, { 9, "IX" },
93 { 5, "V" }, { 4, "IV" },
95 { 0, nullptr } // end marker
98 litehtml::string result
;
99 for (const romandata_t
* current
= romandata
; current
->value
> 0; ++current
)
101 while (value
>= current
->value
)
103 result
+= current
->numeral
;
104 value
-= current
->value
;