Samchon Framework for CPP  1.0.0
samchon::WeakString Class Reference

A string class only references characeters, reference only. More...

#include <WeakString.hpp>

Public Member Functions

 WeakString ()
 Default Constructor does not reference any character. More...
 
 WeakString (const char *data, size_t size)
 Constructor by characters with specified size. More...
 
 WeakString (const char *begin, const char *end)
 Constructor by characters of begin and end. More...
 
 WeakString (const char *data)
 Constructor by characters. More...
 
 WeakString (const char &ch)
 Constructor by a single character. More...
 
 WeakString (std::initializer_list< char > &il)
 Constructor by a initializer list. More...
 
 WeakString (const std::string &str)
 Constructor by string. More...
 
auto data () const -> const char *
 Get string data; referenced characeters. More...
 
auto size () const -> size_t
 Returns size of the characters which are being referenced. More...
 
auto empty () const -> bool
 Tests wheter string is emtpy. More...
 
auto at (size_t index) const -> const char &
 Get character of string Returns a const reference to the character at the specified position. More...
 
auto operator[] (size_t index) const -> const char &
 Get character of string Returns a const reference to the character at the specified position. More...
 
auto find (const WeakString &delim, size_t startIndex=NULL) const -> size_t
 Finds first occurence in string. More...
 
auto rfind (const WeakString &delim, size_t endIndex=SIZE_MAX) const -> size_t
 Finds last occurence in string. More...
 
auto finds (const std::vector< std::string > &delims, size_t startIndex=0) const -> IndexPair< WeakString >
 Finds first occurence in string. More...
 
auto rfinds (const std::vector< std::string > &delims, size_t endIndex=SIZE_MAX) const -> IndexPair< WeakString >
 Finds last occurence in string. More...
 
auto substr (size_t startIndex, size_t size=SIZE_MAX) const -> WeakString
 Generates a substring. More...
 
auto substring (size_t startIndex, size_t endIndex=SIZE_MAX) const -> WeakString
 Generates a substring. More...
 
auto between (const WeakString &start={}, const WeakString &end={}) const -> WeakString
 Generates a substring. More...
 
auto split (const WeakString &delim) const -> std::vector< WeakString >
 Generates substrings. More...
 
auto betweens (const WeakString &start={}, const WeakString &end={}) const -> std::vector< WeakString >
 Generates substrings. More...
 
auto trim (const std::vector< std::string > &delims) const -> WeakString
 Removes all designated characters from the beginning and end of the specified string. More...
 
auto ltrim (const std::vector< std::string > &delims) const -> WeakString
 Removes all designated characters from the beginning of the specified string. More...
 
auto rtrim (const std::vector< std::string > &delims) const -> WeakString
 Removes all designated characters from the end of the specified string. More...
 
auto replace (const WeakString &before, const WeakString &after) const -> std::string
 Replace portion of string once. More...
 
auto replaceAll (const WeakString &before, const WeakString &after) const -> std::string
 Returns a string specified word is replaced. More...
 
auto replaceAll (const std::vector< std::pair< std::string, std::string >> &pairs) const -> std::string
 Returns a string specified words are replaced. More...
 
auto toLowerCase () const -> std::string
 Convert uppercase letters to lowercase. More...
 
auto yoUpperCase () const -> std::string
 Convert uppercase letters to lowercase. More...
 
auto str () const -> std::string
 Get the string content. More...
 

Static Public Attributes

static const size_t npos = -1
 Maximum value for size_t. More...
 

Private Attributes

const char * data_
 Referenced characters's pointer of begining position. More...
 
size_t size_
 (Specified) size of referenced characters More...
 

Static Private Attributes

static const std::vector< std::string > SPACE_ARRAY
 An array containing whitespaces. More...
 

Detailed Description

A string class only references characeters, reference only.

WeakSring does not consider any construction, modification and destruction of characters.

Thus, you can have greater advantages than std::string on the side of performance and memory, but of course, you can't modify the characeters at all.

