add wxStringCheck templated utility function
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58565 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -615,7 +615,7 @@ private:
|
|||||||
|
|
||||||
return wxTLS_VALUE(s_cache);
|
return wxTLS_VALUE(s_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this helper struct is used to ensure that GetCache() is called during
|
// this helper struct is used to ensure that GetCache() is called during
|
||||||
// static initialization time, i.e. before any threads creation, as otherwise
|
// static initialization time, i.e. before any threads creation, as otherwise
|
||||||
// the static s_cache construction inside GetCache() wouldn't be MT-safe
|
// the static s_cache construction inside GetCache() wouldn't be MT-safe
|
||||||
@@ -675,7 +675,7 @@ private:
|
|||||||
// a lot of misses in this function...)
|
// a lot of misses in this function...)
|
||||||
Cache::Element * const cacheBegin = GetCacheBegin();
|
Cache::Element * const cacheBegin = GetCacheBegin();
|
||||||
#ifndef wxHAS_COMPILER_TLS
|
#ifndef wxHAS_COMPILER_TLS
|
||||||
// during destruction tls calls may return NULL, in this case return NULL
|
// during destruction tls calls may return NULL, in this case return NULL
|
||||||
// immediately without accessing anything else
|
// immediately without accessing anything else
|
||||||
if ( cacheBegin == NULL )
|
if ( cacheBegin == NULL )
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1810,7 +1810,7 @@ public:
|
|||||||
const wchar_t* t_str() const { return wx_str(); }
|
const wchar_t* t_str() const { return wx_str(); }
|
||||||
#else
|
#else
|
||||||
const char* t_str() const { return wx_str(); }
|
const char* t_str() const { return wx_str(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// overloaded assignment
|
// overloaded assignment
|
||||||
@@ -4114,4 +4114,19 @@ void wxStringIteratorNode::clear()
|
|||||||
#include "wx/crt.h"
|
#include "wx/crt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Checks on wxString characters
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template<bool (T)(const wxUniChar& c)>
|
||||||
|
inline bool wxStringCheck(const wxString& val)
|
||||||
|
{
|
||||||
|
for ( wxString::const_iterator i = val.begin();
|
||||||
|
i != val.end();
|
||||||
|
++i )
|
||||||
|
if (T(*i) == 0)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _WX_WXSTRING_H_
|
#endif // _WX_WXSTRING_H_
|
||||||
|
@@ -246,7 +246,8 @@
|
|||||||
@stdobjects
|
@stdobjects
|
||||||
::wxEmptyString
|
::wxEmptyString
|
||||||
|
|
||||||
@see @ref overview_string, @ref overview_unicode, wxUString
|
@see @ref overview_string, @ref overview_unicode, wxUString,
|
||||||
|
wxCharBuffer, wxUniChar, wxStringTokenizer, @ref group_funcmacro_string
|
||||||
*/
|
*/
|
||||||
class wxString
|
class wxString
|
||||||
{
|
{
|
||||||
@@ -1526,3 +1527,37 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxStringCharType* operator wxStringCharType *();
|
wxStringCharType* operator wxStringCharType *();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup group_funcmacro_string */
|
||||||
|
//@{
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allows to extend a function with the signature:
|
||||||
|
@code bool SomeFunc(const wxUniChar& c) @endcode
|
||||||
|
which operates on a single character, to an entire wxString.
|
||||||
|
|
||||||
|
E.g. if you want to check if an entire string contains only digits,
|
||||||
|
you can do:
|
||||||
|
@code
|
||||||
|
if (wxStringCheck<wxIsdigit>(myString))
|
||||||
|
... // the entire string contains oly digits!
|
||||||
|
else
|
||||||
|
... // at least one character of myString is not a digit
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
@return @true if the given function returns a non-zero value for all
|
||||||
|
characters of the @a val string.
|
||||||
|
*/
|
||||||
|
template<bool (T)(const wxUniChar& c)>
|
||||||
|
inline bool wxStringCheck(const wxString& val)
|
||||||
|
{
|
||||||
|
for ( wxString::const_iterator i = val.begin();
|
||||||
|
i != val.end();
|
||||||
|
++i )
|
||||||
|
if (T(*i) == 0)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//@}
|
||||||
|
Reference in New Issue
Block a user