⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 4 页
字号:
  wxString(const char *psz, wxMBConv& conv, size_t nLength = wxSTRING_MAXLEN);
    // from wxWCharBuffer (i.e. return from wxGetString)
  wxString(const wxWCharBuffer& psz)
    { InitWith(psz, 0, wxSTRING_MAXLEN); }
#else // ANSI
    // from C string (for compilers using unsigned char)
  wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN)
      : m_pchData(NULL)
      { InitWith((const char*)psz, 0, nLength); }

#if wxUSE_WCHAR_T
    // from wide (Unicode) string
  wxString(const wchar_t *pwz, wxMBConv& conv = wxConvLibc, size_t nLength = wxSTRING_MAXLEN);
#endif // !wxUSE_WCHAR_T

    // from wxCharBuffer
  wxString(const wxCharBuffer& psz)
      : m_pchData(NULL)
      { InitWith(psz, 0, wxSTRING_MAXLEN); }
#endif // Unicode/ANSI

    // dtor is not virtual, this class must not be inherited from!
 ~wxString() { GetStringData()->Unlock(); }

  // generic attributes & operations
    // as standard strlen()
  size_t Len() const { return GetStringData()->nDataLength; }
    // string contains any characters?
  bool IsEmpty() const { return Len() == 0; }
    // empty string is "FALSE", so !str will return TRUE
  bool operator!() const { return IsEmpty(); }
    // truncate the string to given length
  wxString& Truncate(size_t uiLen);
    // empty string contents
  void Empty()
  {
    Truncate(0);

    wxASSERT_MSG( IsEmpty(), _T("string not empty after call to Empty()?") );
  }
    // empty the string and free memory
  void Clear()
  {
    if ( !GetStringData()->IsEmpty() )
      Reinit();

    wxASSERT_MSG( !GetStringData()->nDataLength &&
                  !GetStringData()->nAllocLength,
                  _T("string should be empty after Clear()") );
  }

  // contents test
    // Is an ascii value
  bool IsAscii() const;
    // Is a number
  bool IsNumber() const;
    // Is a word
  bool IsWord() const;

  // data access (all indexes are 0 based)
    // read access
    wxChar  GetChar(size_t n) const
      { wxASSERT_VALID_INDEX( n );  return m_pchData[n]; }
    // read/write access
    wxChar& GetWritableChar(size_t n)
      { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
    // write access
    void  SetChar(size_t n, wxChar ch)
      { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); m_pchData[n] = ch; }

    // get last character
    wxChar  Last() const
      {
          wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );

          return m_pchData[Len() - 1];
      }

    // get writable last character
    wxChar& Last()
      {
          wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );
          CopyBeforeWrite();
          return m_pchData[Len()-1];
      }

    /*
        So why do we have all these overloaded operator[]s? A bit of history:
        initially there was only one of them, taking size_t. Then people
        started complaining because they wanted to use ints as indices (I
        wonder why) and compilers were giving warnings about it, so we had to
        add the operator[](int). Then it became apparent that you couldn't
        write str[0] any longer because there was ambiguity between two
        overloads and so you now had to write str[0u] (or, of course, use the
        explicit casts to either int or size_t but nobody did this).

        Finally, someone decided to compile wxWin on an Alpha machine and got
        a surprize: str[0u] didn't compile there because it is of type
        unsigned int and size_t is unsigned _long_ on Alpha and so there was
        ambiguity between converting uint to int or ulong. To fix this one we
        now add operator[](uint) for the machines where size_t is not already
        the same as unsigned int - hopefully this fixes the problem (for some
        time)

        The only real fix is, of course, to remove all versions but the one
        taking size_t...
     */

    // operator version of GetChar
    wxChar  operator[](size_t n) const
      { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }

    // operator version of GetChar
    wxChar  operator[](int n) const
      { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }

    // operator version of GetWriteableChar
    wxChar& operator[](size_t n)
      { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }

