CsString  1.3.2
CsString::CsBasicStringView< S > Class Template Reference

Templated class for read only access to a string. More...

Public Typedefs

using const_iterator = typename S::const_iterator
 
using const_reverse_iterator = typename S::const_reverse_iterator
 
using iterator = typename S::const_iterator
 
using reverse_iterator = typename S::const_reverse_iterator
 
using size_type = typename S::difference_type
 

Public Member Functions

 CsBasicStringView () = default
 
 CsBasicStringView (const S &str)
 
 CsBasicStringView (const_iterator begin, const_iterator end)
 
value_type at (size_type index) const
 
value_type back () const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
int compare (CsBasicStringView< S > str) const
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
bool endsWith (CsBasicStringView< S > str) const
 
const_iterator find_fast (const char (&str)[N]) const
 
const_iterator find_fast (const char (&str)[N], const_iterator iter_begin) const
 
const_iterator find_fast (const char (&str)[N], const_iterator iter_begin, size_type size) const
 
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator find_fast (const T &str) const
 
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator find_fast (const T &str, const_iterator iter_begin) const
 
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator find_fast (const T &str, const_iterator iter_begin, size_type size) const
 
const_iterator find_fast (CsBasicStringView< S > str) const
 
const_iterator find_fast (CsBasicStringView< S > str, const_iterator iter_begin) const
 
const_iterator find_fast (value_type c) const
 
const_iterator find_fast (value_type c, const_iterator iter_begin) const
 
value_type front () const
 
size_type length () const
 
CsBasicStringView< S > & operator= (const CsBasicStringView< S > &str) = default
 
CsBasicStringView< S > & operator= (CsBasicStringView< S > &&str) = default
 
value_type operator[] (size_type index) const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
CsBasicStringView< S > remove_prefix (size_type size) const
 
CsBasicStringView< S > remove_suffix (size_type size) const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_iterator rfind_fast (CsBasicStringView< S > str) const
 
const_iterator rfind_fast (CsBasicStringView< S > str, const_iterator iter_end) const
 
size_type size () const
 
bool startsWith (CsBasicStringView< S > str) const
 
CsBasicStringView< S > substr (size_type indexStart=0, size_type size=npos) const
 
void swap (CsBasicStringView< S > &str)
 

Related Functions

These are not member functions

