Nugget
|
#include <fixed_substring.h>
Public Types | |
typedef basic_string< T > | base_type |
typedef fixed_substring< T > | this_type |
typedef base_type::size_type | size_type |
typedef base_type::value_type | value_type |
typedef base_type::iterator | iterator |
typedef base_type::const_iterator | const_iterator |
Public Types inherited from eastl::basic_string< T, Allocator > | |
typedef basic_string< T, Allocator > | this_type |
typedef basic_string_view< T > | view_type |
typedef T | value_type |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef eastl::reverse_iterator< iterator > | reverse_iterator |
typedef eastl::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef eastl_size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef Allocator | allocator_type |
Public Member Functions | |
fixed_substring (const base_type &x) | |
fixed_substring (const base_type &x, size_type position, size_type n=base_type::npos) | |
fixed_substring (const value_type *p, size_type n) | |
fixed_substring (const value_type *p) | |
fixed_substring (const value_type *pBegin, const value_type *pEnd) | |
this_type & | operator= (const base_type &x) |
this_type & | operator= (const value_type *p) |
this_type & | assign (const base_type &x) |
this_type & | assign (const base_type &x, size_type position, size_type n) |
this_type & | assign (const value_type *p, size_type n) |
this_type & | assign (const value_type *p) |
this_type & | assign (const value_type *pBegin, const value_type *pEnd) |
void | AllocateSelf () |
void | AllocateSelf (size_type n) |
Layout & | internalLayout () EA_NOEXCEPT |
const Layout & | internalLayout () const EA_NOEXCEPT |
const allocator_type & | get_allocator () const EA_NOEXCEPT |
allocator_type & | get_allocator () EA_NOEXCEPT |
Public Member Functions inherited from eastl::basic_string< T, Allocator > | |
basic_string (const allocator_type &allocator) EA_NOEXCEPT | |
basic_string (const this_type &x, size_type position, size_type n=npos) | |
basic_string (const value_type *p, size_type n, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
EASTL_STRING_EXPLICIT | basic_string (const value_type *p, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) |
basic_string (size_type n, value_type c, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
basic_string (const this_type &x) | |
basic_string (const this_type &x, const allocator_type &allocator) | |
basic_string (const value_type *pBegin, const value_type *pEnd, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
basic_string (CtorDoNotInitialize, size_type n, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
basic_string (CtorSprintf, const value_type *pFormat,...) | |
basic_string (std::initializer_list< value_type > init, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
basic_string (this_type &&x) EA_NOEXCEPT | |
basic_string (this_type &&x, const allocator_type &allocator) | |
basic_string (const view_type &sv, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
basic_string (const view_type &sv, size_type position, size_type n, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
template<typename OtherCharType > | |
basic_string (CtorConvert, const OtherCharType *p, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
template<typename OtherCharType > | |
basic_string (CtorConvert, const OtherCharType *p, size_type n, const allocator_type &allocator=EASTL_BASIC_STRING_DEFAULT_ALLOCATOR) | |
template<typename OtherStringType > | |
basic_string (CtorConvert, const OtherStringType &x) | |
const allocator_type & | get_allocator () const EA_NOEXCEPT |
allocator_type & | get_allocator () EA_NOEXCEPT |
void | set_allocator (const allocator_type &allocator) |
operator basic_string_view< T > () const EA_NOEXCEPT | |
this_type & | operator= (const this_type &x) |
this_type & | operator= (const value_type *p) |
this_type & | operator= (value_type c) |
this_type & | operator= (std::initializer_list< value_type > ilist) |
this_type & | operator= (view_type v) |
this_type & | operator= (this_type &&x) |
void | swap (this_type &x) |
this_type & | assign (const this_type &x) |
this_type & | assign (const this_type &x, size_type position, size_type n=npos) |
this_type & | assign (const value_type *p, size_type n) |
this_type & | assign (const value_type *p) |
this_type & | assign (size_type n, value_type c) |
this_type & | assign (const value_type *pBegin, const value_type *pEnd) |
this_type & | assign (this_type &&x) |
this_type & | assign (std::initializer_list< value_type >) |
template<typename OtherCharType > | |
this_type & | assign_convert (const OtherCharType *p) |
template<typename OtherCharType > | |
this_type & | assign_convert (const OtherCharType *p, size_type n) |
template<typename OtherStringType > | |
this_type & | assign_convert (const OtherStringType &x) |
iterator | begin () EA_NOEXCEPT |
const_iterator | begin () const EA_NOEXCEPT |
const_iterator | cbegin () const EA_NOEXCEPT |
iterator | end () EA_NOEXCEPT |
const_iterator | end () const EA_NOEXCEPT |
const_iterator | cend () const EA_NOEXCEPT |
reverse_iterator | rbegin () EA_NOEXCEPT |
const_reverse_iterator | rbegin () const EA_NOEXCEPT |
const_reverse_iterator | crbegin () const EA_NOEXCEPT |
reverse_iterator | rend () EA_NOEXCEPT |
const_reverse_iterator | rend () const EA_NOEXCEPT |
const_reverse_iterator | crend () const EA_NOEXCEPT |
bool | empty () const EA_NOEXCEPT |
size_type | size () const EA_NOEXCEPT |
size_type | length () const EA_NOEXCEPT |
size_type | max_size () const EA_NOEXCEPT |
size_type | capacity () const EA_NOEXCEPT |
void | resize (size_type n, value_type c) |
void | resize (size_type n) |
void | reserve (size_type=0) |
void | set_capacity (size_type n=npos) |
void | force_size (size_type n) |
void | shrink_to_fit () |
const value_type * | data () const EA_NOEXCEPT |
value_type * | data () EA_NOEXCEPT |
const value_type * | c_str () const EA_NOEXCEPT |
reference | operator[] (size_type n) |
const_reference | operator[] (size_type n) const |
reference | at (size_type n) |
const_reference | at (size_type n) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
this_type & | operator+= (const this_type &x) |
this_type & | operator+= (const value_type *p) |
this_type & | operator+= (value_type c) |
this_type & | append (const this_type &x) |
this_type & | append (const this_type &x, size_type position, size_type n=npos) |
this_type & | append (const value_type *p, size_type n) |
this_type & | append (const value_type *p) |
this_type & | append (size_type n, value_type c) |
this_type & | append (const value_type *pBegin, const value_type *pEnd) |
this_type & | append_sprintf_va_list (const value_type *pFormat, va_list arguments) |
this_type & | append_sprintf (const value_type *pFormat,...) |
template<typename OtherCharType > | |
this_type & | append_convert (const OtherCharType *p) |
template<typename OtherCharType > | |
this_type & | append_convert (const OtherCharType *p, size_type n) |
template<typename OtherStringType > | |
this_type & | append_convert (const OtherStringType &x) |
void | push_back (value_type c) |
void | pop_back () |
this_type & | insert (size_type position, const this_type &x) |
this_type & | insert (size_type position, const this_type &x, size_type beg, size_type n) |
this_type & | insert (size_type position, const value_type *p, size_type n) |
this_type & | insert (size_type position, const value_type *p) |
this_type & | insert (size_type position, size_type n, value_type c) |
iterator | insert (const_iterator p, value_type c) |
iterator | insert (const_iterator p, size_type n, value_type c) |
iterator | insert (const_iterator p, const value_type *pBegin, const value_type *pEnd) |
iterator | insert (const_iterator p, std::initializer_list< value_type >) |
this_type & | erase (size_type position=0, size_type n=npos) |
iterator | erase (const_iterator p) |
iterator | erase (const_iterator pBegin, const_iterator pEnd) |
reverse_iterator | erase (reverse_iterator position) |
reverse_iterator | erase (reverse_iterator first, reverse_iterator last) |
void | clear () EA_NOEXCEPT |
pointer | detach () EA_NOEXCEPT |
this_type & | replace (size_type position, size_type n, const this_type &x) |
this_type & | replace (size_type pos1, size_type n1, const this_type &x, size_type pos2, size_type n2=npos) |
this_type & | replace (size_type position, size_type n1, const value_type *p, size_type n2) |
this_type & | replace (size_type position, size_type n1, const value_type *p) |
this_type & | replace (size_type position, size_type n1, size_type n2, value_type c) |
this_type & | replace (const_iterator first, const_iterator last, const this_type &x) |
this_type & | replace (const_iterator first, const_iterator last, const value_type *p, size_type n) |
this_type & | replace (const_iterator first, const_iterator last, const value_type *p) |
this_type & | replace (const_iterator first, const_iterator last, size_type n, value_type c) |
this_type & | replace (const_iterator first, const_iterator last, const value_type *pBegin, const value_type *pEnd) |
size_type | copy (value_type *p, size_type n, size_type position=0) const |
size_type | find (const this_type &x, size_type position=0) const EA_NOEXCEPT |
size_type | find (const value_type *p, size_type position=0) const |
size_type | find (const value_type *p, size_type position, size_type n) const |
size_type | find (value_type c, size_type position=0) const EA_NOEXCEPT |
size_type | rfind (const this_type &x, size_type position=npos) const EA_NOEXCEPT |
size_type | rfind (const value_type *p, size_type position=npos) const |
size_type | rfind (const value_type *p, size_type position, size_type n) const |
size_type | rfind (value_type c, size_type position=npos) const EA_NOEXCEPT |
size_type | find_first_of (const this_type &x, size_type position=0) const EA_NOEXCEPT |
size_type | find_first_of (const value_type *p, size_type position=0) const |
size_type | find_first_of (const value_type *p, size_type position, size_type n) const |
size_type | find_first_of (value_type c, size_type position=0) const EA_NOEXCEPT |
size_type | find_last_of (const this_type &x, size_type position=npos) const EA_NOEXCEPT |
size_type | find_last_of (const value_type *p, size_type position=npos) const |
size_type | find_last_of (const value_type *p, size_type position, size_type n) const |
size_type | find_last_of (value_type c, size_type position=npos) const EA_NOEXCEPT |
size_type | find_first_not_of (const this_type &x, size_type position=0) const EA_NOEXCEPT |
size_type | find_first_not_of (const value_type *p, size_type position=0) const |
size_type | find_first_not_of (const value_type *p, size_type position, size_type n) const |
size_type | find_first_not_of (value_type c, size_type position=0) const EA_NOEXCEPT |
size_type | find_last_not_of (const this_type &x, size_type position=npos) const EA_NOEXCEPT |
size_type | find_last_not_of (const value_type *p, size_type position=npos) const |
size_type | find_last_not_of (const value_type *p, size_type position, size_type n) const |
size_type | find_last_not_of (value_type c, size_type position=npos) const EA_NOEXCEPT |
this_type | substr (size_type position=0, size_type n=npos) const |
int | compare (const this_type &x) const EA_NOEXCEPT |
int | compare (size_type pos1, size_type n1, const this_type &x) const |
int | compare (size_type pos1, size_type n1, const this_type &x, size_type pos2, size_type n2) const |
int | compare (const value_type *p) const |
int | compare (size_type pos1, size_type n1, const value_type *p) const |
int | compare (size_type pos1, size_type n1, const value_type *p, size_type n2) const |
int | comparei (const this_type &x) const EA_NOEXCEPT |
int | comparei (const value_type *p) const |
void | make_lower () |
void | make_upper () |
void | ltrim () |
void | rtrim () |
void | trim () |
void | ltrim (const value_type *p) |
void | rtrim (const value_type *p) |
void | trim (const value_type *p) |
this_type | left (size_type n) const |
this_type | right (size_type n) const |
this_type & | sprintf_va_list (const value_type *pFormat, va_list arguments) |
this_type & | sprintf (const value_type *pFormat,...) |
bool | validate () const EA_NOEXCEPT |
int | validate_iterator (const_iterator i) const EA_NOEXCEPT |
template<typename OtherCharType > | |
basic_string< T, Allocator > & | append_convert (const OtherCharType *pOther) |
template<typename OtherStringType > | |
basic_string< T, Allocator > & | append_convert (const OtherStringType &x) |
template<typename OtherCharType > | |
basic_string< T, Allocator > & | append_convert (const OtherCharType *pOther, size_type n) |
template<typename OtherCharType > | |
basic_string< T, Allocator > & | assign_convert (const OtherCharType *p) |
template<typename OtherCharType > | |
basic_string< T, Allocator > & | assign_convert (const OtherCharType *p, size_type n) |
template<typename OtherStringType > | |
basic_string< T, Allocator > & | assign_convert (const OtherStringType &x) |
Public Attributes | |
eastl::compressed_pair< Layout, allocator_type > | mPair |
Static Public Attributes | |
static const EA_CONSTEXPR size_type | npos |
Static Public Attributes inherited from eastl::basic_string< T, Allocator > | |
static const EA_CONSTEXPR size_type | npos = (size_type)-1 |
static EA_CONSTEXPR_OR_CONST size_type | kMaxSize = ~kHeapMask |
Additional Inherited Members | |
Static Public Member Functions inherited from eastl::basic_string< T, Allocator > | |
static int | compare (const value_type *pBegin1, const value_type *pEnd1, const value_type *pBegin2, const value_type *pEnd2) |
static int | comparei (const value_type *pBegin1, const value_type *pEnd1, const value_type *pBegin2, const value_type *pEnd2) |
Protected Member Functions inherited from eastl::basic_string< T, Allocator > | |
Layout & | internalLayout () EA_NOEXCEPT |
const Layout & | internalLayout () const EA_NOEXCEPT |
allocator_type & | internalAllocator () EA_NOEXCEPT |
const allocator_type & | internalAllocator () const EA_NOEXCEPT |
value_type * | DoAllocate (size_type n) |
void | DoFree (value_type *p, size_type n) |
size_type | GetNewCapacity (size_type currentCapacity) |
size_type | GetNewCapacity (size_type currentCapacity, size_type minimumGrowSize) |
void | AllocateSelf () |
void | AllocateSelf (size_type n) |
void | DeallocateSelf () |
iterator | InsertInternal (const_iterator p, value_type c) |
void | RangeInitialize (const value_type *pBegin, const value_type *pEnd) |
void | RangeInitialize (const value_type *pBegin) |
void | SizeInitialize (size_type n, value_type c) |
bool | IsSSO () const EA_NOEXCEPT |
void | ThrowLengthException () const |
void | ThrowRangeException () const |
void | ThrowInvalidArgumentException () const |
Static Protected Member Functions inherited from eastl::basic_string< T, Allocator > | |
static const value_type * | CharTypeStringFindEnd (const value_type *pBegin, const value_type *pEnd, value_type c) |
static const value_type * | CharTypeStringRFind (const value_type *pRBegin, const value_type *pREnd, const value_type c) |
static const value_type * | CharTypeStringSearch (const value_type *p1Begin, const value_type *p1End, const value_type *p2Begin, const value_type *p2End) |
static const value_type * | CharTypeStringRSearch (const value_type *p1Begin, const value_type *p1End, const value_type *p2Begin, const value_type *p2End) |
static const value_type * | CharTypeStringFindFirstOf (const value_type *p1Begin, const value_type *p1End, const value_type *p2Begin, const value_type *p2End) |
static const value_type * | CharTypeStringRFindFirstOf (const value_type *p1RBegin, const value_type *p1REnd, const value_type *p2Begin, const value_type *p2End) |
static const value_type * | CharTypeStringFindFirstNotOf (const value_type *p1Begin, const value_type *p1End, const value_type *p2Begin, const value_type *p2End) |
static const value_type * | CharTypeStringRFindFirstNotOf (const value_type *p1RBegin, const value_type *p1REnd, const value_type *p2Begin, const value_type *p2End) |
Protected Attributes inherited from eastl::basic_string< T, Allocator > | |
eastl::compressed_pair< Layout, allocator_type > | mPair |
Static Protected Attributes inherited from eastl::basic_string< T, Allocator > | |
static EA_CONSTEXPR_OR_CONST size_type | kHeapMask = ~(size_type(~size_type(0)) >> 1) |
static EA_CONSTEXPR_OR_CONST size_type | kSSOMask = 0x80 |
Implements a string which is a reference to a segment of characters. This class is efficient because it allocates no memory and copies no memory during construction and assignment, but rather refers directly to the segment of chracters. A common use of this is to have a fixed_substring efficiently refer to a substring within another string.
You cannot directly resize a fixed_substring (e.g. via resize, insert, append, erase), but you can assign a different substring to it. You can modify the characters within a substring in place. As of this writing, in the name of being lean and simple it is the user's responsibility to not call unsupported resizing functions such as those listed above. A detailed listing of the functions which are not supported is given below in the class declaration.
The c_str function doesn't act as one might hope, as it simply returns the pointer to the beginning of the string segment and the 0-terminator may be beyond the end of the segment. If you want to always be able to use c_str as expected, use the fixed string solution we describe below.
Another use of fixed_substring is to provide C++ string-like functionality with a C character array. This allows you to work on a C character array as if it were a C++ string as opposed using the C string API. Thus you can do this:
void DoSomethingForUser(char* timeStr, size_t timeStrCapacity) { fixed_substring tmp(timeStr, timeStrCapacity); tmp = "hello "; tmp += "world"; }
Note that this class constructs and assigns from const string pointers and const string objects, yet this class does not declare its member data as const. This is a concession in order to allow this implementation to be simple and lean. It is the user's responsibility to make sure that strings that should not or can not be modified are either not used by fixed_substring or are not modified by fixed_substring.
A more flexible alternative to fixed_substring is fixed_string. fixed_string has none of the functional limitations that fixed_substring has and like fixed_substring it doesn't allocate memory. However, fixed_string makes a copy of the source string and uses local memory to store that copy. Also, fixed_string objects on the stack are going to have a limit as to their maximum size.
Notes: As of this writing, the string class necessarily reallocates when an insert of self is done into self. As a result, the fixed_substring class doesn't support inserting self into self.
Example usage: basic_string<char> str("hello world"); fixed_substring<char> sub(str, 2, 5); // sub == "llo w"