2
0
mirror of https://github.com/boostorg/locale.git synced 2026-01-19 04:22:08 +00:00

839 Commits

Author SHA1 Message Date
Alexander Grund
2fe203055f Factor out (conditional) has_win_locale in tests
Only call into library code when the function is available.
That check was missed in one test so put the same code into a single place.

Fixes #181
2023-06-18 09:45:25 +02:00
Alexander Grund
d38793d071 Suppress unreachable code warning when disabling std or WinAPI backend
Fixes #180
2023-06-18 09:45:25 +02:00
Alexander Grund
50ebf53157 CI: Add job testing only ICU or only WinAPI backend on Windows
Test compile/link may fail when the WinAPI or std backend is disabled.

See #180 & #181
2023-06-18 09:41:50 +02:00
Alexander Grund
e910a195e3 Merge pull request #173 from Flamefire/fix-utf8_support-var
Reconcile `utf8_support` handling in std backend
2023-06-15 10:21:39 +02:00
Alexander Grund
ac05f1d945 Merge branch 'develop' into fix-utf8_support-var 2023-06-14 09:34:00 +02:00
Alexander Grund
aa58a42637 Add coverage collection for VS 2017 on appveyor
The `std::collate` bug is only triggered on the VS 2017 image on
appveyor hence it is the only one where `collation_works` returns false
and the `utf8_collator_from_wide` is used.
So to collect coverage for that this is the configuration to do it.
2023-06-14 09:33:29 +02:00
Alexander Grund
57f87d9ace Update changelog 2023-06-14 09:30:39 +02:00
Alexander Grund
c823f3a893 Merge pull request #179 from Flamefire/test
Improve tests and deprecate `localization_backend_manager::get`
2023-06-14 09:30:32 +02:00
Alexander Grund
1f42c4a6c9 Merge pull request #178 from Flamefire/gha-windows-status
GHA-CI: Show library config on Windows CI
2023-06-13 20:25:12 +02:00
Alexander Grund
30987bbd02 Fix test failure with WinAPI backend which ignores use_ansi_encoding
Also test generator stuff for all backends and small refactoring of the
win_backend code
2023-06-13 18:08:19 +02:00
Alexander Grund
6dd2abc5b1 Add test for use_ansi_encoding 2023-06-13 11:33:22 +02:00
Alexander Grund
d64f588875 Replace localization_backend_manager::get by ...::create
Carry the intention better reducing the old 3 methods to 1.

Also remove unimplemented but defined functions from `generator`.
2023-06-13 11:14:40 +02:00
Alexander Grund
6bf68d83ce Add test for the char-type argument of backend::install
Make sure it is used when it should and ignored when it shouldn't.
2023-06-13 11:05:24 +02:00
Alexander Grund
9b07560af3 Fix uncovered line 2023-06-13 09:58:33 +02:00
Alexander Grund
71f1dc4225 Add coverage collection for VS 2017 on appveyor
The `std::collate` bug is only triggered on the VS 2017 image on
appveyor hence it is the only one where `collation_works` returns false
and the `utf8_collator_from_wide` is used.
So to collect coverage for that this is the configuration to do it.
2023-06-12 14:34:34 +02:00
Alexander Grund
90320132db GHA-CI: Show library config on Windows CI
For debugging especially the available locales are important.
So run `show_config` with `--verbose-test` also on Windows similar to
the POSIX jobs.
2023-06-12 12:44:42 +02:00
Alexander Grund
90125f7bab Workaround a Windows collation bug with UTF-8 system locale
On that affected system:
  - `col.compare("a", "b") == col.compare("b", "a") == 1`
  - hence `locale("a", "b") == locale("b", "a")`
  - `col.transform("a")` thows `std::length_error(string too long)`
To avoid this we fallback to `utf8_collator_from_wide` instead
2023-06-11 17:00:24 +02:00
Alexander Grund
29f87ebed7 Add time_put_from_base back
This was removed as it is basically forwarding the call and hence looks
very similar to what `std::time_put_by_name` does.
However the `ios_base&` in the `do_put` function is actually used to
e.g. translate weekday names or determine the date format to use
(e.g. whether the year has 2 or 4 digits
or month comes before or after the days: dd/mm vs mm/dd)
Very likely the `std::locale::name` is used for that so we need to pass
a `std::ios_base&` with a locale that was constructed by the requested name.
2023-06-11 17:00:24 +02:00
Alexander Grund
0991420a36 Fix utf8_collator_from_wide::do_transform
Revert that part of the change and generalize.
We can't use `utf_to_utf` as the result may not be valid UTF.
2023-06-11 17:00:23 +02:00
Alexander Grund
6a48f2787b Create std/utf8_converter & utf8_collate by name
Creating a base locale with a seemingly random facet makes it hard to
understand as this specific facet is only required in the class.
Passing the name and creating the required facet in the class is easier
to understand as creation and usage are closer.
2023-06-11 17:00:23 +02:00
Alexander Grund
2fbb7476cf Reconcile utf8_support handling in std backend
Document the meaning of the `utf8_support` enum and refactor/change
usages to be consistent and logical. Add comments where required.