library_string.png
Warning
  • WeakString not copy(strcpy) characeters but only references characeters. Be careful about destruction of the characters being referenced by the WeakString
  • WeakString will be used for basic data type in most case. Avoid to use WeakString by pre-definition in header (*.hpp)
See also
samchon::library
Author
Jeongho Nam http://samchon.org

Definition at line 35 of file WeakString.hpp.

Constructor & Destructor Documentation

samchon::WeakString::WeakString ( )
inline

Default Constructor does not reference any character.

Constructs an empty string, with zero size

Definition at line 77 of file WeakString.hpp.

Referenced by rfinds(), substr(), and substring().

Here is the caller graph for this function:

samchon::WeakString::WeakString ( const char *  data,
size_t  size 
)
inline

Constructor by characters with specified size.

Constructs by characters to be referenced with limited size.

Although the original size of data is over the specified size, you can limit referencing size of the characters

  • Referencing a part of characters
Warning
WeakString only references. Be careful about destruction of the characters (data)
Parameters
dataTarget characters to be referenced by string
size

Specified limit-size of characters to be referenced.

If the specified size is greater than original size, it will be ignored

Definition at line 102 of file WeakString.hpp.

References data(), and size().

Here is the call graph for this function:

samchon::WeakString::WeakString ( const char *  begin,
const char *  end 
)
inline

Constructor by characters of begin and end.

Constructs by characters to be referenced with its end position.

Although the original end point of data is over the specified end, you can limit end point of the characters.

  • Referencing a part of characters
Warning
WeakString only references. Be careful about destruction of the characters (data).
Parameters
beginTarget characters to be referenced by string
end

Specified end point of characters to be referenced.

If the specified end point is greater than original end point, it will be ignored.

Definition at line 127 of file WeakString.hpp.

samchon::WeakString::WeakString ( const char *  data)
inline

Constructor by characters.

References the null-terminated character sequence pointed by ptr

Warning
WeakString only references. Be careful about destruction of the characeters (data)
Parameters
dataTarget characters to be referenced by string

Definition at line 139 of file WeakString.hpp.

References data().

Here is the call graph for this function:

samchon::WeakString::WeakString ( const char &  ch)
inline

Constructor by a single character.

References a single character

Warning
WeakString only references. Be careful about destruction of the characeter (data)
Parameters
chTarget character to be referenced by string

Definition at line 156 of file WeakString.hpp.

samchon::WeakString::WeakString ( std::initializer_list< char > &  il)
inline

Constructor by a initializer list.

References initializer list of character

Warning
WeakString only references. Be careful about destruction of the characeters (data)
Parameters
ilTarget initializer list of characters to be referenced by string

Definition at line 169 of file WeakString.hpp.

samchon::WeakString::WeakString ( const std::string &  str)
inline

Constructor by string.

References whole chracters of the string

Warning
WeakString only references. Be careful about destruction of the string
Parameters
strTarget string to be referenced by string

Definition at line 186 of file WeakString.hpp.

Member Function Documentation

auto samchon::WeakString::data ( ) const -> const char*
inline

Get string data; referenced characeters.

Returns a pointer to an array that contains a null-terminated sequence of characters representing the current value of the string object

Warning
Returned pointer's size can be longer than string's specified size if the string references only a part of the characters
Returns
A pointer of characters being referenced by the string

Definition at line 206 of file WeakString.hpp.

References data_.

Referenced by WeakString().

Here is the caller graph for this function:

auto samchon::WeakString::size ( ) const -> size_t
inline

Returns size of the characters which are being referenced.

Returns the length of the string, in terms of number of referenced characters

Returns
size of characters being referenced by string

Definition at line 217 of file WeakString.hpp.

References size_.

Referenced by between(), find(), replace(), replaceAll(), rfind(), rtrim(), split(), substr(), WeakString(), samchon::library::XML::XML(), and yoUpperCase().

Here is the caller graph for this function:

auto samchon::WeakString::empty ( ) const -> bool
inline

Tests wheter string is emtpy.

Returns wheter characters' size is zero or not.

Of course, string references nothing, then returns false, too.

Returns
Wheter size is zero or not

Definition at line 231 of file WeakString.hpp.

