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.
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.
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.
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.
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.
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.
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).
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.
Most of them can't be expected to work, e.g. non-ASCII file names can't
be supported without Unicode support.
Some others, e.g. test for NULs in wxDataOutputStream, are questionable,
as it seems that it might be possible to fix them in ANSI build too, but
for now just do the simplest thing to make the tests pass on Travis.
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
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.
Specialize std::iter_swap() for wxString::iterator in C++11 mode as the
default implementation of it doesn't work for iterators using "reference" type
different from "value_type&" as is the case for wxString::iterator.
This notably allows the code using std::reverse() with wxString iterators to
compile in C++11 mode, which wasn't the case before.
This keyword is not expanded by Git which means it's not replaced with the
correct revision value in the releases made using git-based scripts and it's
confusing to have lines with unexpanded "$Id$" in the released files. As
expanding them with Git is not that simple (it could be done with git archive
and export-subst attribute) and there are not many benefits in having them in
the first place, just remove all these lines.
If nothing else, this will make an eventual transition to Git simpler.
Closes#14487.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
Disable unit tests involving operations (such as conversions between UTF and
anything but plain ASCII) not available in ANSI build.
This fixes the test suite for non-Unicode build under Unix.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66103 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
Only comparisons between const_iterator and iterator worked before (because of
implicit conversion from the latter to the former), implement the ones in the
other direction explicitly now.
Closes#12594.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65857 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
These trivial helper functions are available in all builds (provided that
wxUSE_STD_STRING is not explicitly set to non-default 0 value) unlike implicit
conversions to std::[w]string which are only available when wxUSE_STL==1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63938 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
1. changed c_str() to return wxCStrData (implicitly convertible to wxChar*)
2. added template type-safe wrappers for vararg functions
3. added wxUniChar class representing single Unicode character
4. changed wxString::operator[] and wxString::iterator to return wxUniChar
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775