git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54915
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- Fix reading/writing UTF-7-encoded text streams.
- Corrected bug in wxTimeSpan::IsShorterThan() for equal time spans.
- Use std::unordered_{map,set} for wxHashMap/Set if available (Jan van Dijk).
- Fix reading/writing UTF-7-encoded text streams.
- Corrected bug in wxTimeSpan::IsShorterThan() for equal time spans.
- Use std::unordered_{map,set} for wxHashMap/Set if available (Jan van Dijk).
+- Added wxString::Capitalize() and MakeCapitalized().
// convert to upper case in place, return the string itself
wxString& MakeUpper();
// convert to upper case, return the copy of the string
// convert to upper case in place, return the string itself
wxString& MakeUpper();
// convert to upper case, return the copy of the string
- // Here's something to remember: BC++ doesn't like returns in inlines.
- wxString Upper() const ;
+ wxString Upper() const { return wxString(*this).MakeUpper(); }
// convert to lower case in place, return the string itself
wxString& MakeLower();
// convert to lower case, return the copy of the string
// convert to lower case in place, return the string itself
wxString& MakeLower();
// convert to lower case, return the copy of the string
- wxString Lower() const ;
+ wxString Lower() const { return wxString(*this).MakeLower(); }
+ // convert the first character to the upper case and the rest to the
+ // lower one, return the modified string itself
+ wxString& MakeCapitalized();
+ // convert the first character to the upper case and the rest to the
+ // lower one, return the copy of the string
+ wxString Capitalize() const { return wxString(*this).MakeCapitalized(); }
// trimming/padding whitespace (either side) and truncating
// remove spaces from left or from right (default) side
// trimming/padding whitespace (either side) and truncating
// remove spaces from left or from right (default) side
@endcode
Note that the exact usage of this depends on whether or not wxUSE_STL is
@endcode
Note that the exact usage of this depends on whether or not wxUSE_STL is
- enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty
+ enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty
character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from
character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from
- wxString, keeping the same buffer wxString uses intact. In other words,
- relying on wxStringBuffer containing the old wxString data is not a good
+ wxString, keeping the same buffer wxString uses intact. In other words,
+ relying on wxStringBuffer containing the old wxString data is not a good
idea if you want to build your program both with and without wxUSE_STL.
@library{wxbase}
idea if you want to build your program both with and without wxUSE_STL.
@library{wxbase}
internally even if wxUSE_STL is not defined.
Since wxWidgets 3.0 wxString internally uses UCS-2 (basically 2-byte per
internally even if wxUSE_STL is not defined.
Since wxWidgets 3.0 wxString internally uses UCS-2 (basically 2-byte per
- character wchar_t and nearly the same as UTF-16) under Windows and
- UTF-8 under Unix, Linux and OS X to store its content.
+ character wchar_t and nearly the same as UTF-16) under Windows and
+ UTF-8 under Unix, Linux and OS X to store its content.
Much work has been done to make existing code using ANSI string literals
work as before. If you need to have a wxString that uses wchar_t on Unix
and Linux, too, you can specify this on the command line with the
@c configure @c --disable-utf8 switch.
Much work has been done to make existing code using ANSI string literals
work as before. If you need to have a wxString that uses wchar_t on Unix
and Linux, too, you can specify this on the command line with the
@c configure @c --disable-utf8 switch.
If you need a Unicode string class with O(1) access on all platforms
you should consider using wxUString.
If you need a Unicode string class with O(1) access on all platforms
you should consider using wxUString.
Since iterating over a wxString by index can become inefficient in UTF-8
mode iterators should be used instead of index based access:
Since iterating over a wxString by index can become inefficient in UTF-8
mode iterators should be used instead of index based access:
failure in @ref overview_debugging "debug build", but no checks are
done in release builds.
This section also contains both implicit and explicit conversions to C style
failure in @ref overview_debugging "debug build", but no checks are
done in release builds.
This section also contains both implicit and explicit conversions to C style
- strings. Although implicit conversion is quite convenient, you are advised
+ strings. Although implicit conversion is quite convenient, you are advised
to use wc_str() for the sake of clarity.
@li GetChar()
to use wc_str() for the sake of clarity.
@li GetChar()
- These functions allow you to extract a substring from the string. The
+ These functions allow you to extract a substring from the string. The
original string is not modified and the function returns the extracted
substring.
original string is not modified and the function returns the extracted
substring.
wxString BeforeLast(wxUniChar ch) const;
wxString BeforeLast(wxUniChar ch) const;
+ /**
+ Return the copy of the string with the first string character in the
+ upper case and the subsequent ones in the lower case.
+
+ @since 2.9.0
+
+ @see MakeCapitalized()
+ */
+ wxString Capitalize() const;
+
/**
Empties the string and frees memory occupied by it.
See also: Empty()
/**
Empties the string and frees memory occupied by it.
See also: Empty()
/**
Returns this string converted to the lower case.
/**
Returns this string converted to the lower case.
*/
wxString Lower() const;
*/
wxString Lower() const;
+ /**
+ Converts the first characters of the string to the upper case and all
+ the subsequent ones to the lower case and returns the result.
+
+ @since 2.9.0
+
+ @see Capitalize()
+ */
+ wxString& MakeCapitalized();
+
/**
Converts all characters to lower case and returns the result.
/**
Converts all characters to lower case and returns the result.
*/
wxString& MakeLower();
/**
Converts all characters to upper case and returns the result.
*/
wxString& MakeLower();
/**
Converts all characters to upper case and returns the result.
*/
wxString& MakeUpper();
*/
wxString& MakeUpper();
/**
Returns this string converted to upper case.
/**
Returns this string converted to upper case.
*/
wxString Upper() const;
*/
wxString Upper() const;
convertible to both @c const @c char* and to @c const @c wchar_t*.
Given this ambiguity it is mostly better to use wc_str(), mb_str() or
utf8_str() instead.
convertible to both @c const @c char* and to @c const @c wchar_t*.
Given this ambiguity it is mostly better to use wc_str(), mb_str() or
utf8_str() instead.
Please see the @ref overview_unicode "Unicode overview" for more
information about it.
Please see the @ref overview_unicode "Unicode overview" for more
information about it.
Note that the returned value is not convertible to @c char* or
@c wchar_t*, use char_str() or wchar_str() if you need to pass
string value to a function expecting non-const pointer.
Note that the returned value is not convertible to @c char* or
@c wchar_t*, use char_str() or wchar_str() if you need to pass
string value to a function expecting non-const pointer.
@see wc_str(), utf8_str(), c_str(), mb_str(), fn_str()
*/
const wxCStrData c_str() const;
@see wc_str(), utf8_str(), c_str(), mb_str(), fn_str()
*/
const wxCStrData c_str() const;
/**
Returns the multibyte (C string) representation of the string
/**
Returns the multibyte (C string) representation of the string
- using @e conv's wxMBConv::cWC2MB method and returns wxCharBuffer.
-
+ using @e conv's wxMBConv::cWC2MB method and returns wxCharBuffer.
+
@see wc_str(), utf8_str(), c_str(), wxMBConv
*/
const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
@see wc_str(), utf8_str(), c_str(), wxMBConv
*/
const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
Converts the strings contents to UTF-8 and returns it either as a
temporary wxCharBuffer object or as a pointer to the internal
string contents in UTF-8 build.
Converts the strings contents to UTF-8 and returns it either as a
temporary wxCharBuffer object or as a pointer to the internal
string contents in UTF-8 build.
@see wc_str(), c_str(), mb_str()
*/
const char* utf8_str() const;
@see wc_str(), c_str(), mb_str()
*/
const char* utf8_str() const;
//@{
/**
Converts the strings contents to the wide character represention
//@{
/**
Converts the strings contents to the wide character represention
- and returns it as a temporary wxWCharBuffer object (Unix and OS X)
+ and returns it as a temporary wxWCharBuffer object (Unix and OS X)
or returns a pointer to the internal string contents in wide character
mode (Windows).
or returns a pointer to the internal string contents in wide character
mode (Windows).
*/
wxWritableWCharBuffer wchar_str() const;
*/
wxWritableWCharBuffer wchar_str() const;
Explicit conversion to C string in the internal representation (either
wchar_t* or UTF-8-encoded char*, depending on the build).
*/
Explicit conversion to C string in the internal representation (either
wchar_t* or UTF-8-encoded char*, depending on the build).
*/
@endcode
Note that the exact usage of this depends on whether or not wxUSE_STL is
@endcode
Note that the exact usage of this depends on whether or not wxUSE_STL is
- enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty
+ enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty
character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from
character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from
- wxString, keeping the same buffer wxString uses intact. In other words,
- relying on wxStringBuffer containing the old wxString data is not a good
+ wxString, keeping the same buffer wxString uses intact. In other words,
+ relying on wxStringBuffer containing the old wxString data is not a good
idea if you want to build your program both with and without wxUSE_STL.
Note that SetLength @c must be called before wxStringBufferLength destructs.
idea if you want to build your program both with and without wxUSE_STL.
Note that SetLength @c must be called before wxStringBufferLength destructs.
+wxString& wxString::MakeCapitalized()
+{
+ const iterator en = end();
+ iterator it = begin();
+ if ( it != en )
+ {
+ *it = (wxChar)wxToupper(*it);
+ for ( ++it; it != en; ++it )
+ *it = (wxChar)wxTolower(*it);
+ }
+
+ return *this;
+}
+
// ---------------------------------------------------------------------------
// trimming and padding
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// trimming and padding
// ---------------------------------------------------------------------------
-// convert to upper case, return the copy of the string
-wxString wxString::Upper() const
-{ wxString s(*this); return s.MakeUpper(); }
-
-// convert to lower case, return the copy of the string
-wxString wxString::Lower() const { wxString s(*this); return s.MakeLower(); }
-
// ----------------------------------------------------------------------------
// wxUTF8StringBuffer
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxUTF8StringBuffer
// ----------------------------------------------------------------------------
wxString s1l(s1);
s1u.MakeUpper();
s1l.MakeLower();
wxString s1l(s1);
s1u.MakeUpper();
s1l.MakeLower();
+
+ CPPUNIT_ASSERT_EQUAL( _T("HELLO!"), s1u );
+ CPPUNIT_ASSERT_EQUAL( _T("hello!"), s1l );
+
wxString s2u, s2l;
s2u.MakeUpper();
s2l.MakeLower();
wxString s2u, s2l;
s2u.MakeUpper();
s2l.MakeLower();
- CPPUNIT_ASSERT( s1u == _T("HELLO!") );
- CPPUNIT_ASSERT( s1l == _T("hello!") );
- CPPUNIT_ASSERT( s2u == wxEmptyString );
- CPPUNIT_ASSERT( s2l == wxEmptyString );
+ CPPUNIT_ASSERT_EQUAL( "", s2u );
+ CPPUNIT_ASSERT_EQUAL( "", s2l );
+
+
+ wxString s3("good bye");
+ CPPUNIT_ASSERT_EQUAL( "Good bye", s3.Capitalize() );
+ s3.MakeCapitalized();
+ CPPUNIT_ASSERT_EQUAL( "Good bye", s3 );
+
+ CPPUNIT_ASSERT_EQUAL( "Abc", wxString("ABC").Capitalize() );
+
+ CPPUNIT_ASSERT_EQUAL( "", wxString().Capitalize() );
}
void StringTestCase::Compare()
}
void StringTestCase::Compare()