Referenced by between(), betweens(), samchon::library::XML::push_back(), rfind(), rtrim(), and samchon::library::StringUtil::substituteSQL().

Here is the caller graph for this function:

auto samchon::WeakString::at ( size_t  index) const -> const char&
inline

Get character of string Returns a const reference to the character at the specified position.

Returns
const reference of character at the specified index

Definition at line 242 of file WeakString.hpp.

Referenced by yoUpperCase().

Here is the caller graph for this function:

auto samchon::WeakString::operator[] ( size_t  index) const -> const char&
inline

Get character of string Returns a const reference to the character at the specified position.

Returns
const reference of character at the specified index

Definition at line 253 of file WeakString.hpp.

auto samchon::WeakString::find ( const WeakString delim,
size_t  startIndex = NULL 
) const -> size_t
inline

Finds first occurence in string.

Finds the string after startIndex and returns the position of first occurence of delim.

If delim is not found, returns -1 (npos)

Parameters
delimThe substring of the string which to find
startIndexSpecified starting index of find. Default is 0
Returns
Index of first occurence of the specified substring or -1

Definition at line 273 of file WeakString.hpp.

References npos, size(), and size_.

Referenced by between(), betweens(), finds(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), rtrim(), samchon::library::Date::set(), split(), samchon::library::StringUtil::substituteSQL(), samchon::library::URLVariables::URLVariables(), samchon::protocol::WebServer::WebServer(), and samchon::library::XML::XML().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::rfind ( const WeakString delim,
size_t  endIndex = SIZE_MAX 
) const -> size_t
inline

Finds last occurence in string.

Finds the string before endIndex and returns the position of last occurence of delim. If delim is not found, returns -1 (npos)

Parameters
delimThe substring of the string which to find
endIndexSpecified last index of find. Default is size() - 1
Returns
Index of first occurence of the specified substring or -1

Definition at line 297 of file WeakString.hpp.

References empty(), npos, and size().

Referenced by rfinds(), rtrim(), and samchon::library::XML::XML().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::finds ( const std::vector< std::string > &  delims,
size_t  startIndex = 0 
) const -> IndexPair<WeakString>
inline

Finds first occurence in string.

Finds first occurence position of each delim in the string after startIndex and returns the minimum position of them.

Note
  • If startIndex is not specified, then starts from 0.
  • If failed to find any substring, returns -1 (npos)
Parameters
delimsThe substrings of target(str) which to find
startIndexSpecified starting index of find. Default is 0
Returns
pair<size_t := position, string := matched substring>

Definition at line 330 of file WeakString.hpp.

References find(), samchon::IndexPair< T >::get_index(), samchon::IndexPair< T >::getValue(), and samchon::library::Math::minimum().

Referenced by samchon::library::StringUtil::finds().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::rfinds ( const std::vector< std::string > &  delims,
size_t  endIndex = SIZE_MAX 
) const -> IndexPair<WeakString>
inline

Finds last occurence in string.

Finds last occurence position of each delim in the string before endIndex and returns the maximum position of them.

Note
  • If index is not specified, then starts str.size() - 1
  • If failed to find any substring, returns -1 (npos)
Parameters
delimsThe substrings of target(str) which to find
endIndexSpecified starting index of find. Default is size() - 1
Returns
pair<size_t := position, string := matched substring>

Definition at line 366 of file WeakString.hpp.

References samchon::IndexPair< T >::get_index(), samchon::IndexPair< T >::getValue(), samchon::library::Math::maximum(), rfind(), and WeakString().

Referenced by samchon::library::StringUtil::rfinds().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::substr ( size_t  startIndex,
size_t  size = SIZE_MAX 
) const -> WeakString
inline

Generates a substring.

Extracts a substring consisting of the character specified by startIndex and all characters up to endIndex - 1.

  • If endIndex is not specified, string::size() will be used instead.
  • If endIndex is greater than startIndex, then those will be swapped
Parameters
startIndex

Index of the first character.

If startIndex is greater than endIndex, those will be swapped.

Parameters
size

Index of the last character - 1.

If not specified, then string::size() will be used instead.

