2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-03-08 14:43:31 +00:00
|
|
|
// Name: wxcrt.h
|
2009-01-31 13:58:45 +00:00
|
|
|
// Purpose: interface of global CRT wrapper functions
|
2008-03-08 14:43:31 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-05 20:48:06 +00:00
|
|
|
/** @addtogroup group_funcmacro_string */
|
2008-03-25 07:36:12 +00:00
|
|
|
//@{
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
/**
|
2009-01-31 13:58:45 +00:00
|
|
|
Returns @true if the pointer @a p is either @NULL or points to an empty string,
|
|
|
|
@false otherwise.
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-03-25 07:36:12 +00:00
|
|
|
@header{wx/wxcrt.h}
|
|
|
|
*/
|
|
|
|
bool wxIsEmpty(const char* p);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
This is a safe version of standard function @e strlen(): it does exactly
|
|
|
|
the same thing (i.e. returns the length of the string) except that it
|
|
|
|
returns 0 if @a p is the @NULL pointer.
|
2008-03-09 12:33:59 +00:00
|
|
|
|
2008-03-25 07:36:12 +00:00
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
size_t wxStrlen(const char* p);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2009-01-31 13:58:45 +00:00
|
|
|
/**
|
|
|
|
This is a safe version of standard function @e strlen(): it returns the length
|
|
|
|
of the string s in bytes if this length is smaller than @a maxlen bytes.
|
|
|
|
Otherwise it returns @a maxlen.
|
|
|
|
|
|
|
|
The @a maxlen parameter makes it easier to avoid array indexing errors
|
|
|
|
since you are sure that wxStrnlen() won't read any memory exceeding the
|
|
|
|
@c "*(p+maxlen)" location.
|
|
|
|
|
|
|
|
@since 2.9.0
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
|
|
|
*/
|
|
|
|
size_t wxStrnlen(const char* p, size_t maxlen);
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
This function complements the standard C function @e stricmp() which
|
|
|
|
performs case-insensitive comparison.
|
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return A negative value, 0, or positive value if @a p1 is less than,
|
2009-01-31 13:58:45 +00:00
|
|
|
equal to or greater than @a p2. The comparison is case-sensitive.
|
2008-03-25 07:36:12 +00:00
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
int wxStrcmp(const char* p1, const char* p2);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
This function complements the standard C function @e strcmp() which performs
|
|
|
|
case-sensitive comparison.
|
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return A negative value, 0, or positive value if @a p1 is less than,
|
2009-01-31 13:58:45 +00:00
|
|
|
equal to or greater than @e p2. The comparison is case-insensitive.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-25 07:36:12 +00:00
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
int wxStricmp(const char* p1, const char* p2);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2009-01-31 13:58:45 +00:00
|
|
|
@deprecated Use wxString::operator== instead.
|
2008-03-25 07:36:12 +00:00
|
|
|
|
|
|
|
This macro is defined as:
|
|
|
|
|
|
|
|
@code
|
|
|
|
#define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
bool wxStringEq(const wxString& s1, const wxString& s2);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
@deprecated Use wxString::Find() instead.
|
|
|
|
|
|
|
|
Returns @true if the substring @a s1 is found within @a s2, ignoring case
|
|
|
|
if @a exact is @false. If @a subString is @false, no substring matching is
|
|
|
|
done.
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
bool wxStringMatch(const wxString& s1, const wxString& s2,
|
|
|
|
bool subString = true, bool exact = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
This is a convenience function wrapping wxStringTokenizer which simply
|
|
|
|
returns all tokens found in the given @a string in an array.
|
|
|
|
|
|
|
|
Please see wxStringTokenizer::wxStringTokenizer() for a description of the
|
|
|
|
other parameters.
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-25 07:36:12 +00:00
|
|
|
wxArrayString wxStringTokenize(const wxString& string,
|
|
|
|
const wxString& delims = wxDEFAULT_DELIMITERS,
|
|
|
|
wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-11-29 14:41:02 +00:00
|
|
|
/**
|
|
|
|
Safe and more convenient replacement for strncpy().
|
|
|
|
|
|
|
|
This function copies the source string @a src to the destination buffer @a
|
|
|
|
dst of size @a n without overflowing the buffer and ensuring that it is
|
2009-01-06 16:17:50 +00:00
|
|
|
always @NUL-terminated.
|
2008-11-29 14:41:02 +00:00
|
|
|
|
|
|
|
Example of use:
|
|
|
|
@code
|
|
|
|
char buf[256];
|
|
|
|
if ( wxStrlcpy(buf, GetSomeString(), WXSIZEOF(buf)) > WXSIZEOF(buf) )
|
|
|
|
... handle truncation ...
|
|
|
|
@endcode
|
|
|
|
Notice that using wxStrncpy() in similar way is wrong, the above is broadly
|
|
|
|
equivalent to
|
|
|
|
@code
|
|
|
|
char buf[256];
|
|
|
|
buf[WXSIZEOF(buf) - 1] = '\0';
|
|
|
|
wxStrncpy(buf, GetSomeString(), WXSIZEOF(buf) - 1);
|
|
|
|
if ( buf[WXSIZEOF(buf) - 1] != '\0' )
|
|
|
|
{
|
|
|
|
... truncation occurred ...
|
|
|
|
// need to NUL-terminate string manually
|
|
|
|
buf[WXSIZEOF(buf) - 1] = '\0';
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
which should explain the advantage of using wxStrlcpy().
|
|
|
|
|
|
|
|
Notice that this function is similar to the OpenBSD strlcpy() function.
|
|
|
|
|
|
|
|
@param dst
|
|
|
|
Destination buffer of size (greater or) equal to @a n.
|
|
|
|
@param src
|
2009-01-06 16:17:50 +00:00
|
|
|
@NUL-terminated source string.
|
2008-11-29 14:41:02 +00:00
|
|
|
@param n
|
|
|
|
The size of the destination buffer.
|
|
|
|
@return
|
|
|
|
The length of @a src, if the returned value is greater or equal to @a n
|
|
|
|
then there was not enough space in the destination buffer and the
|
|
|
|
string was truncated.
|
|
|
|
|
2009-01-31 13:58:45 +00:00
|
|
|
@since 2.9.0
|
2008-11-29 14:41:02 +00:00
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
|
|
|
*/
|
2009-01-31 13:58:45 +00:00
|
|
|
size_t wxStrlcpy(char *dst, const char *src, size_t n);
|
2008-11-29 14:41:02 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
This function replaces the dangerous standard function @e sprintf() and is
|
|
|
|
like @e snprintf() available on some platforms. The only difference with
|
|
|
|
@e 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 wxVsnprintf(), wxString::Printf()
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-31 13:58:45 +00:00
|
|
|
int wxSnprintf(char* buf, size_t len, const char* format, ...);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-25 07:36:12 +00:00
|
|
|
The same as wxSnprintf() but takes a @c va_list argument instead of an
|
|
|
|
arbitrary number of parameters.
|
|
|
|
|
|
|
|
@note If @c 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 @c wxUSE_PRINTF_POS_PARAMS is 1.
|
|
|
|
|
|
|
|
@see wxSnprintf(), wxString::PrintfV()
|
|
|
|
|
|
|
|
@header{wx/wxcrt.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-31 13:58:45 +00:00
|
|
|
int wxVsnprintf(char* buf, size_t len, const char* format, va_list argPtr);
|
2008-03-25 07:36:12 +00:00
|
|
|
|
|
|
|
//@}
|
2008-03-08 13:52:38 +00:00
|
|
|
|