]> git.saurik.com Git - wxWidgets.git/blobdiff - interface/wx/string.h
use UnsetToolTip() instead of SetToolTip(NULL) to fix wxX11 build broken on Buildbot...
[wxWidgets.git] / interface / wx / string.h
index 844fe0ea9ad4e17e5c8352b3d1b5da92fe12c04b..204cd4ec953bddf706e498414cc44be1af42836d 100644 (file)
     @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}
@@ -75,15 +75,18 @@ public:
     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.
+
     Since iterating over a wxString by index can become inefficient in UTF-8
     Since iterating over a wxString by index can become inefficient in UTF-8
-    mode and iterators should be used instead of index based access:
+    mode iterators should be used instead of index based access:
 
     @code
     wxString s = "hello";
 
     @code
     wxString s = "hello";
@@ -120,6 +123,8 @@ public:
     append something to a C string (including literal constants), so to do this it
     should be converted to a wxString first.
 
     append something to a C string (including literal constants), so to do this it
     should be converted to a wxString first.
 
+        @li insert()
+        @li append()
         @li operator<<()
         @li operator+=()
         @li operator+()
         @li operator<<()
         @li operator+=()
         @li operator+()
@@ -134,6 +139,7 @@ public:
         @li wxString()
         @li operator=()
         @li ~wxString()
         @li wxString()
         @li operator=()
         @li ~wxString()
+        @li assign()
 
         The MakeXXX() variants modify the string in place, while the other functions
         return a new string which contains the original text converted to the upper or
 
         The MakeXXX() variants modify the string in place, while the other functions
         return a new string which contains the original text converted to the upper or
@@ -143,6 +149,8 @@ public:
         @li Upper()
         @li MakeLower()
         @li Lower()
         @li Upper()
         @li MakeLower()
         @li Lower()
+        @li MakeCapitalized()
+        @li Capitalize()
 
         Many functions below take a character index in the string. As with C
         strings and arrays, the indices start from 0, so the first character of a
 
         Many functions below take a character index in the string. As with C
         strings and arrays, the indices start from 0, so the first character of a
@@ -151,7 +159,7 @@ public:
         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()
@@ -166,10 +174,9 @@ public:
         @li mb_str()
         @li fn_str()
 
         @li mb_str()
         @li fn_str()
 
-        The default comparison function Cmp() is case-sensitive and
-        so is the default version of IsSameAs(). For case
-        insensitive comparisons you should use CmpNoCase() or
-        give a second parameter to IsSameAs. This last function is may be more
+        The default comparison function Cmp() is case-sensitive and so is the default
+        version of IsSameAs(). For case insensitive comparisons you should use CmpNoCase()
+        or give a second parameter to IsSameAs(). This last function is maybe more
         convenient if only equality of the strings matters because it returns a boolean
         @true value if the strings are the same and not 0 (which is usually @false
         in C) as Cmp() does.
         convenient if only equality of the strings matters because it returns a boolean
         @true value if the strings are the same and not 0 (which is usually @false
         in C) as Cmp() does.
@@ -179,6 +186,7 @@ public:
         with some predefined prefix and is more efficient than doing direct string
         comparison as you would also have to precalculate the length of the prefix.
 
         with some predefined prefix and is more efficient than doing direct string
         comparison as you would also have to precalculate the length of the prefix.
 
+        @li compare()
         @li Cmp()
         @li CmpNoCase()
         @li IsSameAs()
         @li Cmp()
         @li CmpNoCase()
         @li IsSameAs()
@@ -203,6 +211,8 @@ public:
         when working with some external API which requires the caller to provide
         a writable buffer.
 
         when working with some external API which requires the caller to provide
         a writable buffer.
 
+        @li reserve()
+        @li resize()
         @li Alloc()
         @li Shrink()
         @li wxStringBuffer
         @li Alloc()
         @li Shrink()
         @li wxStringBuffer
@@ -217,16 +227,19 @@ public:
         These functions return the string length and check whether the string
         is empty or they empty it.
 
         These functions return the string length and check whether the string
         is empty or they empty it.
 
+        @li length()
+        @li size()
         @li Len()
         @li IsEmpty()
         @li operator!()
         @li Empty()
         @li Clear()
 
         @li Len()
         @li IsEmpty()
         @li operator!()
         @li Empty()
         @li Clear()
 
