string.h
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C头文件 代码 · 共 1,531 行 · 第 1/4 页
H
1,531 行
{ return wxStringBase::at(n); }
wxChar& operator[](size_type n)
{ return wxStringBase::at(n); }
#ifndef wxSIZE_T_IS_UINT
wxChar& operator[](unsigned int n)
{ return wxStringBase::at(n); }
#endif // size_t != unsigned int
// implicit conversion to C string
operator const wxChar*() const { return c_str(); }
// identical to c_str(), for wxWin 1.6x compatibility
const wxChar* wx_str() const { return c_str(); }
// identical to c_str(), for MFC compatibility
const wxChar* GetData() const { return c_str(); }
// conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
// converting numbers or strings which are certain not to contain special
// chars (typically system functions, X atoms, environment variables etc.)
//
// the behaviour of these functions with the strings containing anything
// else than 7 bit ASCII characters is undefined, use at your own risk.
#if wxUSE_UNICODE
static wxString FromAscii(const char *ascii); // string
static wxString FromAscii(const char ascii); // char
const wxCharBuffer ToAscii() const;
#else // ANSI
static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
static wxString FromAscii(const char ascii) { return wxString( ascii ); }
const char *ToAscii() const { return c_str(); }
#endif // Unicode/!Unicode
// conversions with (possible) format conversions: have to return a
// buffer with temporary data
//
// the functions defined (in either Unicode or ANSI) mode are mb_str() to
// return an ANSI (multibyte) string, wc_str() to return a wide string and
// fn_str() to return a string which should be used with the OS APIs
// accepting the file names. The return value is always the same, but the
// type differs because a function may either return pointer to the buffer
// directly or have to use intermediate buffer for translation.
#if wxUSE_UNICODE
const wxCharBuffer mb_str(wxMBConv& conv = wxConvLibc) const;
const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
const wxChar* wc_str() const { return c_str(); }
// for compatibility with !wxUSE_UNICODE version
const wxChar* wc_str(wxMBConv& WXUNUSED(conv)) const { return c_str(); }
#if wxMBFILES
const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
#else // !wxMBFILES
const wxChar* fn_str() const { return c_str(); }
#endif // wxMBFILES/!wxMBFILES
#else // ANSI
const wxChar* mb_str() const { return c_str(); }
// for compatibility with wxUSE_UNICODE version
const wxChar* mb_str(wxMBConv& WXUNUSED(conv)) const { return c_str(); }
const wxWX2MBbuf mbc_str() const { return mb_str(); }
#if wxUSE_WCHAR_T
const wxWCharBuffer wc_str(wxMBConv& conv) const;
#endif // wxUSE_WCHAR_T
#ifdef __WXOSX__
const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLocal ) ); }
#else
const wxChar* fn_str() const { return c_str(); }
#endif
#endif // Unicode/ANSI
// overloaded assignment
// from another wxString
wxString& operator=(const wxStringBase& stringSrc)
{ return (wxString&)wxStringBase::operator=(stringSrc); }
// from a character
wxString& operator=(wxChar ch)
{ return (wxString&)wxStringBase::operator=(ch); }
// from a C string - STL probably will crash on NULL,
// so we need to compensate in that case
#if wxUSE_STL
wxString& operator=(const wxChar *psz)
{ if(psz) wxStringBase::operator=(psz); else Clear(); return *this; }
#else
wxString& operator=(const wxChar *psz)
{ return (wxString&)wxStringBase::operator=(psz); }
#endif
#if wxUSE_UNICODE
// from wxWCharBuffer
wxString& operator=(const wxWCharBuffer& psz)
{ (void) operator=((const wchar_t *)psz); return *this; }
#else // ANSI
// from another kind of C string
wxString& operator=(const unsigned char* psz);
#if wxUSE_WCHAR_T
// from a wide string
wxString& operator=(const wchar_t *pwz);
#endif
// from wxCharBuffer
wxString& operator=(const wxCharBuffer& psz)
{ (void) operator=((const char *)psz); return *this; }
#endif // Unicode/ANSI
// string concatenation
// in place concatenation
/*
Concatenate and return the result. Note that the left to right
associativity of << allows to write things like "str << str1 << str2
<< ..." (unlike with +=)
*/
// string += string
wxString& operator<<(const wxString& s)
{
#if !wxUSE_STL
wxASSERT_MSG( s.GetStringData()->IsValid(),
_T("did you forget to call UngetWriteBuf()?") );
#endif
append(s);
return *this;
}
// string += C string
wxString& operator<<(const wxChar *psz)
{ append(psz); return *this; }
// string += char
wxString& operator<<(wxChar ch) { append(1, ch); return *this; }
// string += buffer (i.e. from wxGetString)
#if wxUSE_UNICODE
wxString& operator<<(const wxWCharBuffer& s)
{ (void)operator<<((const wchar_t *)s); return *this; }
void operator+=(const wxWCharBuffer& s)
{ (void)operator<<((const wchar_t *)s); }
#else // !wxUSE_UNICODE
wxString& operator<<(const wxCharBuffer& s)
{ (void)operator<<((const char *)s); return *this; }
void operator+=(const wxCharBuffer& s)
{ (void)operator<<((const char *)s); }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
// string += C string
wxString& Append(const wxString& s)
{
// test for empty() to share the string if possible
if ( empty() )
*this = s;
else
append(s);
return *this;
}
wxString& Append(const wxChar* psz)
{ append(psz); return *this; }
// append count copies of given character
wxString& Append(wxChar ch, size_t count = 1u)
{ append(count, ch); return *this; }
wxString& Append(const wxChar* psz, size_t nLen)
{ append(psz, nLen); return *this; }
// prepend a string, return the string itself
wxString& Prepend(const wxString& str)
{ *this = str + *this; return *this; }
// non-destructive concatenation
//
friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2);
//
friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch);
//
friend wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string);
//
friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wxChar *psz);
//
friend wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string);
// stream-like functions
// insert an int into string
wxString& operator<<(int i)
{ return (*this) << Format(_T("%d"), i); }
// insert an unsigned int into string
wxString& operator<<(unsigned int ui)
{ return (*this) << Format(_T("%u"), ui); }
// insert a long into string
wxString& operator<<(long l)
{ return (*this) << Format(_T("%ld"), l); }
// insert an unsigned long into string
wxString& operator<<(unsigned long ul)
{ return (*this) << Format(_T("%lu"), ul); }
#if wxABI_VERSION >= 20603
#if defined wxLongLong_t && !defined wxLongLongIsLong
// insert a long long if they exist and aren't longs
wxString& operator<<(wxLongLong_t ll)
{
const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("d");
return (*this) << Format(fmt, ll);
}
// insert an unsigned long long
wxString& operator<<(wxULongLong_t ull)
{
const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("u");
return (*this) << Format(fmt , ull);
}
#endif
#endif
// insert a float into string
wxString& operator<<(float f)
{ return (*this) << Format(_T("%f"), f); }
// insert a double into string
wxString& operator<<(double d)
{ return (*this) << Format(_T("%g"), d); }
// string comparison
// case-sensitive comparison (returns a value < 0, = 0 or > 0)
int Cmp(const wxChar *psz) const;
int Cmp(const wxString& s) const;
// same as Cmp() but not case-sensitive
int CmpNoCase(const wxChar *psz) const;
int CmpNoCase(const wxString& s) const;
// test for the string equality, either considering case or not
// (if compareWithCase then the case matters)
bool IsSameAs(const wxChar *psz, bool compareWithCase = true) const
{ return (compareWithCase ? Cmp(psz) : CmpNoCase(psz)) == 0; }
// comparison with a signle character: returns true if equal
bool IsSameAs(wxChar c, bool compareWithCase = true) const
{
return (length() == 1) && (compareWithCase ? GetChar(0u) == c
: wxToupper(GetChar(0u)) == wxToupper(c));
}
// simple sub-string extraction
// return substring starting at nFirst of length nCount (or till the end
// if nCount = default value)
wxString Mid(size_t nFirst, size_t nCount = npos) const;
// operator version of Mid()
wxString operator()(size_t start, size_t len) const
{ return Mid(start, len); }
// check that the string starts with prefix and return the rest of the
// string in the provided pointer if it is not NULL, otherwise return
// false
bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
// get first nCount characters
wxString Left(size_t nCount) const;
// get last nCount characters
wxString Right(size_t nCount) const;
// get all characters before the first occurance of ch
// (returns the whole string if ch not found)
wxString BeforeFirst(wxChar ch) const;
// get all characters before the last occurence of ch
// (returns empty string if ch not found)
wxString BeforeLast(wxChar ch) const;
// get all characters after the first occurence of ch
// (returns empty string if ch not found)
wxString AfterFirst(wxChar ch) const;
// get all characters after the last occurence of ch
// (returns the whole string if ch not found)
wxString AfterLast(wxChar ch) const;
// for compatibility only, use more explicitly named functions above
wxString Before(wxChar ch) const { return BeforeLast(ch); }
wxString After(wxChar ch) const { return AfterFirst(ch); }
// case conversion
// convert to upper case in place, return the string itself
wxString& MakeUpper();
// convert to upper case, return the copy of the string
// Here's something to remember: BC++ doesn't like returns in inlines.
wxString Upper() const ;
// convert to lower case in place, return the string itself
wxString& MakeLower();
// convert to lower case, return the copy of the string
wxString Lower() const ;
// trimming/padding whitespace (either side) and truncating
// remove spaces from left or from right (default) side
wxString& Trim(bool bFromRight = true);
// add nCount copies chPad in the beginning or at the end (default)
wxString& Pad(size_t nCount, wxChar chPad = wxT(' '), bool bFromRight = true);
// searching and replacing
// searching (return starting index, or -1 if not found)
int Find(wxChar ch, bool bFromEnd = false) const; // like strchr/strrchr
// searching (return starting index, or -1 if not found)
int Find(const wxChar *pszSub) const; // like strstr
// replace first (or all of bReplaceAll) occurences of substring with
// another string, returns the number of replacements made
size_t Replace(const wxChar *szOld,
const wxChar *szNew,
bool bReplaceAll = true);
// check if the string contents matches a mask containing '*' and '?'
bool Matches(const wxChar *szMask) const;
// conversion to numbers: all functions return true only if the whole
// string is a number and put the value of this number into the pointer
// provided, the base is the numeric base in which the conversion should be
// done and must be comprised between 2 and 36 or be 0 in which case the
// standard C rules apply (leading '0' => octal, "0x" => hex)
// convert to a signed integer
bool ToLong(long *val, int base = 10) const;
// convert to an unsigned integer
bool ToULong(unsigned long *val, int base = 10) const;
// convert to a double
bool ToDouble(double *val) const;
// formated input/output
// as sprintf(), returns the number of characters written or < 0 on error
// (take 'this' into account in attribute parameter count)
int Printf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
// as vprintf(), returns the number of characters written or < 0 on error
int PrintfV(const wxChar* pszFormat, va_list argptr);
// returns the string containing the result of Printf() to it
static wxString Format(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_1;
// the same as above, but takes a va_list
static wxString FormatV(const wxChar *pszFormat, va_list argptr);
// raw access to string memory
// ensure that string has space for at least nLen characters
// only works if the data of this string is not shared
bool Alloc(size_t nLen) { reserve(nLen); /*return capacity() >= nLen;*/ return true; }
// minimize the string's memory
// only works if the data of this string is not shared
bool Shrink();
#if !wxUSE_STL
// get writable buffer of at least nLen bytes. Unget() *must* be called
// a.s.a.p. to put string back in a reasonable state!
wxChar *GetWriteBuf(size_t nLen);
// call this immediately after GetWriteBuf() has been used
void UngetWriteBuf();
void UngetWriteBuf(size_t nLen);
#endif
// wxWidgets version 1 compatibility functions
// use Mid()
wxString SubString(size_t from, size_t to) const
{ return Mid(from, (to - from + 1)); }
// values for second parameter of CompareTo function
enum caseCompare {exact, ignoreCase};
// values for first parameter of Strip function
enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
// use Printf()
// (take 'this' into account in attribute parameter count)
int sprintf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
// use Cmp()
inline int CompareTo(const wxChar* psz, caseCompare cmp = exact) const
{ return cmp == exact ? Cmp(psz) : CmpNoCase(psz); }
// use Len
size_t Length() const { return length(); }
// Count the number of characters
int Freq(wxChar ch) const;
// use MakeLower
void LowerCase() { MakeLower(); }
// use MakeUpper
void UpperCase() { MakeUpper(); }
// use Trim except that it doesn't change this string
wxString Strip(stripType w = trailing) const;
// use Find (more general variants not yet supported)
size_t Index(const wxChar* psz) const { return Find(psz); }
size_t Index(wxChar ch) const { return Find(ch); }
// use Truncate
wxString& Remove(size_t pos) { return Truncate(pos); }
wxString& RemoveLast(size_t n = 1) { return Truncate(length() - n); }
wxString& Remove(size_t nStart, size_t nLen)
{ return (wxString&)erase( nStart, nLen ); }
// use Find()
int First( const wxChar ch ) const { return Find(ch); }
int First( const wxChar* psz ) const { return Find(psz); }
int First( const wxString &str ) const { return Find(str); }
int Last( const wxChar ch ) const { return Find(ch, true); }
bool Contains(const wxString& str) const { return Find(str) != wxNOT_FOUND; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?