Commit graph

480 commits

Author SHA1 Message Date
Vadim Zeitlin
133fd7faa1 Fix wxString::GetCache() compilation in UTF-8 DLL build with MSVS
Don't declare static Cache variable inside wxString declaration itself
because it is implicitly DLL-exported, due to the use of
__declspec(dllexport) for the entire wxString class, but thread-specific
variables can't be exported, so this resulted in a compilation error.

Avoid this by using a static thread-specific variable inside GetCache(),
which had to be moved out of line.
2023-03-26 17:56:55 +01:00
Hartwig Wiesmann
313a415e2e Fix harmless warning in wxString in wxUSE_UNICODE_UTF8 build
Add an explicit cast from ptrdiff_t to unsigned int to avoid the
warning which is harmless because the difference here is bound by the
cache size.

See #23297.
2023-02-25 22:51:47 +01:00
Pavel Tyunin
31ca15fa47
Add noexcept to wxString::swap() 2023-02-03 22:09:52 +02:00
Pavel Tyunin
e438079485
Add non-member swap to wxString 2023-02-03 22:09:52 +02:00
Pavel Tyunin
bcda42a082
Add rvalue versions of wxString assignment and construction functions 2023-02-03 22:09:52 +02:00
Pavel Tyunin
d00a072dc5
Add move operations to wxString 2023-02-03 22:09:51 +02:00
Blake-Madden
dc7e970177 Initialize some wxString structs members in their declarations
This avoids some spurious -Wmaybe_unitialized warning when using
`std::optional<wxString>` with gcc and is also generally better practice
as it ensures that the fields are always initialized correctly.

Closes #23167.
2023-01-29 01:42:08 +01:00
Vadim Zeitlin
94e3827988 Remove leftover blocks that used to be used in ANSI build
Update some comments and prefer using #if/#else when testing for
wxUSE_UNICODE_UTF8 and wxUSE_UNICODE_WCHAR rather than #if/#elif as
exactly one of them is always defined now. Similarly, test for
wxUSE_UNICODE_WCHAR directly instead of testing !wxUSE_UNICODE_UTF8 and
vice versa.

It could be nice to actually test for just a single one of these symbols
everywhere, but this would require a lot of noisy changes, so for now
keep the code as is.

No real changes, just simplify.
2023-01-12 17:08:59 +00:00
Vadim Zeitlin
275ab09ed7 Switch to a simpler wxString::Printf() implementation
Don't use std::index_sequence, as this has some advantages:

- This way doesn't require using another helper function, which is
  burdensome here and would be even more so if we had to do it for all
  the other wx vararg functions too.

- We don't need to require C++14 and can keep supporting even g++ 4.8.

The sole drawback is that we cannot pass the index of the argument to
wxArgNormalizer ctor any longer, which means that we can't validate it,
but this is addressed by validating the entire format string at once in
the new Validate() member function, which is also more efficient than
the old way for the format strings with more than one format specifier,
as they only need to be parsed once now, instead of having to do it for
each format specifier separately when GetArgumentType() is called.

This also means that we can't handle char arguments differently
depending on whether they are used with "%c" or "%d" format specifier.
This is a backwards-incompatible change, but should affect very few use
cases, so it seems to be worth breaking it to get the above benefits.
2022-11-23 02:47:41 +01:00
Vadim Zeitlin
c453167c71 Take wxFormatString in wxString::Format() and sprintf() too
The argument of these functions will have to be converted to
wxFormatString anyhow in Printf(), so take it directly, as this at least
means that only a single conversion will be done, when Format() is
called, instead of converting whatever is passed to it to wxString
before converting this wxString to wxFormatString.
2022-11-23 02:44:50 +01:00
Vadim Zeitlin
6456ddac57 Reimplement wxString::Printf() as variadic template
This implementation uses std::index_sequence which is C++14-only, so
we'll need to increase the minimum C++ version requirements if we use
it.
2022-11-23 02:44:50 +01:00
Vadim Zeitlin
2c0c727f49 Remove wx own wxStringImpl implementation
Always use std::basic_string<> as wxStringImpl.

Closes #22883.
2022-11-17 00:40:50 +01:00
Vadim Zeitlin
b4b23ac423 Merge branch 'always-use-thread-local'
Always use thread_local as we can rely on compiler TLS support working
under Windows 7 and later.

There are some known problems in MinGW thread local variable support,
but they only affect (obsolete) 32-bit builds and will hopefully be
fixed in this compiler soon.

See #22917.
2022-11-10 16:32:42 +01:00
Vadim Zeitlin
2d1928e6aa Correct misleading comment for wxString::IsSameAs() overloads
They can't be removed as doing it would result in errors when compiling
any code using IsSameAs() due to ambiguous conversions.
2022-10-28 21:17:15 +01:00
Vadim Zeitlin
37418eed8e Replace wxWritableCharBuffer template with 2 simpler classes
This addresses a FIXME comment in this template, it was written in a
generic form to compile in both Unicode and ANSI builds of the library,
but now it can be written more simply and efficiently (in the "char"
case).