#ifndef wxSIZE_T_IS_UINT
    // operator version of GetChar
    wxChar operator[](unsigned int n) const
      { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }

    // operator version of GetWriteableChar
    wxChar& operator[](unsigned int n)
      { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
#endif // size_t != unsigned int

    // implicit conversion to C string
    operator const wxChar*() const { return m_pchData; }

    // explicit conversion to C string (use this with printf()!)
    const wxChar* c_str()   const { return m_pchData; }
    // identical to c_str(), for wxWin 1.6x compatibility
    const wxChar* wx_str()  const { return m_pchData; }
    // identical to c_str(), for MFC compatibility
    const wxChar* GetData() const { return m_pchData; }

    // 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
        { return conv.cWC2MB(m_pchData); }

    const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }

    const wxChar* wc_str() const { return m_pchData; }

    // for compatibility with !wxUSE_UNICODE version
    const wxChar* wc_str(wxMBConv& WXUNUSED(conv)) const { return m_pchData; }

#if wxMBFILES
    const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
#else // !wxMBFILES
    const wxChar* fn_str() const { return m_pchData; }
#endif // wxMBFILES/!wxMBFILES
#else // ANSI
    const wxChar* mb_str() const { return m_pchData; }

    // for compatibility with wxUSE_UNICODE version
    const wxChar* mb_str(wxMBConv& WXUNUSED(conv)) const { return m_pchData; }

    const wxWX2MBbuf mbc_str() const { return mb_str(); }

#if wxUSE_WCHAR_T
    const wxWCharBuffer wc_str(wxMBConv& conv) const
        { return conv.cMB2WC(m_pchData); }
#endif // wxUSE_WCHAR_T

    const wxChar* fn_str() const { return m_pchData; }
#endif // Unicode/ANSI

  // overloaded assignment
    // from another wxString
  wxString& operator=(const wxString& stringSrc);
    // from a character
  wxString& operator=(wxChar ch);
    // from a C string
  wxString& operator=(const wxChar *psz);
#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)
  {
    wxASSERT_MSG( s.GetStringData()->IsValid(),
                  _T("did you forget to call UngetWriteBuf()?") );

    ConcatSelf(s.Len(), s);
    return *this;
  }
      // string += C string
  wxString& operator<<(const wxChar *psz)
    { ConcatSelf(wxStrlen(psz), psz); return *this; }
      // string += char
  wxString& operator<<(wxChar ch) { ConcatSelf(1, &ch); return *this; }

      // string += string
  void operator+=(const wxString& s) { (void)operator<<(s); }
      // string += C string
  void operator+=(const wxChar *psz) { (void)operator<<(psz); }
      // string += char
  void operator+=(wxChar ch) { (void)operator<<(ch); }

      // 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 IsEmpty() to share the string if possible
        if ( IsEmpty() )
            *this = s;
        else
            ConcatSelf(s.Length(), s.c_str());
        return *this;
    }
  wxString& Append(const wxChar* psz)
    { ConcatSelf(wxStrlen(psz), psz); return *this; }
    // append count copies of given character
  wxString& Append(wxChar ch, size_t count = 1u)
    { wxString str(ch, count); return *this << str; }
  wxString& Append(const wxChar* psz, size_t nLen)
    { ConcatSelf(nLen, psz); return *this; }

    // prepend a string, return the string itself
  wxString& Prepend(const wxString& str)
    { *this = str + *this; return *this; }

    // non-destructive concatenation
      //
  friend wxString WXDLLEXPORT operator+(const wxString& string1,  const wxString& string2);
      //
  friend wxString WXDLLEXPORT operator+(const wxString& string, wxChar ch);
      //
  friend wxString WXDLLEXPORT operator+(wxChar ch, const wxString& string);
      //
  friend wxString WXDLLEXPORT operator+(const wxString& string, const wxChar *psz);
      //
  friend wxString WXDLLEXPORT 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); }
      // 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 { return wxStrcmp(c_str(), psz); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -