1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of global CRT wrapper functions
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 /** @addtogroup group_funcmacro_string */
13 Returns @true if the pointer @a p is either @NULL or points to an empty string,
18 bool wxIsEmpty(const char* p
);
21 This is a safe version of standard function @e strlen(): it does exactly
22 the same thing (i.e. returns the length of the string) except that it
23 returns 0 if @a p is the @NULL pointer.
27 size_t wxStrlen(const char* p
);
30 This is a safe version of standard function @e strlen(): it returns the length
31 of the string s in bytes if this length is smaller than @a maxlen bytes.
32 Otherwise it returns @a maxlen.
34 The @a maxlen parameter makes it easier to avoid array indexing errors
35 since you are sure that wxStrnlen() won't read any memory exceeding the
36 @c "*(p+maxlen)" location.
42 size_t wxStrnlen(const char* p
, size_t maxlen
);
45 This function complements the standard C function @e stricmp() which
46 performs case-insensitive comparison.
48 @return A negative value, 0, or positive value if @a p1 is less than,
49 equal to or greater than @a p2. The comparison is case-sensitive.
53 int wxStrcmp(const char* p1
, const char* p2
);
56 This function complements the standard C function @e strcmp() which performs
57 case-sensitive comparison.
59 @return A negative value, 0, or positive value if @a p1 is less than,
60 equal to or greater than @e p2. The comparison is case-insensitive.
64 int wxStricmp(const char* p1
, const char* p2
);
67 @deprecated Use wxString::operator== instead.
69 This macro is defined as:
72 #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
77 bool wxStringEq(const wxString
& s1
, const wxString
& s2
);
80 @deprecated Use wxString::Find() instead.
82 Returns @true if the substring @a s1 is found within @a s2, ignoring case
83 if @a exact is @false. If @a subString is @false, no substring matching is
88 bool wxStringMatch(const wxString
& s1
, const wxString
& s2
,
89 bool subString
= true, bool exact
= false);
92 This is a convenience function wrapping wxStringTokenizer which simply
93 returns all tokens found in the given @a string in an array.
95 Please see wxStringTokenizer::wxStringTokenizer() for a description of the
100 wxArrayString
wxStringTokenize(const wxString
& string
,
101 const wxString
& delims
= wxDEFAULT_DELIMITERS
,
102 wxStringTokenizerMode mode
= wxTOKEN_DEFAULT
);
105 Safe and more convenient replacement for strncpy().
107 This function copies the source string @a src to the destination buffer @a
108 dst of size @a n without overflowing the buffer and ensuring that it is
109 always @NUL-terminated.
114 if ( wxStrlcpy(buf, GetSomeString(), WXSIZEOF(buf)) > WXSIZEOF(buf) )
115 ... handle truncation ...
117 Notice that using wxStrncpy() in similar way is wrong, the above is broadly
121 buf[WXSIZEOF(buf) - 1] = '\0';
122 wxStrncpy(buf, GetSomeString(), WXSIZEOF(buf) - 1);
123 if ( buf[WXSIZEOF(buf) - 1] != '\0' )
125 ... truncation occurred ...
126 // need to NUL-terminate string manually
127 buf[WXSIZEOF(buf) - 1] = '\0';
130 which should explain the advantage of using wxStrlcpy().
132 Notice that this function is similar to the OpenBSD strlcpy() function.
135 Destination buffer of size (greater or) equal to @a n.
137 @NUL-terminated source string.
139 The size of the destination buffer.
141 The length of @a src, if the returned value is greater or equal to @a n
142 then there was not enough space in the destination buffer and the
143 string was truncated.
149 size_t wxStrlcpy(char *dst
, const char *src
, size_t n
);
152 This function replaces the dangerous standard function @e sprintf() and is
153 like @e snprintf() available on some platforms. The only difference with
154 @e sprintf() is that an additional argument - buffer size - is taken and
155 the buffer is never overflowed.
157 Returns the number of characters copied to the buffer or -1 if there is not
160 @see wxVsnprintf(), wxString::Printf()
164 int wxSnprintf(char* buf
, size_t len
, const char* format
, ...);
167 The same as wxSnprintf() but takes a @c va_list argument instead of an
168 arbitrary number of parameters.
170 @note If @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function
171 supports positional arguments (see wxString::Printf() for more
172 information). However other functions of the same family (wxPrintf(),
173 wxSprintf(), wxFprintf(), wxVfprintf(), wxVfprintf(), wxVprintf(),
174 wxVsprintf()) currently do not to support positional parameters even
175 when @c wxUSE_PRINTF_POS_PARAMS is 1.
177 @see wxSnprintf(), wxString::PrintfV()
181 int wxVsnprintf(char* buf
, size_t len
, const char* format
, va_list argPtr
);