-        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.
 
+        @li substr()
         @li Mid()
         @li operator()()
         @li Left()
         @li Mid()
         @li operator()()
         @li Left()
@@ -241,6 +254,9 @@ public:
         These functions replace the standard @e strchr() and @e strstr()
         functions.
 
         These functions replace the standard @e strchr() and @e strstr()
         functions.
 
+        @li find()
+        @li rfind()
+        @li replace()
         @li Find()
         @li Replace()
 
         @li Find()
         @li Replace()
 
@@ -268,7 +284,7 @@ public:
     ::Objects, ::wxEmptyString,
 
     @see @ref overview_string "wxString overview", @ref overview_unicode
     ::Objects, ::wxEmptyString,
 
     @see @ref overview_string "wxString overview", @ref overview_unicode
-    "Unicode overview"
+    "Unicode overview", wxUString
 */
 class wxString
 {
 */
 class wxString
 {
@@ -460,6 +476,16 @@ public:
     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()
@@ -623,14 +649,39 @@ public:
     //@{
     /**
         Converts C string encoded in UTF-8 to wxString.
     //@{
     /**
         Converts C string encoded in UTF-8 to wxString.
-        Note that this method assumes that @a s is a valid UTF-8 sequence and
-        doesn't do any validation in release builds, it's validity is only checked in
-        debug builds.
+
+        If @a s is not a valid UTF-8 string, an empty string is returned.
+
+        Notice that when using UTF-8 wxWidgets build there is a more efficient
+        alternative to this function called FromUTF8Unchecked() which, unlike
+        this one, doesn't check that the input string is valid.
+
+        @since 2.8.4
     */
     static wxString FromUTF8(const char* s);
     static wxString FromUTF8(const char* s, size_t len);
     //@}
 
     */
     static wxString FromUTF8(const char* s);
     static wxString FromUTF8(const char* s, size_t len);
     //@}
 
+    //@{
+    /**
+        Converts C string encoded in UTF-8 to wxString without checking its
+        validity.
+
+        This method assumes that @a s is a valid UTF-8 sequence and doesn't do
+        any validation (although an assert failure is triggered in debug builds
+        if the string is invalid). Only use it if you are absolutely sure that
+        @a s is a correct UTF-8 string (e.g. because it comes from another
+        library using UTF-8) and if the performance matters, otherwise use
+        slower (in UTF-8 build) but safer FromUTF8(). Passing a bad UTF-8
+        string to this function will result in creating a corrupted wxString
+        and all the subsequent operations on it will be undefined.
+
+        @since 2.8.9
+    */
+    static wxString FromUTF8Unchecked(const char* s);
+    static wxString FromUTF8Unchecked(const char* s, size_t len);
+    //@}
+
     /**
         Returns the character at position @a n (read-only).
     */
     /**
         Returns the character at position @a n (read-only).
     */
@@ -731,6 +782,8 @@ public:
 
     /**
         Returns this string converted to the lower case.
 
     /**
         Returns this string converted to the lower case.
+
+        @see MakeLower()
     */
     wxString Lower() const;
 
     */
     wxString Lower() const;
 
@@ -741,13 +794,27 @@ public:
     */
     void LowerCase();
 
     */
     void LowerCase();
 
+    /**
+        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.
+
+        @see Lower()
     */
     wxString& MakeLower();
 
     /**
         Converts all characters to upper case and returns the result.
     */
     wxString& MakeLower();
 
     /**
         Converts all characters to upper case and returns the result.
+
+        @see Upper()
     */
     wxString& MakeUpper();
 
     */
     wxString& MakeUpper();
 
@@ -990,6 +1057,8 @@ public:
 
     /**
         Returns this string converted to upper case.
 
     /**
         Returns this string converted to upper case.
+
+        @see MakeUpper()
     */
     wxString Upper() const;
 
     */
     wxString Upper() const;
 
@@ -1005,14 +1074,14 @@ public:
         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;
@@ -1063,8 +1132,8 @@ public:
 
     /**
         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;
@@ -1152,7 +1221,7 @@ public:
         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;
@@ -1162,7 +1231,7 @@ public:
     //@{
     /**
         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).
 
@@ -1186,7 +1255,7 @@ public:
     */
     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).
     */
@@ -1345,10 +1414,10 @@ wxString wxEmptyString;
     @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.