Returns
Sub string by specified index(es)

Definition at line 419 of file WeakString.hpp.

References size(), and WeakString().

Referenced by between(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), samchon::library::Date::set(), samchon::library::URLVariables::URLVariables(), and samchon::library::XML::XML().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::substring ( size_t  startIndex,
size_t  endIndex = SIZE_MAX 
) const -> WeakString
inline

Generates a substring.

Extracts a substring consisting of the characters starts from startIndex and with a size specified size.

Parameters
startIndex

Index of the first character.

If startIndex is greater than endIndex, those will be swapped.

Parameters
endIndex

Number of characters to include in substring.

If the specified size is greater than last index of characeters, it will be shrinked.

Returns
Sub string by specified index and size

Definition at line 443 of file WeakString.hpp.

References size_, and WeakString().

Referenced by between(), betweens(), replaceAll(), split(), samchon::library::StringUtil::substring(), and samchon::library::XML::XML().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::between ( const WeakString start = {},
const WeakString end = {} 
) const -> WeakString
inline

Generates a substring.

Extracts a substring consisting of the characters from specified start to end.

It's same with substring( ? = (str.find(start) + start.size()), find(end, ?) )

  • between("ABCD[EFGH]IJK", "[", "]") => "EFGH"
Note
  • If start is not specified, extracts from begin of the string to end
  • If end is not specified, extracts from start to end of the string
  • If start and end are all omitted, returns str, itself.
Parameters
startA string for separating substring at the front
endA string for separating substring at the end
Returns
substring by specified terms

Definition at line 475 of file WeakString.hpp.

References empty(), find(), size(), substr(), and substring().

Referenced by samchon::library::StringUtil::between(), samchon::protocol::WebServerConnector::connect(), samchon::library::HTTPLoader::load(), samchon::library::Date::set(), samchon::protocol::WebServer::WebServer(), and samchon::library::XML::XML().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::split ( const WeakString delim) const -> std::vector<WeakString>
inline

Generates substrings.

Splits a string in to an array of substrings dividing by the specified delimiter

Parameters
delimThe pattern which specifies where to split the string
Returns
An array of substrings

Definition at line 502 of file WeakString.hpp.

References find(), size(), and substring().

Referenced by betweens(), samchon::library::HTTPLoader::load(), samchon::library::Date::set(), samchon::library::StringUtil::split(), and samchon::library::URLVariables::URLVariables().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::betweens ( const WeakString start = {},
const WeakString end = {} 
) const -> std::vector<WeakString>
inline

Generates substrings.

Splits a string into an array of substrings dividing by delimeters of start and end.

It's the array of substrings adjusted the between.

Note
  • If start is omitted, it's same with the split by endStr not having last item
  • If end is omitted, it's same with the split by startStr not having first item
  • If start and end are all omitted, returns string, itself
Parameters
start

A string for separating substring at the front.

If omitted, it's same with split(end) not having last item.

Parameters
end

A string for separating substring at the end.

If omitted, it's same with split(start) not having first item.

Returns
An array of substrings

Definition at line 548 of file WeakString.hpp.

References empty(), find(), npos, split(), and substring().

Referenced by samchon::library::StringUtil::betweens().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::trim ( const std::vector< std::string > &  delims) const -> WeakString
inline

Removes all designated characters from the beginning and end of the specified string.

Parameters
delimsDesignated character(s)
Returns
Updated string where designated characters was removed from the beginning and end

Definition at line 634 of file WeakString.hpp.

auto samchon::WeakString::ltrim ( const std::vector< std::string > &  delims) const -> WeakString
inline

Removes all designated characters from the beginning of the specified string.

Parameters
delimsDesignated character(s)
Returns
Updated string where designated characters was removed from the beginning

Definition at line 645 of file WeakString.hpp.

auto samchon::WeakString::rtrim ( const std::vector< std::string > &  delims) const -> WeakString
inline

Removes all designated characters from the end of the specified string.

Parameters
delimsDesignated character(s)
Returns
Updated string where designated characters was removed from the end

Definition at line 660 of file WeakString.hpp.