bool operator!= (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 
bool operator< (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 
bool operator<= (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 
bool operator== (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 
bool operator> (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 
bool operator>= (CsBasicStringView< S > &str1, CsBasicStringView< S > &str2)
 

Detailed Description

template<typename S>
class CsString::CsBasicStringView< S >

The CsBasicStringView class is a templated class which provides read only access to a CsBasicString. The template parameter indicates the string data type which is passed to the CsBasicStringView template.

A CsBasicStringView is a view of a particular type of string. The encoding is defined by the type of string. For example, a CsBasicStringView<CsBasicString<utf8>> is a view of a CsBasicString<utf8>.

The following typedefs are provided for convenience.

using CsStringView = CsBasicStringView<CsBasicString<utf8>>;
using CsStringView_utf8 = CsBasicStringView<CsBasicString<utf8>>;
using CsStringView_utf16 = CsBasicStringView<CsBasicString<utf16>>;

For additional information about CsBasicString refer to Why CsString was Created.

For information about character encoding, code points, and Unicode refer to String Terminology.

Member Typedef Documentation

template<typename S>
CsBasicStringView::const_iterator

Provides an STL style const iterator for string view.

Provides an STL style const reverse iterator for string view.

template<typename S>
CsBasicStringView::iterator

Provides an STL style const iterator for string view.

Provides an STL style non-const reverse iterator for string view.

template<typename S>
CsBasicStringView::size_type

Typedef for an integer type representing sizes in a string view.

Constructor & Destructor Documentation

template<typename S>
CsString::CsBasicStringView< S >::CsBasicStringView ( )
inlinedefault

Constructs an empty CsBasicStringView.

template<typename S>
CsString::CsBasicStringView< S >::CsBasicStringView ( const S &  str)
inline

Constructs a CsBasicStringView from the string str.

template<typename S>
CsString::CsBasicStringView< S >::CsBasicStringView ( const_iterator  begin,
const_iterator  end 
)
inline

Constructs a CsBasicStringView using the specified iterator range.

Member Function Documentation

template<typename S>
CsChar CsBasicStringView::at ( size_type  index) const

Returns the code point at position index in this CsBasicStringView. The behavior of this method is undefined if index is negative or if index is equal to or greater than the size() of the string view.

See also
operator[]().
template<typename S>
CsChar CsBasicStringView::back ( ) const

Returns the last code point in this CsBasicStringView. The behavior of this method is undefined if the string view is empty.

See also
front().
template<typename S>
iterator CsString::CsBasicStringView< S >::begin ( )
inline

Returns an iterator to the first code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::begin ( ) const
inline

Returns a const iterator to the first code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::cbegin ( ) const
inline

Returns a const iterator to the first code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::cend ( ) const
inline

Returns a const iterator to the element after the last code point of this CsBasicStringView.

template<typename S>
int CsString::CsBasicStringView< S >::compare ( CsBasicStringView<S>  str) const

Lexically compares this string with the string view str.

  • Returns -1 if this string is less than str
  • Returns 0 if this string is equal to str
  • Returns 1 if this string is greater than str
template<typename S>
const_iterator CsString::CsBasicStringView< S >::constBegin ( ) const
inline

Returns a const iterator to the first code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::constEnd ( ) const
inline

Returns a const iterator to the element after the last code point of this CsBasicStringView.

template<typename S>
const_reverse_iterator CsString::CsBasicStringView< S >::crbegin ( ) const
inline

Returns a const iterator to the last code point of this CsBasicStringView.

template<typename S>
const_reverse_iterator CsString::CsBasicStringView< S >::crend ( ) const
inline

Returns a const iterator to the element before the first code point of this CsBasicStringView.

template<typename S>
bool CsBasicStringView::empty ( ) const

Returns true if this CsBasicStringView is empty.

template<typename S>
iterator CsString::CsBasicStringView< S >::end ( )
inline

Returns a iterator to the element after the last code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::end ( ) const
inline

Returns a const iterator to the element after the last code point of this CsBasicStringView

template<typename S>
bool CsBasicStringView::endsWith ( CsBasicStringView<S>  str) const

Returns true if this string view ends with the string view str, otherwise returns false.

See also
startsWith().
template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const char (&  str)[N]) const

Find the specified string literal str in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const char (&  str)[N],
const_iterator  iter_begin 
) const

Find the specified string literal str in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const char (&  str)[N],
const_iterator  iter_begin,
size_type  size 
) const

Find the specified string literal str in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView. Only the first size number of code points of str are searched.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const T &  str) const

Find the specified C style string str in this CsBasicStringView.

This method is only permitted if CS_STRING_ALLOW_UNSAFE is defined.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const T &  str,
const_iterator  iter_begin 
) const

Find the specified C style string str in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView.

This method is only permitted if CS_STRING_ALLOW_UNSAFE is defined.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
template<typename T, typename = typename std::enable_if<std::is_same<T, const char *>::value || std::is_same<T, char *>::value>::type>
const_iterator CsString::CsBasicStringView< S >::find_fast ( const T &  str,
const_iterator  iter_begin,
size_type  size 
) const

Find the specified C style string str in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView. Only the first size number of code points of str are searched.

This method is only permitted if CS_STRING_ALLOW_UNSAFE is defined.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( CsBasicStringView<S>  str) const

Find the specified CsBasicStringView str in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( CsBasicStringView<S>  str,
const_iterator  iter_begin 
) const

Find the specified CsBasicStringView str in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( value_type  c) const

Find the specified CsChar c in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::find_fast ( value_type  c,
const_iterator  iter_begin 
) const

Find the specified CsChar c in this CsBasicStringView. Begin searching from iter_begin in this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
size_type CsBasicStringView::front ( ) const

