basic_string.h

来自「symbian上STL模板库的实现」· C头文件 代码 · 共 1,380 行 · 第 1/5 页

H
1,380
字号
                 *  The data is copied, so there is no dependence on @a s once the                 *  function returns.                 */                basic_string&                    assign(const _CharT* __s)                    {                        __glibcxx_requires_string(__s);                        return this->assign(__s, traits_type::length(__s));                    }                /**                 *  @brief  Set value to multiple characters.                 *  @param n  Length of the resulting string.                 *  @param c  The character to use.                 *  @return  Reference to this string.                 *                 *  This function sets the value of this string to @a n copies of                 *  character @a c.                 */                basic_string&                    assign(size_type __n, _CharT __c)                    { return _M_replace_aux(size_type(0), this->size(), __n, __c); }                /**                 *  @brief  Set value to a range of characters.                 *  @param first  Iterator referencing the first character to append.                 *  @param last  Iterator marking the end of the range.                 *  @return  Reference to this string.                 *                 *  Sets value of string to characters in the range [first,last).                 */                template<class _InputIterator>                    basic_string&                    assign(_InputIterator __first, _InputIterator __last)                    { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }                /**                 *  @brief  Insert multiple characters.                 *  @param p  Iterator referencing location in string to insert at.                 *  @param n  Number of characters to insert                 *  @param c  The character to insert.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *                 *  Inserts @a n copies of character @a c starting at the position                 *  referenced by iterator @a p.  If adding characters causes the length                 *  to exceed max_size(), length_error is thrown.  The value of the                 *  string doesn't change if an error is thrown.                 */                void                    insert(iterator __p, size_type __n, _CharT __c)                    {	this->replace(__p, __p, __n, __c);  }                /**                 *  @brief  Insert a range of characters.                 *  @param p  Iterator referencing location in string to insert at.                 *  @param beg  Start of range.                 *  @param end  End of range.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *                 *  Inserts characters in range [beg,end).  If adding characters causes                 *  the length to exceed max_size(), length_error is thrown.  The value                 *  of the string doesn't change if an error is thrown.                 */                template<class _InputIterator>                    void insert(iterator __p, _InputIterator __beg, _InputIterator __end)                    { this->replace(__p, __p, __beg, __end); }                /**                 *  @brief  Insert value of a string.                 *  @param pos1  Iterator referencing location in string to insert at.                 *  @param str  The string to insert.                 *  @return  Reference to this string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *                 *  Inserts value of @a str starting at @a pos1.  If adding characters                 *  causes the length to exceed max_size(), length_error is thrown.  The                 *  value of the string doesn't change if an error is thrown.                 */                basic_string&                    insert(size_type __pos1, const basic_string& __str)                    { return this->insert(__pos1, __str, size_type(0), __str.size()); }                /**                 *  @brief  Insert a substring.                 *  @param pos1  Iterator referencing location in string to insert at.                 *  @param str  The string to insert.                 *  @param pos2  Start of characters in str to insert.                 *  @param n  Number of characters to insert.                 *  @return  Reference to this string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *  @throw  std::out_of_range  If @a pos1 > size() or                 *  @a pos2 > @a str.size().                 *                 *  Starting at @a pos1, insert @a n character of @a str beginning with                 *  @a pos2.  If adding characters causes the length to exceed                 *  max_size(), length_error is thrown.  If @a pos1 is beyond the end of                 *  this string or @a pos2 is beyond the end of @a str, out_of_range is                 *  thrown.  The value of the string doesn't change if an error is                 *  thrown.                 */                basic_string&                    insert(size_type __pos1, const basic_string& __str,                            size_type __pos2, size_type __n)                    { return this->insert(__pos1, __str._M_data()                            + __str._M_check(__pos2, "basic_string::insert"),                            __str._M_limit(__pos2, __n)); }                /**                 *  @brief  Insert a C substring.                 *  @param pos  Iterator referencing location in string to insert at.                 *  @param s  The C string to insert.                 *  @param n  The number of characters to insert.                 *  @return  Reference to this string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *  @throw  std::out_of_range  If @a pos is beyond the end of this                 *  string.                 *                 *  Inserts the first @a n characters of @a s starting at @a pos.  If                 *  adding characters causes the length to exceed max_size(),                 *  length_error is thrown.  If @a pos is beyond end(), out_of_range is                 *  thrown.  The value of the string doesn't change if an error is                 *  thrown.                 */                basic_string&                    insert(size_type __pos, const _CharT* __s, size_type __n);                /**                 *  @brief  Insert a C string.                 *  @param pos  Iterator referencing location in string to insert at.                 *  @param s  The C string to insert.                 *  @return  Reference to this string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *  @throw  std::out_of_range  If @a pos is beyond the end of this                 *  string.                 *                 *  Inserts the first @a n characters of @a s starting at @a pos.  If                 *  adding characters causes the length to exceed max_size(),                 *  length_error is thrown.  If @a pos is beyond end(), out_of_range is                 *  thrown.  The value of the string doesn't change if an error is                 *  thrown.                 */                basic_string&                    insert(size_type __pos, const _CharT* __s)                    {                        __glibcxx_requires_string(__s);                        return this->insert(__pos, __s, traits_type::length(__s));                    }                /**                 *  @brief  Insert multiple characters.                 *  @param pos  Index in string to insert at.                 *  @param n  Number of characters to insert                 *  @param c  The character to insert.                 *  @return  Reference to this string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *  @throw  std::out_of_range  If @a pos is beyond the end of this                 *  string.                 *                 *  Inserts @a n copies of character @a c starting at index @a pos.  If                 *  adding characters causes the length to exceed max_size(),                 *  length_error is thrown.  If @a pos > length(), out_of_range is                 *  thrown.  The value of the string doesn't change if an error is                 *  thrown.                 */                basic_string&                    insert(size_type __pos, size_type __n, _CharT __c)                    { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),                            size_type(0), __n, __c); }                /**                 *  @brief  Insert one character.                 *  @param p  Iterator referencing position in string to insert at.                 *  @param c  The character to insert.                 *  @return  Iterator referencing newly inserted char.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *                 *  Inserts character @a c at position referenced by @a p.  If adding                 *  character causes the length to exceed max_size(), length_error is                 *  thrown.  If @a p is beyond end of string, out_of_range is thrown.                 *  The value of the string doesn't change if an error is thrown.                 */                iterator                    insert(iterator __p, _CharT __c)                    {                        _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());                        const size_type __pos = __p - _M_ibegin();                        _M_replace_aux(__pos, size_type(0), size_type(1), __c);                        _M_rep()->_M_set_leaked();                        return this->_M_ibegin() + __pos;                    }                /**                 *  @brief  Remove characters.                 *  @param pos  Index of first character to remove (default 0).                 *  @param n  Number of characters to remove (default remainder).                 *  @return  Reference to this string.                 *  @throw  std::out_of_range  If @a pos is beyond the end of this                 *  string.                 *                 *  Removes @a n characters from this string starting at @a pos.  The                 *  length of the string is reduced by @a n.  If there are < @a n                 *  characters to remove, the remainder of the string is truncated.  If                 *  @a p is beyond end of string, out_of_range is thrown.  The value of                 *  the string doesn't change if an error is thrown.                 */                basic_string&                    erase(size_type __pos = 0, size_type __n = npos)                    { return _M_replace_safe(_M_check(__pos, "basic_string::erase"),                            _M_limit(__pos, __n), NULL, size_type(0)); }                /**                 *  @brief  Remove one character.                 *  @param position  Iterator referencing the character to remove.                 *  @return  iterator referencing same location after removal.                 *                 *  Removes the character at @a position from this string. The value                 *  of the string doesn't change if an error is thrown.                 */                iterator                    erase(iterator __position)                    {                        _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()                                && __position < _M_iend());                        const size_type __pos = __position - _M_ibegin();                        _M_replace_safe(__pos, size_type(1), NULL, size_type(0));                        _M_rep()->_M_set_leaked();                        return _M_ibegin() + __pos;                    }                /**                 *  @brief  Remove a range of characters.                 *  @param first  Iterator referencing the first character to remove.                 *  @param last  Iterator referencing the end of the range.                 *  @return  Iterator referencing location of first after removal.                 *                 *  Removes the characters in the range [first,last) from this string.                 *  The value of the string doesn't change if an error is thrown.                 */                iterator                    erase(iterator __first, iterator __last)                    {                        _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last                                && __last <= _M_iend());                        const size_type __pos = __first - _M_ibegin();                        _M_replace_safe(__pos, __last - __first, NULL, size_type(0));                        _M_rep()->_M_set_leaked();                        return _M_ibegin() + __pos;                    }                /**                 *  @brief  Replace characters with value from another string.                 *  @param pos  Index of first character to replace.                 *  @param n  Number of characters to be replaced.                 *  @param str  String to insert.                 *  @return  Reference to this string.                 *  @throw  std::out_of_range  If @a pos is beyond the end of this                 *  string.                 *  @throw  std::length_error  If new length exceeds @c max_size().                 *                 *  Removes the characters in the range [pos,pos+n) from this string.                 *  In place, the value of @a str is inserted.  If @a pos is beyond end                 *  of string, out_of_range is thrown.  If the length of the result                 *  exceeds max_size(), length_error is thrown.  The value of the string                 *  doesn't change if an error is thrown.                 */                basic_string&                    replace(size_type __pos, size_type __n, const basic_string& __str)                    { return this->replace(__pos, __n, __str._M_data(), __str.size()); }                /**                 *  @brief  Replace characters with value from another string.                 *  @param pos1  Index of first character to replace.                 *  @param n1  Number of characters to be replaced.                 *  @param str  String to insert.                 *  @param pos2  Index of first character of str to use.                 *  @param n2  Number of characters from str to use.

⌨️ 快捷键说明

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