References data_, empty(), find(), samchon::IndexPair< T >::get_index(), samchon::IndexPair< T >::getValue(), samchon::library::Math::maximum(), samchon::library::Math::minimum(), rfind(), size(), size_, and str().

Here is the call graph for this function:

auto samchon::WeakString::replace ( const WeakString before,
const WeakString after 
) const -> std::string
inline

Replace portion of string once.

Parameters
beforeA specific word you want to be replaced
afterA specific word you want to replace
Returns
A string specific word is replaced once

Definition at line 740 of file WeakString.hpp.

References find(), size(), str(), and substr().

Here is the call graph for this function:

auto samchon::WeakString::replaceAll ( const WeakString before,
const WeakString after 
) const -> std::string
inline

Returns a string specified word is replaced.

Parameters
beforeA specific word you want to be replaced
afterA specific word you want to replace
Returns
A string specified word is replaced

Definition at line 763 of file WeakString.hpp.

Referenced by samchon::library::XML::clearProperties(), samchon::library::StringUtil::replaceAll(), replaceAll(), and samchon::library::StringUtil::substituteSQL().

Here is the caller graph for this function:

auto samchon::WeakString::replaceAll ( const std::vector< std::pair< std::string, std::string >> &  pairs) const -> std::string
inline

Returns a string specified words are replaced.

Parameters
strTarget string to replace
pairsA specific word's pairs you want to replace and to be replaced
Returns
A string specified words are replaced

Definition at line 775 of file WeakString.hpp.

References find(), replaceAll(), size(), str(), substr(), and substring().

Here is the call graph for this function:

auto samchon::WeakString::toLowerCase ( ) const -> std::string
inline

Convert uppercase letters to lowercase.

Returns a string that all uppercase characters are converted to lowercase.

Parameters
wstrTarget string to convert uppercase to lowercase
Returns
A string converted to lowercase

Definition at line 851 of file WeakString.hpp.

References str().

Referenced by samchon::library::StringUtil::toLowerCase().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::yoUpperCase ( ) const -> std::string
inline

Convert uppercase letters to lowercase.

Returns a string all lowercase characters are converted to uppercase.

Parameters
strTarget string to convert lowercase to uppercase
Returns
A string converted to uppercase

Definition at line 869 of file WeakString.hpp.

References at(), data_, size(), size_, and str().

Referenced by samchon::library::StringUtil::yoUpperCase().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::WeakString::str ( ) const -> std::string
inline

Get the string content.

Returns a string object with a copy of the current contents in the WeakString.

Returns
A new string copied from the WeakString

Definition at line 926 of file WeakString.hpp.

Referenced by samchon::protocol::WebServerConnector::connect(), samchon::protocol::InvokeParameter::InvokeParameter(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), rtrim(), samchon::library::XML::setProperty(), samchon::library::XML::setValue(), samchon::library::StringUtil::substituteSQL(), toLowerCase(), and yoUpperCase().

Here is the caller graph for this function:

Member Data Documentation

const std::vector<std::string> samchon::WeakString::SPACE_ARRAY
staticprivate

An array containing whitespaces.

Definition at line 41 of file WeakString.hpp.

const size_t samchon::WeakString::npos = -1
static

Maximum value for size_t.

npos is a static member constant value with the greatest possible value for an element of type size_t.

This value, when used as the value for a len (or sublen) parameter in string's member functions, means "until the end of the string". As a return value, it is usually used to indicate no matches.

This constant is defined with a value of -1, which because size_t is an unsigned integral type, it is the largest possible representable value for this type.

Definition at line 56 of file WeakString.hpp.

Referenced by betweens(), find(), and rfind().

const char* samchon::WeakString::data_
private

Referenced characters's pointer of begining position.

Definition at line 62 of file WeakString.hpp.

Referenced by data(), rtrim(), and yoUpperCase().

size_t samchon::WeakString::size_
private

(Specified) size of referenced characters

Definition at line 67 of file WeakString.hpp.

Referenced by find(), rtrim(), size(), substring(), and yoUpperCase().


The documentation for this class was generated from the following file: