]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/wxcrt.h
MYcopystring is not required anymore when compat2.8 is off
[wxWidgets.git] / interface / wx / wxcrt.h
CommitLineData
23324ae1 1/////////////////////////////////////////////////////////////////////////////
7c913512 2// Name: wxcrt.h
e54c96f1 3// Purpose: interface of global functions
7c913512
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
b21126db 9/** @addtogroup group_funcmacro_string */
3950d49c
BP
10//@{
11
7c913512 12/**
d29a9a8a 13 @return @true if the pointer is either @NULL or points to an empty string,
3950d49c 14 @false otherwise.
23324ae1 15
3950d49c
BP
16 @header{wx/wxcrt.h}
17*/
18bool wxIsEmpty(const char* p);
23324ae1 19
7c913512 20/**
3950d49c
BP
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.
4cc4bfaf 24
3950d49c 25 @header{wx/wxcrt.h}
23324ae1 26*/
3950d49c 27size_t wxStrlen(const char* p);
23324ae1
FM
28
29/**
3950d49c
BP
30 This function complements the standard C function @e stricmp() which
31 performs case-insensitive comparison.
32
d29a9a8a 33 @return A negative value, 0, or positive value if @a p1 is less than,
3950d49c
BP
34 equal to or greater than @a p2. The comparison is case-sensitive.
35
36 @header{wx/wxcrt.h}
23324ae1 37*/
3950d49c 38int wxStrcmp(const char* p1, const char* p2);
23324ae1
FM
39
40/**
3950d49c
BP
41 This function complements the standard C function @e strcmp() which performs
42 case-sensitive comparison.
43
d29a9a8a 44 @return A negative value, 0, or positive value if @a p1 is less than,
3950d49c 45 equal to or greater than @e p2. The comparison is case-insensitive.
7c913512 46
3950d49c 47 @header{wx/wxcrt.h}
23324ae1 48*/
3950d49c 49int wxStricmp(const char* p1, const char* p2);
23324ae1
FM
50
51/**
3950d49c
BP
52 @deprecated Use wxString instead.
53
54 This macro is defined as:
55
56 @code
57 #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
58 @endcode
59
60 @header{wx/wxcrt.h}
23324ae1 61*/
3950d49c 62bool wxStringEq(const wxString& s1, const wxString& s2);
23324ae1
FM
63
64/**
3950d49c
BP
65 @deprecated Use wxString::Find() instead.
66
67 Returns @true if the substring @a s1 is found within @a s2, ignoring case
68 if @a exact is @false. If @a subString is @false, no substring matching is
69 done.
70
71 @header{wx/wxcrt.h}
23324ae1 72*/
3950d49c
BP
73bool wxStringMatch(const wxString& s1, const wxString& s2,
74 bool subString = true, bool exact = false);
23324ae1
FM
75
76/**
3950d49c
BP
77 This is a convenience function wrapping wxStringTokenizer which simply
78 returns all tokens found in the given @a string in an array.
79
80 Please see wxStringTokenizer::wxStringTokenizer() for a description of the
81 other parameters.
82
83 @header{wx/wxcrt.h}
23324ae1 84*/
3950d49c
BP
85wxArrayString wxStringTokenize(const wxString& string,
86 const wxString& delims = wxDEFAULT_DELIMITERS,
87 wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
23324ae1 88
e408bf52
VZ
89/**
90 Safe and more convenient replacement for strncpy().
91
92 This function copies the source string @a src to the destination buffer @a
93 dst of size @a n without overflowing the buffer and ensuring that it is
8d740f72 94 always @NUL-terminated.
e408bf52
VZ
95
96 Example of use:
97 @code
98 char buf[256];
99 if ( wxStrlcpy(buf, GetSomeString(), WXSIZEOF(buf)) > WXSIZEOF(buf) )
100 ... handle truncation ...
101 @endcode
102 Notice that using wxStrncpy() in similar way is wrong, the above is broadly
103 equivalent to
104 @code
105 char buf[256];
106 buf[WXSIZEOF(buf) - 1] = '\0';
107 wxStrncpy(buf, GetSomeString(), WXSIZEOF(buf) - 1);
108 if ( buf[WXSIZEOF(buf) - 1] != '\0' )
109 {
110 ... truncation occurred ...
111 // need to NUL-terminate string manually
112 buf[WXSIZEOF(buf) - 1] = '\0';
113 }
114 @endcode
115 which should explain the advantage of using wxStrlcpy().
116
117 Notice that this function is similar to the OpenBSD strlcpy() function.
118
119 The template parameter @a T can be either @c char or @c wchar_t.
120
121 @param dst
122 Destination buffer of size (greater or) equal to @a n.
123 @param src
8d740f72 124 @NUL-terminated source string.
e408bf52
VZ
125 @param n
126 The size of the destination buffer.
127 @return
128 The length of @a src, if the returned value is greater or equal to @a n
129 then there was not enough space in the destination buffer and the
130 string was truncated.
131
132 @since{2.9.0}
133
134 @header{wx/wxcrt.h}
135 */
136template <typename T>
137size_t wxStrlcpy(T *dst, const T *src, size_t n);
138
23324ae1 139/**
3950d49c
BP
140 This function replaces the dangerous standard function @e sprintf() and is
141 like @e snprintf() available on some platforms. The only difference with
142 @e sprintf() is that an additional argument - buffer size - is taken and
143 the buffer is never overflowed.
144
145 Returns the number of characters copied to the buffer or -1 if there is not
146 enough space.
147
148 @see wxVsnprintf(), wxString::Printf()
149
150 @header{wx/wxcrt.h}
23324ae1 151*/
3950d49c 152int wxSnprintf(wxChar* buf, size_t len, const wxChar* format, ...);
23324ae1
FM
153
154/**
3950d49c
BP
155 The same as wxSnprintf() but takes a @c va_list argument instead of an
156 arbitrary number of parameters.
157
158 @note If @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function
159 supports positional arguments (see wxString::Printf() for more
160 information). However other functions of the same family (wxPrintf(),
161 wxSprintf(), wxFprintf(), wxVfprintf(), wxVfprintf(), wxVprintf(),
162 wxVsprintf()) currently do not to support positional parameters even
163 when @c wxUSE_PRINTF_POS_PARAMS is 1.
164
165 @see wxSnprintf(), wxString::PrintfV()
166
167 @header{wx/wxcrt.h}
23324ae1 168*/
3950d49c
BP
169int wxVsnprintf(wxChar* buf, size_t len,
170 const wxChar* format, va_list argPtr);
171
172//@}
23324ae1 173