Returns the first code point in this CsBasicStringView. The behavior of this method is undefined if the string view is empty.

See also
back().
template<typename S>
size_type CsBasicStringView::length ( ) const

Returns the number of code points in this CsBasicStringView. Returns the same result as size().

template<typename S>
CsBasicStringView< S > & CsString::CsBasicStringView< S >::operator= ( const CsBasicStringView<S> &  str)
inlinedefault

Assigns the string view str to this CsBasicStringView.

Returns a reference to this CsBasicStringView.

template<typename S>
CsBasicStringView< S > & CsString::CsBasicStringView< S >::operator= ( CsBasicStringView<S> &&  str)
inlinedefault

Move assigns the string view str to this CsBasicStringView.

Returns a reference to this CsBasicStringView.

template<typename S>
CsChar CsBasicStringView::operator[] ( size_type  index) const

Returns the code point at position index in this CsBasicStringView. The behavior of this method is undefined if index is negative or if index is equal to or greater than the size() of the string view.

See also
at().
template<typename S>
reverse_iterator CsString::CsBasicStringView< S >::rbegin ( )
inline

Returns a iterator to the last code point of this CsBasicStringView.

template<typename S>
const_reverse_iterator CsString::CsBasicStringView< S >::rbegin ( ) const
inline

Returns a const iterator to the last code point of this CsBasicStringView.

template<typename S>
CsBasicStringView CsBasicStringView::remove_prefix ( size_type  size) const

Moves the start of CsBasicStringView forward by size code points.

template<typename S>
CsBasicStringView CsBasicStringView::remove_suffix ( size_type  size) const

Moves the end of CsBasicStringView backward by size code points.

template<typename S>
reverse_iterator CsString::CsBasicStringView< S >::rend ( )
inline

Returns a iterator to the element before the first code point of this CsBasicStringView.

template<typename S>
const_reverse_iterator CsString::CsBasicStringView< S >::rend ( ) const
inline

Returns a const iterator to the element before the first code point of this CsBasicStringView.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::rfind_fast ( CsBasicStringView<S>  str) const

Find the specified CsBasicStringView str in this CsBasicStringView, searching is from the end towards the beginning of this CsBasicStringView.

Returns an iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
const_iterator CsString::CsBasicStringView< S >::rfind_fast ( CsBasicStringView<S>  str,
const_iterator  iter_end 
) const

Find the specified CsBasicStringView str in this CsBasicStringView. Begin searching from iter_begin, searching is from the end towards the beginning of this CsBasicStringView.

Returns and iterator to the first code point of the match. Returns an iterator to the end of the string view if no match is found.

template<typename S>
size_type CsBasicStringView::size ( ) const

Returns the number of code points in this CsBasicStringView. Returns the same result as length().

template<typename S>
bool CsBasicStringView::startsWith ( CsBasicStringView<S>  str) const

Returns true if this string view starts with the string view str, otherwise returns false.

See also
endsWith().
template<typename S>
CsBasicStringView CsBasicStringView::substr ( size_type  indexStart = 0,
size_type  size = npos 
) const

Returns a string view containing the code points starting at the specified indexStart position for size number of code points.

Returns an empty string view if the indexStart exceeds the length of the string view. If there are less than size code points available in the string view, starting at the given indexStart, or if size is equal to npos, the method returns all of the code points available from the specified indexStart to the end of the string view.

template<typename S>
void CsBasicStringView::swap ( CsBasicStringView<S> &  str)

Swaps the string view str with this CsBasicStringView.

Friends And Related Function Documentation

bool operator!= ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically not equal to string view str2.

See also
compare()
bool operator< ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically less than string view str2.

See also
compare()
bool operator<= ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically less than or equal to string view str2.

See also
compare()
bool operator== ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically equal to string view str2.

See also
compare()
bool operator> ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically greater than string view str2.

See also
compare()
bool operator>= ( CsBasicStringView< S > &  str1,
CsBasicStringView< S > &  str2 
)
related

Returns true if string view str1 is lexically greater than or equal to string view str2.

See also
compare()