Rename `native_with_wide` to `native` after that got free for use as
there is no `native_without_wide`.
2023-06-11 17:00:22 +02:00
Alexander Grund
e1f7352107 Remove unused utf8_support::native 2023-06-11 17:00:10 +02:00
Alexander Grund
5e5ede5e29 Merge pull request #177 from Flamefire/utf8-classic-fallback
Ensure that UTF-8 encoding is used when requested in std backend
2023-06-10 09:51:13 +02:00
Alexander Grund
c594880f73 If UTF-8 requested use Unicode enabled classic locale if supported
E.g. on Linux this is required or `ctype<wchar_t>.toupper` will not
correctly handle unicode characters.
Refactor to a loop over possible fallbacks to use with from_wide
and combine it with the Windows locale name case.
Also try different spellings of the encoding as e.g. some stdlibs want
"utf8" while others only accept "UTF-8".
2023-06-09 10:54:13 +02:00
Alexander Grund
90c1fc2d76 Cleanup defines in std-backend
Move the interleaved checks for WinAPI to the using function.
Also refactor `normalize_encoding` & `encoding_to_windows_codepage`
to take `string_view` and make the latter always available.
2023-06-09 10:54:13 +02:00
Alexander Grund
458aeee83c Use the C++11 cstdint header instead of the boost fallback 2023-06-09 10:41:44 +02:00
Alexander Grund
0bf6ba514d Replace unsafe usages of reinterpret_cast
Such casts usually work but are technically undefined behavior
if the target isn't `(unsigned) char`
2023-06-09 10:41:44 +02:00
Alexander Grund
7cc271765c Try the fallback locale always on Windows
When `to_windows_name` failed to returned `"C"` which is loadable and
hence skips the fallback locale check.
So check if a valid windows_name was returned.
2023-06-08 18:44:43 +02:00
Alexander Grund
1792407b81 Ensure that UTF-8 encoding is used when requested
Replace the failure by using the C-locale with `utf8_support::from_wide`
similar to the non-UTF-8 codepath such that if the `info` facet returns
UTF-8 then it is really used and not (likely) US-ASCII.
2023-06-08 18:44:43 +02:00
Alexander Grund
1be9d99566 Add fallback if UTF-8 locale cannot be loaded
Check if locale without (the UTF-8) encoding exists and use that with
`utf8_support::from_wide` before failing.
2023-06-08 18:44:43 +02:00
Alexander Grund
42c2a6d6e0 Raise an error if an UTF-8 locale was requested but couldn't be loaded 2023-06-08 18:44:42 +02:00
Alexander Grund
a821f487fb Show availability of UTF-8 C-locale in show_config
Helps to debug potential failures due to missing UTF-8 support.
2023-06-06 14:46:07 +02:00
Alexander Grund
0b0b3e4f1b Add missing typeinfo include 2023-05-30 21:19:50 +02:00
Alexander Grund
8d231b1dad Improve exception reporting in testsuite 2023-05-30 16:50:45 +02:00
Alexander Grund
b8d591e871 Use RAII class icu_handle and factor out and reuse uconv 2023-05-30 08:47:10 +02:00
Alexander Grund
825562182c Use utf_to_utf when target/source encoding is known to be UTF-8
Improves speed by using static dispatch and inlining.
2023-05-29 18:36:01 +02:00
Alexander Grund
85a0c19475 Avoid uninitialized warning in test 2023-05-28 12:22:14 +02:00
Alexander Grund
156c3930ad Avoid exceptions when creating simple_converter
Intead of throwing and catching an exception on every unconvertible char
in the range `[128,256)` skip it and let the size check handle it.
2023-05-28 12:22:14 +02:00
Alexander Grund
904d18a9f6 Test generated facets for different locales
Allow to catch cases where the facet is only generated for e.g. UTF-8
2023-05-28 12:22:14 +02:00
Alexander Grund
cfa4a3ea7a Refactor date/time part of test_*_formatting
Instead of doing a combined formatting and comparison of many format
parts (`as::date`, `as::time` & `as::datetime`) test each one
individually to be able to spot issues easier when it fails
2023-05-26 19:35:36 +02:00
Alexander Grund
6a95c82083 Simplify tests with empty_stream
Add a function to clear a string stream (i.e. make it empty)
and use it instead of `s.str(some-templated-empty-string)`
2023-05-26 19:35:36 +02:00
Alexander Grund
6ae2db2d03 Merge pull request #175 from Flamefire/cygwin-winapi
Make std backend fall back to classic locale instead of system locale
2023-05-25 12:44:05 +02:00
Alexander Grund
fcf50b5262 Make std backend fall back to classic locale instead of system locale
Partial fix of #172
2023-05-24 17:00:37 +02:00
Alexander Grund
dfb4dad677 Add missing include to locale_data.hpp to locale.hpp 2023-05-24 16:56:27 +02:00
Alexander Grund
2a1de6cd9b Enable the fallback to Windows locale name on Cygwin
As Cygwin may use the WinAPI we can do the same checks there.
2023-05-24 12:59:45 +02:00
Alexander Grund
51df38ff17 Avoid the c_str getter where possible
Since C++11 we can directly pass the string to
e.g. `std::facet_by_name` making the code more readable.
2023-05-23 18:56:12 +02:00
Alexander Grund
1dfe26c550 Reactoring: Replace CHAR*-pair by string_view
Make it obvious what the pair is for.
2023-05-16 13:29:46 +02:00
Alexander Grund
5366747fe2 Minor refactoring using const and avoiding includes 2023-05-16 12:04:59 +02:00
Alexander Grund
9b1813e757 Remove superflous braces
Make the code a bit shorter vertically, enforced formating ensures
correct indentation which provides enough readability
2023-05-16 12:04:59 +02:00
Alexander Grund
154a0e1a89 Add test using non UTF-8 message key encoding
Check an optimisation not yet tested: Use the catalog with different key
encoding when there are only ASCII keys.
2023-05-16 10:49:58 +02:00