358 Commits
Author SHA1 Message Date
Paul Cornett b5a4a389fb Avoid -Wformat-signedness warnings 2026-07-16 20:44:58 -07:00
Paul Cornett eb44efae4b Avoid some -Wzero-as-null-pointer-constant warnings
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Has been cancelled
CMake builds / MSW/MSVC wxMSW (push) Has been cancelled
CMake builds / MSW/Clang wxMSW (push) Has been cancelled
CMake builds / macOS latest wxOSX Ninja (push) Has been cancelled
CMake builds / macOS 14 wxOSX Xcode (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 5.15 (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 6.10 (push) Has been cancelled
Mac builds / wxMac ARM ASAN not compatible (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxiOS Simulator on Silicon Mac (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / wxMSW vs2026 DLL Release x64 (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits not compatible (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
2026-06-15 22:37:00 -07:00
dxbjavid a3ad8e3360 Fix buffer overflow in wxVsnprintf() when size==0
Don't write NUL byte to "buf[size - 1]" when size is 0.

This bug was present in both implementations of wxVsnprintf(), so fix it
in both places too.

Closes #26522.
2026-05-31 15:41:46 +02:00
Vadim Zeitlin cf50020259 Avoid buffer read overflow in wxCharTypeBuffer ctor
Don't assume that the data is always followed by NUL.

Closes #26527.
2026-05-30 18:00:35 +02:00
Vadim Zeitlin b2342ec001 Stop checking if wchar_t is a distinct type, just assume it is
We don't support ancient MSVC version which didn't treat wchar_t as a
distinct type, so don't bother catering for such compilers and simplify
the code by removing the checks for wxWCHAR_T_IS_REAL_TYPE.

Also remove the checks for this from configure and CMake.
2026-04-07 23:21:57 +02:00
Václav Slavík f972df830e Add test for wxString::operator<=> 2026-03-18 17:26:03 +01:00
utelle 4c7500631d Skip some wxNumberFormatter tests under old Windows versions
On some Windows platforms locale information used in the number
formatting tests is not reported correctly.

Adjust CanRunTest() to skip running the tests on such platforms.

See #25675.

Closes #25878.
2025-10-14 12:42:46 +02:00
Ulrich Telle 8c46e47ecf Support more aspects in wxUILocale and wxNumberFormatter
Add support for currency amounts, including functions for retrieving
currency symbol and currency code for the current locale and the
possibility to format such amounts according to the locale rules.

Allow retrieving more information about numeric values formatting, for
both numbers and currency amounts, including grouping information when
group separator is used and number of digits after decimal separator and
also use them when formatting numbers.

Finally add function to retrieve the measurement system (metric or
imperial) used by the current locale.

See #1781.

Closes #25765.
2025-10-09 23:16:22 +02:00
Vadim Zeitlin fd0c23ee24 Add wxString::AssignFromUTF8() function
This can be used to optimize repeated conversions from UTF-8 by reusing
the string buffer.

See #25740.
2025-08-30 16:33:39 +02:00
Vadim Zeitlin b672131185 Replace hex and octal escapes with literal UTF-8 characters
This makes the code more readable and there should be no reason not to
use UTF-8 in string literals any longer.

Also replace wxHAVE_U_ESCAPE (all still supported compilers have it)
with wxMUST_USE_U_ESCAPE, which is only set for MSVS 2015 currently and
will be removed when we drop support for it and can use literal Unicode
characters in the wide strings everywhere.
2025-06-20 17:42:55 +02:00
Vadim Zeitlin b4e873312e Fix build regression due to a preprocessor condition in a test
This fixes a typo resulting in build failure from the recent b9726c02d5
(Disable sporadically failing test in MSVS 2019 CI build, 2025-05-09).

See #25056.
2025-05-10 16:06:14 +02:00
Vadim Zeitlin b9726c02d5 Disable sporadically failing test in MSVS 2019 CI build
This is not great, but this tests keep failing for no apparent reason.

Closes #25056.
2025-05-09 19:45:04 +02:00
Vadim Zeitlin 12b29979d3 Avoid setting locale to UTF-8 in the tests under Windows
Unix builds / Ubuntu 24.04 wxGTK with ASAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK with UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / Windows MSVC (push) Has been cancelled
CMake builds / macOS 14 wxOSX (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / Windows wxQt 6.8 (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxMac ARM with ASAN (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac macOS 14 (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2019 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2019 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / msw-msys2-clang (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
Update Documentation / Update Online Documentation (push) Has been cancelled
Maybe this is somehow responsible for the mysterious crashes in this
test in the CI jobs.

See #25056.
2025-03-30 20:57:40 +02:00
Vadim Zeitlin e958b834cf Don't test wxGetenv(char*) with non-ASCII values under MSW
This doesn't work because the CRT always uses CP_ACP for converting and
if the current locale encoding is not UTF-8 (which is not the case for
this test), it doesn't work for arbitrary Unicode strings.

Document this limitation as well as the recommended alternative.
2025-01-21 18:46:10 +01:00
Vadim Zeitlin b1c866fc2a Use UTF-8 in wxGetenv() overload for wide strings too
This uses different code path than wxGetEnv(wxString) and while it would
probably be better to somehow avoid this, for now just make the same
changes to this function as were made to the other one in the parent
commit.
2025-01-20 03:36:40 +01:00
Vadim Zeitlin 3ebcfe25c3 Use UTF-8 for environment variables names and values under Unix
This is a much more reasonable conversion to use than the current locale
encoding for the values defined outside of the program and we can still
fall back to the latter if using UTF-8 doesn't work by using
wxConvWhateverWorks.

Also use the same approach for the user name.
2025-01-20 03:36:39 +01:00
Vadim Zeitlin 16e46bf8d3 Fix wxString::BeforeFirst() when "rest" is the string itself
This didn't work correctly before, but there doesn't seem to be any good
reason to not allow this, as it allows to naturally extract some leading
prefix from a string and it also already worked for BeforeLast(), so
make it work for BeforeFirst() too.
2025-01-15 02:21:05 +01:00
Vadim Zeitlin 7aa6da06d0 Remove wxUSE_LONGLONG and always use wxLongLong_t
All supported platforms provide 64-bit integer types since many years,
so remove the legacy wxLongLongWx implementation and rename
wxLongLongNative to just wxLongLong and always compile it in.

Note that wxLongLong itself must still be kept for compatibility as it
has member functions, such as GetValue() or ToString(), that can be used
in the existing code.
2024-10-18 19:26:15 +02:00
Lauri Nurmi 007787c3a8 Remove unused wxString variables
A few were removed tests/, which might have existed for readability.
2024-10-02 00:31:08 +03:00
Vadim Zeitlin b3359a922d Include errno.h before using errno in the string unit test
Even if the code currently compiles without this, it's still better to
explicitly include the header we need.
2024-03-12 16:51:12 +01:00
Vadim Zeitlin 2573e61c19 Fix harmless MSVC warning about uninitialized variables in a test
MSVS 2022 gave C4701 when std::isinf(d) was used below in release build.
2023-12-25 17:24:55 +01:00
Ian McInerney 97cba7c0ca Restore ToCDouble compatibility with leading spaces/+ and hex
The previous ToCDouble() function accepted leading spaces, a starting +
sign, and hex strings. std::from_chars() does not accept spaces or +,
and requires a special flag to convert hex strings, so handle this
manually to preserve the old behaviour of this function.

This is similar to the changes done for ToCULong() in #24022.

Closes #24089.
2023-11-30 02:29:58 +01:00
Vadim Zeitlin dede4b9326 Use "= default" for all trivial default ctors and dtors
Replace user-specified empty constructors and destructors with the
compiler-generated versions, which has a number of advantages for code
generation, in addition to being more clear.

Closes #22965.

Closes #24058.
2023-11-17 01:33:32 +01:00
Vadim Zeitlin ae2b05be5c Fix more compatibility problems in C++17 wxString::ToLong()
Unlike the traditional C functions, std::from_chars() doesn't skip
leading whitespace and doesn't accept the leading "+" sign, so we need
to skip them explicitly to preserve the behaviour of ToLong() in the
previous wxWidgets versions.
2023-10-31 00:44:10 +01:00
Vadim Zeitlin 8d6a722ed8 Fix C++17 implementation of wxString::ToCULong()
Do use std::from_chars<unsigned long>() in it as otherwise values
greater than LONG_MAX failed to parse.

Handle negative numbers explicitly to still parse them in this function
as well, as needs to be done for compatibility.

Add a test case for the previously failing numbers.

Closes #23957.
2023-10-31 00:44:10 +01:00
Joan Bruguera Micó 19936c2176 Don't clobber std::string_view equality with char *
Make the wxString(std::string_view) constructor explicit.

Otherwise, when comparing a std::string_view with a const char *, the
cast to wxString will be considered as a candidate for the comparison,
ultimately causing an "ambiguous overload for 'operator=='" error.

For example, this sample only builds if the constructor is explicit:

  #include <wx/string.h>
  #include <string_view>

  int main() {
    std::string_view view = "abc";
    const char *str = "abc";
    return view == str;
  }

However, making the constructor explicit will break assignment:

    std::string_view view = "abc";
    wxString s;
    s = view; // Error: no match for "operator="

That we can fix by implementing operator=(std::string_view)

That, however, introduces another ambiguity:

    std::string str = "abc";
    wxString s;
    s = str; // Ambiguous between s = wxString(str)
                              and s = std::string_view(str)

That we can fix by implementing operator=(std::string)

Finally, note that some rather obscure ambiguities remain, such as:

    wxString s;
    s = {"abc", 2}; // Ambiguous between s = wxString("abc", 2)
                                     and s = std::string_view("abc", 2)

Avoiding them is not simple (https://cplusplus.github.io/LWG/issue2946)
and doesn't add much value.

Closes #23834.
2023-09-06 02:44:11 +02:00
Ian McInerney b8d3b37c9e Add new macro for standard library header inclusion
Newer standard library headers should only be included when the compiler
is targetting that standard, otherwise some compilers (like MSVC) will
warn that you are using a newer C++ include on an older version.
2023-07-24 16:54:14 +01:00
Ian McInerney 3dfb2a5ac1 Add std::string_view constructors to wxString 2023-07-20 19:59:01 +01:00
Vadim Zeitlin 85e88d6af3 Merge branch 'format-unicode-fix' of https://github.com/lanurmi/wxWidgets
Fix for wxLocale breaking Unicode string formatting under macOS.

See #23454.
2023-04-28 15:06:54 +02:00
Vadim Zeitlin 7465d8297e Add wxString::wc_string() for consistency
We have utf8_str() and utf8_string(), but no similar equivalent for
wc_str(), so add one too, it seems nicer to use than ToStdWstring().

Closes #23463.
2023-04-20 15:20:13 +02:00
Lauri Nurmi aefd1e41c7 Attempt to test whether wxLocale breaks formatting Unicode strings 2023-04-17 02:04:59 +03:00
Vadim Zeitlin 889845fbc4 Add support for wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR to wxString
This symbol is similar to the existing wxNO_IMPLICIT_WXSTRING_ENCODING
and can be defined when building the application (as opposed to when
building the library) to disable implicit wxString conversions to
pointer types, i.e. char*, wchat_t* and void*.

This makes the just added wxUSE_CHAR_CONV_IN_WXSTRING library build
option unnecessary, so remove it.
2023-04-16 01:16:56 +02:00
Vadim Zeitlin 4913857ef7 Define wxNO_UNSAFE_WXSTRING_CONV if wxUSE_UNSAFE_WXSTRING_CONV==0
This doesn't really change anything, but allows to simplify the tests,
as we can now check only for wxNO_UNSAFE_WXSTRING_CONV and this covers
both the case of the library compiled without support for the unsafe
conversions at all and the case when the conversions are disabled by
explicitly defining wxNO_UNSAFE_WXSTRING_CONV when building the
application.
2023-04-16 01:16:56 +02:00
Vadim Zeitlin 35c35c235e Remove wxUSE_STL which is not really used any longer
wxString is always based on std::[w]string since 2c0c727f49 (Remove wx
own wxStringImpl implementation, 2022-11-16) and all containers use
standard containers by default too now -- and there is a separate
wxUSE_STD_CONTAINERS for this anyhow.

The only remaining use of wxUSE_STL was as the default value for
wxUSE_STD_STRING_CONV_IN_WXSTRING option, but it's not really needed
for this neither, and this option can just be set to 0 by default.

Also add wxUSE_CHAR_CONV_IN_WXSTRING which can now be set to 0 too to
disable all unwanted implicit conversions (even "safe" ones, to wide
strings, in addition to the unsafe ones to narrow strings that could be
already disabled with wxUSE_UNSAFE_WXSTRING_CONV) to allow people who
don't want to have any implicit conversions at all to do it.

Keep --enable-stl configure option for compatibility, but warn if it is
used to tell people that it is not needed any longer.
2023-04-15 17:22:09 +02:00
Vadim Zeitlin 9b1d031a1b Show more information if wxString::ToLong() tests fail
Make it possible to see which test failed if one did.
2023-04-05 15:59:36 +02:00
Vadim Zeitlin 2b5dbd1ec5 Get rid of CppUnit boilerplate in wxString unit test
No real changes, just remove the completely useless StringTestCase and
use Catch macros directly instead of CPPUNIT_ASSERT wrappers.
2023-03-28 13:48:13 +01:00
Vadim Zeitlin 1869f9ec6f Use range for instead of iterators in unit test
No real changes, just simplify the code and ensure that iterating over a
string using range for loop works as expected.
2023-03-26 17:56:55 +01:00
Pavel Tyunin de59024f53 Better move constructor test
Previous version didn't actually call the move constructor.
2023-02-05 13:09:08 +02:00
Pavel Tyunin 1a46836e88 Remove unused test variables 2023-02-05 13:09:07 +02:00
Pavel Tyunin e04a8de87a Remove duplicated assign() tests and move remaining ones from AssignOp 2023-02-05 13:09:06 +02:00
Pavel Tyunin 62f83858a0 Add tests for wxString assignment operator 2023-02-03 22:09:52 +02:00
Pavel Tyunin 974feb4c39 Add tests for wxString move constructors 2023-02-03 22:09:52 +02:00
Vadim Zeitlin 20489626e8 Remove code restoring errno in StringTestCase::Format()
There doesn't seem to be any need to do this, so don't.
2023-01-07 16:50:28 +01:00
Lauri Nurmi ed897d9641 Restore value of errno after wxString::ToInt()/Long()/etc.
Such functions modifying errno is undocumented, and may come
as a surprise to the caller. Consequently also a call to
wxString::Format() would modify errno.
2023-01-06 18:04:53 +02:00
Artur Wieczorek 2b4ee50f34 Reimplement tests with Catch
Use Catch instead of CppUnit for all unit tests here.
2022-12-07 20:52:33 +01:00
Vadim Zeitlin 21549149f0 Check that missing format string arguments are detected
We now assert if not enough arguments are given to a vararg function, as
we can actually do it when checking it all at once, unlike before when
we only checked for the matching format specifier for each argument, so
add a test verifying that this works as expected.
2022-11-23 19:21:36 +01:00
Vadim Zeitlin be7860c766 Remove wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY
Assume they are always 1 now, there is no good reason to ever set them
to 0 any more.

Note that we still keep wxUSE_STD_IOSTREAM for now, but we can drop
wxUSE_STD_DEFAULT as it's not worth having it just for this single
option (previously it was used as the default value for 3 of them).
2022-11-17 00:40:50 +01:00
Vadim Zeitlin 3bc0d1ed92 Deprecate unused wxMBConv parameters in wxString functions
Some wxString functions using wide strings still took wxMBConv just for
consistency with the same functions taking narrow strings in ANSI build,
but this doesn't really make sense any longer because the same code
can't be compiled with different values of wxChar -- it is always the
same thing as wchar_t now, and so we shouldn't pass unused conversion
objects to these functions any more.

So give deprecation warning when these functions are used (but without
formally deprecating them, as it doesn't cost much to keep them) and
avoid using them in the library code.
2022-10-28 21:16:10 +01:00
Vadim Zeitlin 4519d8e08a Remove wxUSE_UNICODE checks as they're always true now
Also remove all code guarded by "#if !wxUSE_UNICODE".
2022-10-27 19:43:30 +02:00
Vadim Zeitlin f2cfcd3d2f Avoid another warning triggered by the last warning workaround
Initialize a variable to avoid -Wmaybe-uninitialized triggered by using
wxUnusedVar() with it now.
2022-10-18 21:40:48 +02:00