Strings
[Functions and Macros by Category]

wxArrayString wxSplit (const wxString &str, const wxChar sep, const wxChar escape= '\\')
wxString wxJoin (const wxArrayString &arr, const wxChar sep, const wxChar escape= '\\')
bool wxIsEmpty (const char *p)
size_t wxStrlen (const char *p)
int wxStrcmp (const char *p1, const char *p2)
int wxStricmp (const char *p1, const char *p2)
bool wxStringEq (const wxString &s1, const wxString &s2)
bool wxStringMatch (const wxString &s1, const wxString &s2, bool subString=true, bool exact=false)
wxArrayString wxStringTokenize (const wxString &string, const wxString &delims=wxDEFAULT_DELIMITERS, wxStringTokenizerMode mode=wxTOKEN_DEFAULT)
int wxSnprintf (wxChar *buf, size_t len, const wxChar *format,...)
int wxVsnprintf (wxChar *buf, size_t len, const wxChar *format, va_list argPtr)
const wxString wxGetTranslation (const wxString &string, const wxString &domain=wxEmptyString)
const wxString wxGetTranslation (const wxString &string, const wxString &plural, size_t n, const wxString &domain=wxEmptyString)
const wxString _ (const wxString &string)
#define wxPLURAL(string, plural, n)
#define wxTRANSLATE(string)
#define wxT(string)
#define wxS(string)
#define _T(string)

Define Documentation

#define _T ( string   ) 

This macro is exactly the same as wxT() and is defined in wxWidgets simply because it may be more intuitive for Windows programmers as the standard Win32 headers also define it (as well as yet another name for the same macro which is _TEXT()).

Don't confuse this macro with _()!

Include file:

#include <wx/chartype.h> 

#define wxPLURAL ( string,
plural,
 ) 

This macro is identical to _() but for the plural variant of wxGetTranslation().

Returns:
A const wxString.
Include file:
#include <wx/intl.h> 

#define wxS ( string   ) 

wxS is macro which can be used with character and string literals to either convert them to wide characters or strings in wchar_t-based Unicode builds or keep them unchanged in UTF-8 builds. The use of this macro is optional as the translation will always be done at run-time even if there is a mismatch between the kind of the literal used and string or character type used in the current build, but using it can be beneficial in performance-sensitive code to do the conversion at compile-time instead.

See also:
wxT()
Include file:
#include <wx/chartype.h> 

#define wxT ( string   ) 

This macro can be used with character and string literals (in other words, 'x' or "foo") to automatically convert them to Unicode in Unicode builds of wxWidgets. This macro is simply returns the value passed to it without changes in ASCII build. In fact, its definition is:

#ifdef UNICODE
#   define wxT(x) L ## x
#else // !Unicode
#   define wxT(x) x
#endif

See also:
Unicode Support in wxWidgets
Include file:
#include <wx/chartype.h> 

#define wxTRANSLATE ( string   ) 

This macro doesn't do anything in the program code -- it simply expands to the value of its argument.

However it does have a purpose which is to mark the literal strings for the extraction into the message catalog created by xgettext program. Usually this is achieved using _() but that macro not only marks the string for extraction but also expands into a wxGetTranslation() call which means that it cannot be used in some situations, notably for static array initialization.

Here is an example which should make it more clear: suppose that you have a static array of strings containing the weekday names and which have to be translated (note that it is a bad example, really, as wxDateTime already can be used to get the localized week day names already). If you write:

    static const char * const weekdays[] = { _("Mon"), ..., _("Sun") };
    ...
    // use weekdays[n] as usual

The code wouldn't compile because the function calls are forbidden in the array initializer. So instead you should do this:

    static const char * const weekdays[] = { wxTRANSLATE("Mon"), ...,
    wxTRANSLATE("Sun") };
    ...
    // use wxGetTranslation(weekdays[n])

Note that although the code would compile if you simply omit wxTRANSLATE() in the above, it wouldn't work as expected because there would be no translations for the weekday names in the program message catalog and wxGetTranslation() wouldn't find them.

Returns:
A const wxChar*.
Include file:
#include <wx/intl.h> 


Function Documentation

const wxString _ ( const wxString string  ) 

This macro expands into a call to wxGetTranslation(), so it marks the message for the extraction by xgettext just as wxTRANSLATE() does, but also returns the translation of the string for the current locale during execution.

Don't confuse this with _T()!

Include file:

#include <wx/intl.h> 

const wxString wxGetTranslation ( const wxString string,
const wxString plural,
size_t  n,
const wxString domain = wxEmptyString 
)

This is an overloaded version of wxGetTranslation(const wxString&, const wxString&), please see its documentation for general information.

This version is used when retrieving translation of string that has different singular and plural forms in English or different plural forms in some other language. Like wxGetTranslation(const wxString&,const wxString&), the string parameter must contain the singular form of the string to be converted and is used as the key for the search in the catalog. The plural parameter is the plural form (in English). The parameter n is used to determine the plural form. If no message catalog is found, string is returned if "n == 1", otherwise plural is returned.

See GNU gettext Manual for additional information on plural forms handling: <http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms> For a shorter alternative see the wxPLURAL() macro.