No real changes.
2022-10-28 21:17:15 +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
ed748bd5a8 Remove wxTLS_XXX() macros from wx itself
Still use wxTHREAD_SPECIFIC_DECL as it is defined as nothing when
wxUSE_THREADS==0, but get rid of wxTLS_VALUE and friends.

Also enable wxUSE_STRING_POS_CACHE when wxUSE_UNICODE_UTF8 because the
issues described in the (now also removed) comment shouldn't occur with
the compiler implementation of the thread-specific variables.
2022-10-26 03:31:54 +02:00
Vadim Zeitlin
16a746ec35 Remove tests for wxHAS_COMPILER_TLS from wx code
It is now always defined, so they're useless.
2022-10-26 03:31:54 +02:00
Vadim Zeitlin
4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
Vadim Zeitlin
0a387693c6 Use std::wstring unconditionally
Don't test for its existence in configure and CMake and don't use
wxStdWideString in the code.
2022-10-11 00:45:30 +02:00
Vadim Zeitlin
6bbfdb157e Check that C++11 is available and remove tests for it
Don't bother checking for various C++11 features that are available in
all C++11 compilers.

Also assume that std::exception_ptr is available in all still supported
MinGW versions and remove checks for it too (see #16634).

Further simplifications remain possible, this is just the first step.
2022-10-11 00:02:29 +02:00
Lauri Nurmi
66916c74a3 Fix double negatives used with 'neither' in docs and comments
In many cases it should be 'either', and 'nor' should be 'or'
accordingly.

No changes to actual code.

Closes #22723.
2022-08-19 16:22:21 +02:00
Artur Wieczorek
5e2da5a106 Get rid of v2.8 code 2022-08-02 08:26:29 +02:00
Vadim Zeitlin
d311a07b7a Remove unnecessary test which was needed for macOS < 10.7 only
There is no need to check for the weird case of using a C++11 compiler
with C++98 standard library any longer, this is not supposed to happen
and we don't support macOS < 10.7 since a very long time anyhow.
2022-05-11 16:49:43 +01:00
Gerhard Gruber
9dc7248b1d Add conversion to signed/unsigned int to wxString
Add wxString::ToInt() and ToUInt() for convenience and consistency with
the existing ToLong() and ToULong().

Closes #22068.
2022-03-26 00:46:58 +01:00
Blake Madden
668a2186cd Fix comment typos in sources
No real changes.

Closes https://github.com/wxWidgets/wxWidgets/pull/2541
2021-10-03 17:07:44 +02:00
Vadim Zeitlin
0f8e976ac3 Add wxString::utf8_string()
This adds a yet another conversion function, which is not ideal, but
still better than having to write ToStdString(wxConvUTF8) every time for
losslessly converting wxString to std::string: not only this is too
long, but it's also too easy to forget to specify wxConvUTF8, resulting
in data loss when using non-UTF-8 locale.
2021-03-06 15:12:07 +01:00
PB
a6d4799de9 Remove BCC-specific conditionally compiled code 2020-10-13 18:40:31 +02:00
Vadim Zeitlin
3fc5d134a3 Suppress strange -Wunsafe-loop-optimizations in wxString code
The error message

wx/string.h:558:47: error: missed loop optimization, the loop counter may overflow
                    [-Werror=unsafe-loop-optimizations]
       for ( Cache::Element *c = cacheBegin; c != cacheEnd; c++ )
                                             ~~^~~~~~~~~~~

doesn't seem to really make much sense, as it shouldn't overflow here.
2020-08-31 12:40:50 +02:00
Vadim Zeitlin
a535d2c64d Suppress -Wnull-dereference in wxString::GetCacheElement()
It doesn't seem to be really possible here.
2020-08-31 12:40:50 +02:00
Arrigo Marchiori
464aeb8f84 avoid using wxNO_IMPLICIT_WXSTRING_ENCODING in utf-8-only builds 2020-07-17 17:52:16 +02:00
Arrigo Marchiori
57e136d9e1 Enforce consistency of encoding-related macros
Force wxNO_UNSAFE_WXSTRING_CONV on if wxNO_IMPLICIT_WXSTRING_ENCODING is
on, as the latter is even stronger than the former.
2020-07-17 17:52:16 +02:00
Vadim Zeitlin
a2609429a3 Apply implicit encoding check to wxString::{starts,ends}_with() too
Don't provide the overloads taking "const char*" when compiling with
wxNO_IMPLICIT_WXSTRING_ENCODING is defined.
2020-07-17 17:52:16 +02:00
Arrigo Marchiori
65cbf40b7e Add wxNO_UNSAFE_WXSTRING_CONV2 macro
The macro disallows implicit conversions between wxString and const
char*
2020-07-17 17:34:38 +02:00
Vadim Zeitlin
63626acbe4 Fix std::ostream::operator<<(wxScopedWCharBuffer)
This never worked correctly as using operator<<() with wchar_t pointer
just fell back to the overload for void pointers, i.e. printed out the
address of the wide string, which wasn't especially useful, but with
C++20 it doesn't even compile, as this overload is explicitly deleted.

Fix both problems at once by actually doing something useful for it
instead and printing out data in either current encoding or UTF-8 if
converting it to the current encoding failed.
2020-05-10 23:00:00 +02:00
Vadim Zeitlin
176b9dde90 Fix wxString iterator comparison in C++20
In C++20 the reverse comparison operators are also considered when
searching for the operator to use and a wrong operator was selected for
comparisons between iterator and const_iterator, that would result in an
infinite recursion at run-time.

Fix this, thanks to the nice gcc 10 warning about it, by explicitly
defining the operators for this overload set too instead of relying on
implicit conversions.

Although not all these overloads are necessary, and they are only
necessary in C++20, it seems better to define all of them and always
just to be perfectly explicit and clear, as this code is not exactly
simple to follow.
2020-05-10 22:57:41 +02:00
Paul Cornett
b256db8f0f Restore previous behavior of wxString::operator<<(float) 2020-04-22 07:46:06 -07:00
Paul Cornett
c5faf9cfac Avoid passing float argument for "%f" printf specifier
"%f" takes a double. Eliminates some -Wdouble-promotion warnings.
2020-04-21 11:59:36 -07:00
Vadim Zeitlin
ad7fb7f4aa Merge branch 'warnings' of https://github.com/catalinr/wxWidgets
Fix MSVS analyzer warnings about int multiplication overflow and
uninitialized member variables.

See https://github.com/wxWidgets/wxWidgets/pull/1606
2019-10-15 22:50:17 +02:00
Paul Cornett
a3598ba33f Remove unnecessary copy ctors/copy assignment operators
C++11 deprecates having one without the other.
Eliminates many, many GCC -Wdeprecated-copy warnings.
2019-10-14 09:07:21 -07:00
catalinr
2fc569f0c2 Initialize member variables to avoid warnings 2019-10-14 08:09:47 +03:00
Paul Cornett
536025791a Avoid converting empty strings to NULL pointers in non-Unicode build
...when using utf8_str() or wxGTK_CONV as argument to const char* function parameter
2019-08-25 23:08:59 -07:00
Vadim Zeitlin
ea965327eb Add wxString::shrink_to_fit() as synonym for Shrink()
Provide C++11 std::string-compatible method name too.
2019-08-22 00:01:36 +02:00
Lauri Nurmi
4739b9dedd Add C++20-style starts_with()/ends_with() functions to wxString
C++20 introduces these two functions, along with some overloads, to
std::string. Add similar functions to wxString, which simply call the
already existing StartsWith() and EndsWith().

Closes https://github.com/wxWidgets/wxWidgets/pull/1452
2019-07-31 00:52:29 +02:00
Vadim Zeitlin
91b3bfedf8 Fix using std::reverse() with wxString iterators in a proper way
The solution with specializing std::iter_swap() for wxString::iterator
was not conforming as the iterator was still not swappable, as it is
required to be.

Fix this by providing std::swap() overload for wxString::iterator, which
is correct and even simpler.

This allows std::reverse(s.begin(), s.end()) work with clang too and
incidentally avoids warnings about the code relying on non-conforming
extensions with MSVS 2017 which were due to the fact that iter_swap()
workaround wasn't enabled for it, while the new swap() overload is.
2019-04-26 03:20:38 +02:00
Vadim Zeitlin
90edeace90 Merge branch 'ansi-fix'
Fix wxMSW compilation errors in non-Unicode build.

See https://github.com/wxWidgets/wxWidgets/pull/858

Closes #18172.
2018-07-24 15:15:28 +02:00
orbitcowboy
8dfd799fd5 Use const for constant local variables in wxWidgets headers
This avoids warnings from MSVS 2017 static analyzer when C++ core rule
set is activated.

Closes https://github.com/wxWidgets/wxWidgets/pull/819
2018-07-21 16:16:32 +02:00
Vadim Zeitlin
d390bee8a2 Allow comparing wxString with wide strings in non-Unicode build
This fixes a compilation error in wxMSW private fonts support
implementation, which compares wxString with a wide string but, unlike a
local fix there, makes sense more broadly and should reduce the
likelihood of similar errors in the future.

It also makes comparisons with narrow C strings more efficient in the
default, Unicode, build by using wxString::Cmp() method instead of
creating a temporary wxString, as was done before.

See #18172.
2018-07-21 14:08:45 +02:00
Vadim Zeitlin
4a53b029de Mark WXSTRINGCAST and related macros as obsolete in a comment
Make it clear that these macros are defined for compatibility only and
shouldn't be used.

See https://github.com/wxWidgets/wxWidgets/pull/857
2018-07-21 13:25:44 +02:00