[libcxx-commits] [libcxx] [libcxx] Provide locale conversions to tests through lit substitution (PR #105651)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 24 14:44:50 PDT 2024
================
@@ -80,6 +49,12 @@ std::wstring negate_en_US(std::wstring s) {
#endif
}
+wchar_t thousands_sep_or_default(std::wstring s) { return !s.empty() ? s[0] : L','; }
----------------
mstorsjo wrote:
That doesn't work quite off the bat, at least.
The problem is that `FR_MON_THOU_SEP` is a wchar_t string like `L"\u00a0"`, while we want a single `wchar_t`. The `mon_thousands_sep_or_default` helper took a `std::wstring` and returns `s[0]` if `s` is nonempty in the current version of the patch.
This is because what `localeconv()` returns is a struct with strings, where each separator string usually is one single char, but they could in theory be multiple. In the current patch we treat this as strings all the way up to the `foo_sep_or_default()` helpers which convert from a string to a single wchar.
If we wanted to go that way, I guess we could make the `localeconv()` helper executable, that is called in python, only return the first char, and treat it as a numeric single wchar throughout instead. I guess that'd work too. It would be a bit tricky for one of the tests, though, where we currently try to do this:
```
assert(stream_fr_FR_locale<CharT>(-1'000'000s) == L"-1" FR_THOU_SEP "000" FR_THOU_SEP "000s");
```
I'm not sure how we'd easily synthesize a wchar string literal out of that, when we'd have e.g. `-DFR_THOU_SEP=0x00a0`.
https://github.com/llvm/llvm-project/pull/105651
More information about the libcxx-commits
mailing list