This function calls wxLocale::GetString().

Include file:

#include <wx/intl.h> 

const wxString wxGetTranslation ( const wxString string,
const wxString domain = wxEmptyString 
)

This function returns the translation of string in the current locale(). If the string is not found in any of the loaded message catalogs (see Internationalization), the original string is returned. In debug build, an error message is logged -- this should help to find the strings which were not yet translated. If domain is specified then only that domain/catalog is searched for a matching string. As this function is used very often, an alternative (and also common in Unix world) syntax is provided: the _() macro is defined to do the same thing as wxGetTranslation().

This function calls wxLocale::GetString().

Note:
This function is not suitable for literal strings in Unicode builds since the literal strings must be enclosed into _T() or wxT() macro which makes them unrecognised by xgettext, and so they are not extracted to the message catalog. Instead, use the _() and wxPLURAL() macro for all literal strings.
See also:
wxGetTranslation(const wxString&, const wxString&, size_t, const wxString&)
Include file:
#include <wx/intl.h> 

bool wxIsEmpty ( const char *  p  ) 

Returns:
true if the pointer is either NULL or points to an empty string, false otherwise.
Include file:
#include <wx/wxcrt.h> 

wxString wxJoin ( const wxArrayString arr,
const wxChar  sep,
const wxChar  escape = '\\' 
)

Concatenate all lines of the given wxArrayString object using the separator sep and returns the result as a wxString.

If the escape character is non-NULL, then it's used as prefix for each occurrence of sep in the strings contained in arr before joining them which is necessary in order to be able to recover the original array contents from the string later using wxSplit().

See also:
wxSplit()
Include file:
#include <wx/arrstr.h> 

int wxSnprintf ( wxChar *  buf,
size_t  len,
const wxChar *  format,
  ... 
)

This function replaces the dangerous standard function sprintf() and is like snprintf() available on some platforms. The only difference with sprintf() is that an additional argument - buffer size - is taken and the buffer is never overflowed.

Returns the number of characters copied to the buffer or -1 if there is not enough space.

See also:
wxVsnprintf(), wxString::Printf()
Include file:
#include <wx/wxcrt.h> 

wxArrayString wxSplit ( const wxString str,
const wxChar  sep,
const wxChar  escape = '\\' 
)

Splits the given wxString object using the separator sep and returns the result as a wxArrayString.

If the escape character is non-NULL, then the occurrences of sep immediately prefixed with escape are not considered as separators. Note that empty tokens will be generated if there are two or more adjacent separators.

See also:
wxJoin()
Include file:
#include <wx/arrstr.h> 

int wxStrcmp ( const char *  p1,
const char *  p2 
)

This function complements the standard C function stricmp() which performs case-insensitive comparison.

Returns:
A negative value, 0, or positive value if p1 is less than, equal to or greater than p2. The comparison is case-sensitive.
Include file:
#include <wx/wxcrt.h> 

int wxStricmp ( const char *  p1,
const char *  p2 
)

This function complements the standard C function strcmp() which performs case-sensitive comparison.

Returns:
A negative value, 0, or positive value if p1 is less than, equal to or greater than p2. The comparison is case-insensitive.
Include file:
#include <wx/wxcrt.h> 

bool wxStringEq ( const wxString s1,
const wxString s2 
)

Deprecated:
Use wxString instead.
This macro is defined as:

    #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))

Include file:

#include <wx/wxcrt.h> 

bool wxStringMatch ( const wxString s1,
const wxString s2,
bool  subString = true,
bool  exact = false 
)

Deprecated:
Use wxString::Find() instead.
Returns true if the substring s1 is found within s2, ignoring case if exact is false. If subString is false, no substring matching is done.

Include file:

#include <wx/wxcrt.h> 

wxArrayString wxStringTokenize ( const wxString string,
const wxString delims = wxDEFAULT_DELIMITERS,
wxStringTokenizerMode  mode = wxTOKEN_DEFAULT 
)

This is a convenience function wrapping wxStringTokenizer which simply returns all tokens found in the given string in an array.

Please see wxStringTokenizer::wxStringTokenizer() for a description of the other parameters.

Include file:

#include <wx/wxcrt.h> 

size_t wxStrlen ( const char *  p  ) 

This is a safe version of standard function strlen(): it does exactly the same thing (i.e. returns the length of the string) except that it returns 0 if p is the NULL pointer.

Include file:

#include <wx/wxcrt.h> 

int wxVsnprintf ( wxChar *  buf,
size_t  len,
const wxChar *  format,
va_list  argPtr 
)

The same as wxSnprintf() but takes a va_list argument instead of an arbitrary number of parameters.

Note:
If wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports positional arguments (see wxString::Printf() for more information). However other functions of the same family (wxPrintf(), wxSprintf(), wxFprintf(), wxVfprintf(), wxVfprintf(), wxVprintf(), wxVsprintf()) currently do not to support positional parameters even when wxUSE_PRINTF_POS_PARAMS is 1.
See also:
wxSnprintf(), wxString::PrintfV()
Include file:
#include <wx/wxcrt.h> 



wxWidgets logo

[ top ]