string.h
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C头文件 代码 · 共 1,531 行 · 第 1/4 页
H
1,531 行
// use empty()
bool IsNull() const { return empty(); }
// std::string compatibility functions
// take nLen chars starting at nPos
wxString(const wxString& str, size_t nPos, size_t nLen)
: wxStringBase(str, nPos, nLen) { }
// take all characters from pStart to pEnd
wxString(const void *pStart, const void *pEnd)
: wxStringBase((const wxChar*)pStart, (const wxChar*)pEnd) { }
#if wxUSE_STL
wxString(const_iterator first, const_iterator last)
: wxStringBase(first, last) { }
#endif
// lib.string.modifiers
// append elements str[pos], ..., str[pos+n]
wxString& append(const wxString& str, size_t pos, size_t n)
{ return (wxString&)wxStringBase::append(str, pos, n); }
// append a string
wxString& append(const wxString& str)
{ return (wxString&)wxStringBase::append(str); }
// append first n (or all if n == npos) characters of sz
wxString& append(const wxChar *sz)
{ return (wxString&)wxStringBase::append(sz); }
wxString& append(const wxChar *sz, size_t n)
{ return (wxString&)wxStringBase::append(sz, n); }
// append n copies of ch
wxString& append(size_t n, wxChar ch)
{ return (wxString&)wxStringBase::append(n, ch); }
// append from first to last
wxString& append(const_iterator first, const_iterator last)
{ return (wxString&)wxStringBase::append(first, last); }
// same as `this_string = str'
wxString& assign(const wxString& str)
{ return (wxString&)wxStringBase::assign(str); }
// same as ` = str[pos..pos + n]
wxString& assign(const wxString& str, size_t pos, size_t n)
{ return (wxString&)wxStringBase::assign(str, pos, n); }
// same as `= first n (or all if n == npos) characters of sz'
wxString& assign(const wxChar *sz)
{ return (wxString&)wxStringBase::assign(sz); }
wxString& assign(const wxChar *sz, size_t n)
{ return (wxString&)wxStringBase::assign(sz, n); }
// same as `= n copies of ch'
wxString& assign(size_t n, wxChar ch)
{ return (wxString&)wxStringBase::assign(n, ch); }
// assign from first to last
wxString& assign(const_iterator first, const_iterator last)
{ return (wxString&)wxStringBase::assign(first, last); }
// string comparison
#if !defined(HAVE_STD_STRING_COMPARE)
int compare(const wxStringBase& str) const;
// comparison with a substring
int compare(size_t nStart, size_t nLen, const wxStringBase& str) const;
// comparison of 2 substrings
int compare(size_t nStart, size_t nLen,
const wxStringBase& str, size_t nStart2, size_t nLen2) const;
// just like strcmp()
int compare(const wxChar* sz) const;
// substring comparison with first nCount characters of sz
int compare(size_t nStart, size_t nLen,
const wxChar* sz, size_t nCount = npos) const;
#endif // !defined HAVE_STD_STRING_COMPARE
// insert another string
wxString& insert(size_t nPos, const wxString& str)
{ return (wxString&)wxStringBase::insert(nPos, str); }
// insert n chars of str starting at nStart (in str)
wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
{ return (wxString&)wxStringBase::insert(nPos, str, nStart, n); }
// insert first n (or all if n == npos) characters of sz
wxString& insert(size_t nPos, const wxChar *sz)
{ return (wxString&)wxStringBase::insert(nPos, sz); }
wxString& insert(size_t nPos, const wxChar *sz, size_t n)
{ return (wxString&)wxStringBase::insert(nPos, sz, n); }
// insert n copies of ch
wxString& insert(size_t nPos, size_t n, wxChar ch)
{ return (wxString&)wxStringBase::insert(nPos, n, ch); }
iterator insert(iterator it, wxChar ch)
{ return wxStringBase::insert(it, ch); }
void insert(iterator it, const_iterator first, const_iterator last)
{ wxStringBase::insert(it, first, last); }
void insert(iterator it, size_type n, wxChar ch)
{ wxStringBase::insert(it, n, ch); }
// delete characters from nStart to nStart + nLen
wxString& erase(size_type pos = 0, size_type n = npos)
{ return (wxString&)wxStringBase::erase(pos, n); }
iterator erase(iterator first, iterator last)
{ return wxStringBase::erase(first, last); }
iterator erase(iterator first)
{ return wxStringBase::erase(first); }
#ifdef wxSTRING_BASE_HASNT_CLEAR
void clear() { erase(); }
#endif
// replaces the substring of length nLen starting at nStart
wxString& replace(size_t nStart, size_t nLen, const wxChar* sz)
{ return (wxString&)wxStringBase::replace(nStart, nLen, sz); }
// replaces the substring of length nLen starting at nStart
wxString& replace(size_t nStart, size_t nLen, const wxString& str)
{ return (wxString&)wxStringBase::replace(nStart, nLen, str); }
// replaces the substring with nCount copies of ch
wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch)
{ return (wxString&)wxStringBase::replace(nStart, nLen, nCount, ch); }
// replaces a substring with another substring
wxString& replace(size_t nStart, size_t nLen,
const wxString& str, size_t nStart2, size_t nLen2)
{ return (wxString&)wxStringBase::replace(nStart, nLen, str,
nStart2, nLen2); }
// replaces the substring with first nCount chars of sz
wxString& replace(size_t nStart, size_t nLen,
const wxChar* sz, size_t nCount)
{ return (wxString&)wxStringBase::replace(nStart, nLen, sz, nCount); }
wxString& replace(iterator first, iterator last, const_pointer s)
{ return (wxString&)wxStringBase::replace(first, last, s); }
wxString& replace(iterator first, iterator last, const_pointer s,
size_type n)
{ return (wxString&)wxStringBase::replace(first, last, s, n); }
wxString& replace(iterator first, iterator last, const wxString& s)
{ return (wxString&)wxStringBase::replace(first, last, s); }
wxString& replace(iterator first, iterator last, size_type n, wxChar c)
{ return (wxString&)wxStringBase::replace(first, last, n, c); }
wxString& replace(iterator first, iterator last,
const_iterator first1, const_iterator last1)
{ return (wxString&)wxStringBase::replace(first, last, first1, last1); }
// string += string
wxString& operator+=(const wxString& s)
{ return (wxString&)wxStringBase::operator+=(s); }
// string += C string
wxString& operator+=(const wxChar *psz)
{ return (wxString&)wxStringBase::operator+=(psz); }
// string += char
wxString& operator+=(wxChar ch)
{ return (wxString&)wxStringBase::operator+=(ch); }
};
// notice that even though for many compilers the friend declarations above are
// enough, from the point of view of C++ standard we must have the declarations
// here as friend ones are not injected in the enclosing namespace and without
// them the code fails to compile with conforming compilers such as xlC or g++4
wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2);
wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch);
wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string);
wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wxChar *psz);
wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string);
// define wxArrayString, for compatibility
#if WXWIN_COMPATIBILITY_2_4 && !wxUSE_STL
#include "wx/arrstr.h"
#endif
#if wxUSE_STL
// return an empty wxString (not very useful with wxUSE_STL == 1)
inline const wxString wxGetEmptyString() { return wxString(); }
#else // !wxUSE_STL
// return an empty wxString (more efficient than wxString() here)
inline const wxString& wxGetEmptyString()
{
return *(wxString *)&wxEmptyString;
}
#endif // wxUSE_STL/!wxUSE_STL
// ----------------------------------------------------------------------------
// wxStringBuffer: a tiny class allowing to get a writable pointer into string
// ----------------------------------------------------------------------------
#if wxUSE_STL
class WXDLLIMPEXP_BASE wxStringBuffer
{
public:
wxStringBuffer(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(lenWanted)
{ }
~wxStringBuffer() { m_str.assign(m_buf.data(), wxStrlen(m_buf.data())); }
operator wxChar*() { return m_buf.data(); }
private:
wxString& m_str;
#if wxUSE_UNICODE
wxWCharBuffer m_buf;
#else
wxCharBuffer m_buf;
#endif
DECLARE_NO_COPY_CLASS(wxStringBuffer)
};
class WXDLLIMPEXP_BASE wxStringBufferLength
{
public:
wxStringBufferLength(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(lenWanted), m_len(0), m_lenSet(false)
{ }
~wxStringBufferLength()
{
wxASSERT(m_lenSet);
m_str.assign(m_buf.data(), m_len);
}
operator wxChar*() { return m_buf.data(); }
void SetLength(size_t length) { m_len = length; m_lenSet = true; }
private:
wxString& m_str;
#if wxUSE_UNICODE
wxWCharBuffer m_buf;
#else
wxCharBuffer m_buf;
#endif
size_t m_len;
bool m_lenSet;
DECLARE_NO_COPY_CLASS(wxStringBufferLength)
};
#else // if !wxUSE_STL
class WXDLLIMPEXP_BASE wxStringBuffer
{
public:
wxStringBuffer(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL)
{ m_buf = m_str.GetWriteBuf(lenWanted); }
~wxStringBuffer() { m_str.UngetWriteBuf(); }
operator wxChar*() const { return m_buf; }
private:
wxString& m_str;
wxChar *m_buf;
DECLARE_NO_COPY_CLASS(wxStringBuffer)
};
class WXDLLIMPEXP_BASE wxStringBufferLength
{
public:
wxStringBufferLength(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
{
m_buf = m_str.GetWriteBuf(lenWanted);
wxASSERT(m_buf != NULL);
}
~wxStringBufferLength()
{
wxASSERT(m_lenSet);
m_str.UngetWriteBuf(m_len);
}
operator wxChar*() const { return m_buf; }
void SetLength(size_t length) { m_len = length; m_lenSet = true; }
private:
wxString& m_str;
wxChar *m_buf;
size_t m_len;
bool m_lenSet;
DECLARE_NO_COPY_CLASS(wxStringBufferLength)
};
#endif // !wxUSE_STL
// ---------------------------------------------------------------------------
// wxString comparison functions: operator versions are always case sensitive
// ---------------------------------------------------------------------------
// note that when wxUSE_STL == 1 the comparison operators taking std::string
// are used and defining them also for wxString would only result in
// compilation ambiguities when comparing std::string and wxString
#if !wxUSE_STL
inline bool operator==(const wxString& s1, const wxString& s2)
{ return (s1.Len() == s2.Len()) && (s1.Cmp(s2) == 0); }
inline bool operator==(const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) == 0; }
inline bool operator==(const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) == 0; }
inline bool operator!=(const wxString& s1, const wxString& s2)
{ return (s1.Len() != s2.Len()) || (s1.Cmp(s2) != 0); }
inline bool operator!=(const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) != 0; }
inline bool operator!=(const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) != 0; }
inline bool operator< (const wxString& s1, const wxString& s2)
{ return s1.Cmp(s2) < 0; }
inline bool operator< (const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) < 0; }
inline bool operator< (const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) > 0; }
inline bool operator> (const wxString& s1, const wxString& s2)
{ return s1.Cmp(s2) > 0; }
inline bool operator> (const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) > 0; }
inline bool operator> (const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) < 0; }
inline bool operator<=(const wxString& s1, const wxString& s2)
{ return s1.Cmp(s2) <= 0; }
inline bool operator<=(const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) <= 0; }
inline bool operator<=(const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) >= 0; }
inline bool operator>=(const wxString& s1, const wxString& s2)
{ return s1.Cmp(s2) >= 0; }
inline bool operator>=(const wxString& s1, const wxChar * s2)
{ return s1.Cmp(s2) >= 0; }
inline bool operator>=(const wxChar * s1, const wxString& s2)
{ return s2.Cmp(s1) <= 0; }
#if wxUSE_UNICODE
inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
{ return (s1.Cmp((const wchar_t *)s2) == 0); }
inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const wchar_t *)s1) == 0); }
inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
{ return (s1.Cmp((const wchar_t *)s2) != 0); }
inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const wchar_t *)s1) != 0); }
#else // !wxUSE_UNICODE
inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
{ return (s1.Cmp((const char *)s2) == 0); }
inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const char *)s1) == 0); }
inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
{ return (s1.Cmp((const char *)s2) != 0); }
inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const char *)s1) != 0); }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
#if wxUSE_UNICODE
inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
{ return string + (const wchar_t *)buf; }
inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
{ return (const wchar_t *)buf + string; }
#else // !wxUSE_UNICODE
inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
{ return string + (const char *)buf; }
inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
{ return (const char *)buf + string; }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
#endif // !wxUSE_STL
// comparison with char (those are not defined by std::[w]string and so should
// be always available)
inline bool operator==(wxChar c, const wxString& s) { return s.IsSameAs(c); }
inline bool operator==(const wxString& s, wxChar c) { return s.IsSameAs(c); }
inline bool operator!=(wxChar c, const wxString& s) { return !s.IsSameAs(c); }
inline bool operator!=(const wxString& s, wxChar c) { return !s.IsSameAs(c); }
// ---------------------------------------------------------------------------
// Implementation only from here until the end of file
// ---------------------------------------------------------------------------
// don't pollute the library user's name space
#undef wxASSERT_VALID_INDEX
#if wxUSE_STD_IOSTREAM
#include "wx/iosfwrap.h"
WXDLLIMPEXP_BASE wxSTD istream& operator>>(wxSTD istream&, wxString&);
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
#endif // wxSTD_STRING_COMPATIBILITY
#endif // _WX_WXSTRINGH__
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?