/**
* @mainpage Extended STL string
* @author Keenan Tims - ktims@gotroot.ca
* @version 0.2
* @date 2005-04-17
* @section desc Description
* ext_string aims to provide a portable, bug-free implementation of many useful extensions to the
* standard STL string class. These extensions are commonly available among higher-level languages
* such as Perl and Python, but C++ programmers are generally left on their own when it comes to
* basic string processing. By extending the STL's string, we can provide a drop-in replacement for STL
* strings with the greater functionality of higher-level languages.
*
* The primary goal of this library is to make the STL string class more usable to programmers that
* are doing simple string manipulation on a small scale. Due to the usability goals of this class,
* many actions will be inefficiently implemented for the sake of ease of use. Some of this is
* mitigated somewhat by doing modification in-place, however many unnecessary copies of data are
* created by some methods, and the vector-returning methods are inefficient in that they copy the
* substrings into the vector, then return a copy of the vector. This would be much more efficient
* as an iterator model.
*
*
* @section feat Features
*
* @li Fully based on the STL, ext_string provides a superset of std::string methods
* @li String splitting (tokenizing), on a character, a string, or whitespace
* @li Replacement of substrings or characters with another string or character
* @li String case operations (check, adjust)
* @li Integer conversion
* @li Fully open-source under a BSD-like license for use in any product
*
* @if web
* @section download Downloads
*
* Downloads are provided in tar.gz and zip formats containing this documentation, the header file,
* and the library's changelog. The latest version of ext_string is 0.2, released on April 17,
* 2005.
*
* @li<a href="files/ext_string-0.2.tar.gz">ext_string-0.2.tar.gz</a>
* @li<a href="files/ext_string-0.2.zip">ext_string-0.2.zip</a>
* @li <small><a href="files/ext_string-0.1.tar.gz">ext_string-0.1.tar.gz</a></small>
* @li <small><a href="files/ext_string-0.1.zip">ext_string-0.1.zip</a></small>
*
* @section changelog Changelog
*
* The changelog is viewable online <a href="files/CHANGELOG">here</a>
*
* @endif
*
* @section notes Notes/Limitations
* @li Copying all the substrings into a vector for the substring methods is pretty inefficient,
* both for space and time. It would be more prudent to model an iterator to split the string based
* on the specified parameters, but this is more difficult to implement and more cumbersome to use.
* Performance is not the main goal of this library, usability is, thus the tradeoff is deemed to be
* acceptable.
* @li References are not used too aptly in this class. Some performance tuning could be done to
* minimize unnecessary data copying.
* @li The basic methods of std::string aren't overridden by this class, thus assigning the return
* value of eg. string::insert() to an ext_string instance will make an unnecessary string object
* which is then copy-constructed to an ext_string (I believe, internal workings of inheritance and
* polymorphism in C++ are somewhat beyond my experience). These methods should be wrapped by
* ext_string to return the proper type.
*
*
* @section related Related Documentation
*
* @li SGI's STL string reference: http://www.sgi.com/tech/stl/basic_string.html
*
*
* @section license License
*
* Copyright (c) 2005, Keenan Tims
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* @li Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* @li Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
* @li Neither the name of the Extended STL String project nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#ifndef _EXT_STRING_H
#define _EXT_STRING_H
#include <string>
#include <vector>
namespace std
{
/**
* An extension of STL's string providing additional functionality that is often availiable in
* higher-level languages such as Python.
*/
class ext_string : public string
{
public:
/**
* Default constructor
*
* Constructs an empty ext_string ("")
*/
ext_string() : string() { }
/**
* Duplicate the STL string copy constructor
*
* @param[in] s The string to copy
* @param[in] pos The starting position in the string to copy from
* @param[in] n The number of characters to copy
*/
ext_string(const string &s, size_type pos = 0, size_type n = npos) : string(s, pos, npos) { }
/**
* Construct an ext_string from a null-terminated character array
*
* @param[in] s The character array to copy into the new string
*/
ext_string(const value_type *s) : string(s) { }
/**
* Construct an ext_string from a character array and a length
*
* @param[in] s The character array to copy into the new string
* @param[in] n The number of characters to copy
*/
ext_string(const value_type *s, size_type n) : string(s, n) { }
/**
* Create an ext_string with @p n copies of @p c
*
* @param[in] n The number of copies
* @param[in] c The character to copy @p n times
*/
ext_string(size_type n, value_type c) : string(n, c) { }
/**
* Create a string from a range
*
* @param[in] first The first element to copy in
* @param[in] last The last element to copy in
*/
template <class InputIterator>
ext_string(InputIterator first, InputIterator last) : string(first, last) { }
/**
* The destructor
*/
~ext_string() { }
/**
* Split a string by whitespace
*
* @return A vector of strings, each of which is a substring of the string
*/
vector<ext_string> split(size_type limit = npos) const
{
vector<ext_string> v;
const_iterator
i = begin(),
last = i;
for (; i != end(); i++)
{
if (*i == ' ' || *i == '\n' || *i == '\t' || *i == '\r')
{
if (i + 1 != end() && (i[1] == ' ' || i[1] == '\n' || i[1] == '\t' || i[1] == '\r'))
continue;
v.push_back(ext_string(last, i));
last = i + 1;
if (v.size() >= limit - 1)
{
v.push_back(ext_string(last, end()));
return v;
}
}
}
if (last != i)
v.push_back(ext_string(last, i));
return v;
}
/**
* Split a string by a character
*
* Returns a vector of ext_strings, each of which is a substring of the string formed by splitting
* it on boundaries formed by the character @p separator. If @p limit is set, the returned vector
* will contain a maximum of @p limit elements with the last element containing the rest of
* the string.
*
没有合适的资源?快使用搜索试试~ 我知道了~
ext_string.rar_ext_string_字符串分割
共62个文件
html:22个
png:14个
map:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 170 浏览量
2022-09-23
11:00:54
上传
评论
收藏 68KB RAR 举报
温馨提示
本例是对STL中string类的扩展,很好的弥补了现有string类的不足,可以和CString相媲美哦~~ 扩展的功能有分割字串,整形转换成string,字符串替换,判断该字串的类型等。 使用起来也很方便,直接include该头文件即可。
资源推荐
资源详情
资源评论
收起资源包目录
ext_string.rar (62个子文件)
ext_string
ext_string.h 19KB
CHANGELOG 170B
doc
basic__string_8h__incl.png 858B
basic__string_8h__dep__incl.md5 32B
stringfwd_8h__incl.png 808B
classstd_1_1ext__string__coll__graph.png 569B
files.html 2KB
ext__string_8h__incl.md5 32B
inherit__graph__0.md5 32B
stringfwd_8h__dep__incl.md5 32B
ext__string_8h__dep__incl.png 569B
dir_000000_000001.html 2KB
classstd_1_1ext__string.html 59KB
hierarchy.html 1KB
functions.html 3KB
basic__string_8h__incl.md5 32B
stringfwd_8h__dep__incl.map 54B
ext__string_8h__dep__incl.map 54B
dir_000000_dep.map 168B
annotated.html 2KB
ext__string_8h__dep__incl.md5 32B
basic__string_8h__incl.map 13B
ext__string_8h.html 7KB
inherits.html 2KB
basic__string_8h__dep__incl.png 783B
dir_000001_dep.map 83B
index.html 6KB
doxygen.png 1KB
dir_000000.html 2KB
inherit__graph__0.map 61B
stringfwd_8h__incl.md5 32B
ext__string_8h-source.html 25KB
stringfwd_8h__dep__incl.png 748B
dirs.html 1KB
stringfwd_8h-source.html 5KB
doxygen.css 7KB
stringfwd_8h__incl.map 13B
classstd_1_1ext__string__inherit__graph.png 569B
graph_legend.html 4KB
dir_000001_dep.png 403B
inherit__graph__0.png 759B
graph_legend.png 4KB
dir_000001.html 2KB
string_8h-source.html 5KB
functions_func.html 3KB
inherit__graph__1.png 819B
test_8cpp-source.html 2KB
classstd_1_1basic__string.html 39KB
ext__string_8h__incl.png 767B
ext__string_8h__incl.map 13B
stringfwd_8h.html 3KB
inherit__graph__1.md5 32B
dir_000000_dep.png 533B
classstd_1_1ext__string__coll__graph.map 61B
basic__string_8h.html 16KB
graph_legend.dot 2KB
classstd_1_1ext__string__coll__graph.md5 32B
classstd_1_1ext__string__inherit__graph.map 61B
classstd_1_1ext__string__inherit__graph.md5 32B
basic__string_8h__dep__incl.map 54B
basic__string_8h-source.html 67KB
inherit__graph__1.map 109B
共 62 条
- 1
资源评论
局外狗
- 粉丝: 81
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数据集-大豆种子质量好坏检测数据集6503张2个标签YOLO+VOC格式.zip
- JavaScript: 函数与作用域深入解析及应用场景
- 数据集-车内视角拍摄道路路面缺陷数据集1075张3类标签YOLO+VOC格式.zip
- KaixinSont(开心宋体)4.1
- Ruby编程语言中基础和高级控制结构详解
- 数据集-玻璃门窗缺陷检测数据集3085张5类YIOLO+VOC格式.zip
- MySQL索引与优化:原理、策略及高级应用
- Java面向对象编程中的封装与抽象技术详解及应用
- 数据集-玻璃杯玻璃瓶及瓶盖瓶身材质检测数据集2651张YOLO+VOC格式.zip
- Python项目实战:综合应用与案例分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功