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

📄 string.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 4 页
字号:
    // same as Cmp() but not case-sensitive
  int CmpNoCase(const wxChar *psz) const { return wxStricmp(c_str(), psz); }
    // 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 (Len() == 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 = wxSTRING_MAXLEN) 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);
    // minimize the string's memory
    // only works if the data of this string is not shared
  bool Shrink();
    // 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);

  // wxWindows 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 Len(); }
    // 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(Len() - n); }

  wxString& Remove(size_t nStart, size_t nLen) { return 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) != -1; }

    // use IsEmpty()
  bool IsNull() const { return IsEmpty(); }

#ifdef  wxSTD_STRING_COMPATIBILITY
  // std::string compatibility functions

  // standard types
  typedef wxChar value_type;
  typedef const value_type *const_iterator;

  // an 'invalid' value for string index
  static const size_t npos;

  // constructors
    // take nLen chars starting at nPos
  wxString(const wxString& str, size_t nPos, size_t nLen)
      : m_pchData(NULL)
  {
    wxASSERT_MSG( str.GetStringData()->IsValid(),
                  _T("did you forget to call UngetWriteBuf()?") );

    InitWith(str.c_str(), nPos, nLen == npos ? 0 : nLen);
  }
    // take all characters from pStart to pEnd
  wxString(const void *pStart, const void *pEnd);

  // lib.string.capacity
    // return the length of the string
  size_t size() const { return Len(); }
    // return the length of the string
  size_t length() const { return Len(); }
    // return the maximum size of the string
  size_t max_size() const { return wxSTRING_MAXLEN; }
    // resize the string, filling the space with c if c != 0
  void resize(size_t nSize, wxChar ch = wxT('\0'));
    // delete the contents of the string
  void clear() { Empty(); }
    // returns true if the string is empty
  bool empty() const { return IsEmpty(); }
    // inform string about planned change in size
  void reserve(size_t sz) { Alloc(sz); }

  // lib.string.access
    // return the character at position n
  wxChar at(size_t n) const { return GetChar(n); }
    // returns the writable character at position n
  wxChar& at(size_t n) { return GetWritableChar(n); }

    // first valid index position
  const_iterator begin() const { return wx_str(); }
    // position one after the last valid one
  const_iterator end() const { return wx_str() + length(); }

  // lib.string.modifiers
    // append a string
  wxString& append(const wxString& str)
    { *this += str; return *this; }
    // append elements str[pos], ..., str[pos+n]
  wxString& append(const wxString& str, size_t pos, size_t n)
    { ConcatSelf(n, str.c_str() + pos); return *this; }
    // append first n (or all if n == npos) characters of sz
  wxString& append(const wxChar *sz, size_t n = npos)
    { ConcatSelf(n == npos ? wxStrlen(sz) : n, sz); return *this; }

    // append n copies of ch
  wxString& append(size_t n, wxChar ch) { return Pad(n, ch); }

    // same as `this_string = str'
  wxString& assign(const wxString& str)
    { return *this = str; }
    // same as ` = str[pos..pos + n]
  wxString& assign(const wxString& str, size_t pos, size_t n)
    { Empty(); return Append(str.c_str() + pos, n); }
    // same as `= first n (or all if n == npos) characters of sz'
  wxString& assign(const wxChar *sz, size_t n = npos)
    { Empty(); return Append(sz, n == npos ? wxStrlen(sz) : n); }
    // same as `= n copies of ch'
  wxString& assign(size_t n, wxChar ch)
    { Empty(); return Append(ch, n); }

    // insert another string
  wxString& insert(size_t nPos, const wxString& 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 insert(nPos, wxString((const wxChar *)str + nStart, n)); }

    // insert first n (or all if n == npos) characters of sz
  wxString& insert(size_t nPos, const wxChar *sz, size_t n = npos)
    { return insert(nPos, wxString(sz, n)); }
    // insert n copies of ch
  wxString& insert(size_t nPos, size_t n, wxChar ch)
    { return insert(nPos, wxString(ch, n)); }

    // delete characters from nStart to nStart + nLen
  wxString& erase(size_t nStart = 0, size_t nLen = npos);

    // replaces the substring of length nLen starting at nStart
  wxString& replace(size_t nStart, size_t nLen, const wxChar* sz);
    // replaces the substring with nCount copies of ch
  wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch);
    // replaces a substring with another substring
  wxString& replace(size_t nStart, size_t nLen,
                    const wxString& str, size_t nStart2, size_t nLen2);
    // replaces the substring with first nCount chars of sz
  wxString& replace(size_t nStart, size_t nLen,
                    const wxChar* sz, size_t nCount);

    // swap two strings
  void swap(wxString& str);

    // All find() functions take the nStart argument which specifies the
    // position to start the search on, the default value is 0. All functions
    // return npos if there were no match.

    // find a substring
  size_t find(const wxString& str, size_t nStart = 0) const;

  // VC++ 1.5 can't cope with this syntax.
#if !defined(__VISUALC__) || defined(__WIN32__)
    // find first n characters of sz
  size_t find(const wxChar* sz, size_t nStart = 0, size_t n = npos) const;
#endif // VC++ 1.5

  // Gives a duplicate symbol (presumably a case-insensitivity problem)
#if !defined(__BORLANDC__)
    // find the first occurence of character ch after nStart
  size_t find(wxChar ch, size_t nStart = 0) const;
#endif
    // rfind() family is exactly like find() but works right to left

    // as find, but from the end
  size_t rfind(const wxString& str, size_t nStart = npos) const;

  // VC++ 1.5 can't cope with this syntax.
#if !defined(__VISUALC__) || defined(__WIN32__)
    // as find, but from the end
  size_t rfind(const wxChar* sz, size_t nStart = npos,
          size_t n = npos) const;
    // as find, but from the end
  size_t rfind(wxChar ch, size_t nStart = npos) const;
#endif // VC++ 1.5

    // find first/last occurence of any character in the set

    // as strpbrk() but starts at nStart, returns npos if not found
  size_t find_first_of(const wxString& str, size_t nStart = 0) const
    { return find_first_of(str.c_str(), nStart); }
    // same as above
  size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
    // same as find(char, size_t)
  size_t find_first_of(wxChar c, size_t nStart = 0) const
    { return find(c, nStart); }
    // find the last (starting from nStart) char from str in this string
  size_t find_last_of (const wxString& str, size_t nStart = npos) const
    { return find_last_of(str.c_str(), nStart); }
    // same as above
  size_t find_last_of (const wxChar* sz, size_t nStart = npos) const;

⌨️ 快捷键说明

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