OTB  9.0.0
Orfeo Toolbox
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
otb::string_view Struct Reference

#include <otbStringUtilities.h>

+ Collaboration diagram for otb::string_view:

Classes

struct  build_empty
 
struct  char_iterator
 

Public Types

typedef char_iterator const_iterator
 
typedef char const * const_pointer
 
typedef char const & const_reference
 
typedef std::reverse_iterator< char_iteratorconst_reverse_iterator
 
typedef char const * pointer
 
typedef char const & reference
 
typedef std::vcl_size_t size_type
 
typedef const char value_type
 

Public Member Functions

template<std::vcl_size_t N>
 string_view (char const (&array)[N])
 
 string_view (char const *ptr)
 
template<typename II >
 string_view (II first, II last)
 
template<typename II >
 string_view (II first, size_type size_)
 
 string_view (std::string const &s)
 

Static Public Member Functions

static string_view null ()
 
std::vcl_size_t m_size
 
const_iterator m_first
 
bool belongs_to (char const *first, char const *last) const
 
template<std::vcl_size_t N>
bool belongs_to (char const (&array)[N]) const
 
bool belongs_to (char const *ptr) const
 
template<typename String >
bool belongs_to (String const &s) const
 
size_type size () const
 
bool empty () const
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
const_reference operator[] (size_type p)
 
const_reference front () const
 
const_reference back () const
 
const_pointer data () const
 
void remove_prefix (std::vcl_size_t n)
 
void remove_suffix (std::vcl_size_t n)
 
 string_view (build_empty)
 

Detailed Description

String view class. Class inspired by C++17 std::string_view and gsl::string_span.

This idea is to bring efficiency and correctness to C++ functions that take strings. A function that receives a string_view can receive any kind of string flavour and guarantee 0-copy.

The only side effect to be aware of: no terminal-0 is to be expected. i.e. a string_view data cannot be passed freely to a function with a C API that expect a null-terminated string.

Invariant
there is no guarantee ‘data()[size()] == ’\0'`. It may happen though depending on the constructor used.

Definition at line 58 of file otbStringUtilities.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 114 of file otbStringUtilities.h.

◆ const_pointer

typedef char const* otb::string_view::const_pointer

Definition at line 63 of file otbStringUtilities.h.

◆ const_reference

typedef char const& otb::string_view::const_reference

Definition at line 62 of file otbStringUtilities.h.

◆ const_reverse_iterator

Definition at line 116 of file otbStringUtilities.h.

◆ pointer

typedef char const* otb::string_view::pointer

Definition at line 64 of file otbStringUtilities.h.

◆ reference

typedef char const& otb::string_view::reference

Definition at line 61 of file otbStringUtilities.h.

◆ size_type

typedef std::vcl_size_t otb::string_view::size_type

Definition at line 65 of file otbStringUtilities.h.

◆ value_type

typedef const char otb::string_view::value_type

Definition at line 60 of file otbStringUtilities.h.

Constructor & Destructor Documentation

◆ string_view() [1/6]

otb::string_view::string_view ( std::string const &  s)
inline

Constructor from a standard string.

Postcondition
data()[size()] == ’\0'`

Definition at line 121 of file otbStringUtilities.h.

Referenced by null().

◆ string_view() [2/6]

template<std::vcl_size_t N>
otb::string_view::string_view ( char const (&)  array[N])
inline

Constructor from an array of characters.

Postcondition
data()[size()] == ’\0'<= the array is built with this kind of syntax:char const a[]="foobar";`

Definition at line 130 of file otbStringUtilities.h.

◆ string_view() [3/6]

otb::string_view::string_view ( char const *  ptr)
inline

Constructor from a pointer to a 0-terminated raw string.

Postcondition
data()[size()] == ’\0'`

Definition at line 137 of file otbStringUtilities.h.

◆ string_view() [4/6]

template<typename II >
otb::string_view::string_view ( II  first,
size_type  size_ 
)
inline

Constructor from an input iterator and a size.

Postcondition
there is no guarantee ‘data()[size()] == ’\0'`.

Definition at line 152 of file otbStringUtilities.h.

◆ string_view() [5/6]

template<typename II >
otb::string_view::string_view ( II  first,
II  last 
)
inline

Constructor from a pair of input iterators.

Postcondition
there is no guarantee ‘data()[size()] == ’\0'`.

Definition at line 160 of file otbStringUtilities.h.

◆ string_view() [6/6]

otb::string_view::string_view ( build_empty  )
inlineprivate

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 246 of file otbStringUtilities.h.

Member Function Documentation

◆ back()

const_reference otb::string_view::back ( ) const
inline

Returns last character of the view.

Precondition
!empty(), checked with an assertion.

Definition at line 224 of file otbStringUtilities.h.

References empty(), and end().

◆ begin()

const_iterator otb::string_view::begin ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 195 of file otbStringUtilities.h.

References m_first.

Referenced by belongs_to(), otb::find(), front(), otb::is_same_view(), otb::splitter_on_delim::operator()(), otb::operator+(), otb::operator<<(), otb::operator==(), otb::starts_with(), otb::to< std::string >(), otb::details::to_integer(), and otb::details::to_uinteger().

◆ belongs_to() [1/4]

template<std::vcl_size_t N>
bool otb::string_view::belongs_to ( char const (&)  array[N]) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 177 of file otbStringUtilities.h.

References belongs_to().

◆ belongs_to() [2/4]

bool otb::string_view::belongs_to ( char const *  first,
char const *  last 
) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 173 of file otbStringUtilities.h.

References begin(), and end().

Referenced by belongs_to(), otb::find(), and otb::part_iterator< Splitter >::operator++().

◆ belongs_to() [3/4]

bool otb::string_view::belongs_to ( char const *  ptr) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 181 of file otbStringUtilities.h.

References belongs_to().

◆ belongs_to() [4/4]

template<typename String >
bool otb::string_view::belongs_to ( String const &  s) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 185 of file otbStringUtilities.h.

References belongs_to().

◆ cbegin()

const_iterator otb::string_view::cbegin ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 197 of file otbStringUtilities.h.

References m_first.

◆ cend()

const_iterator otb::string_view::cend ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 198 of file otbStringUtilities.h.

References m_first, and m_size.

◆ crbegin()

const_reverse_iterator otb::string_view::crbegin ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 204 of file otbStringUtilities.h.

References m_first, and m_size.

◆ crend()

const_reverse_iterator otb::string_view::crend ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 205 of file otbStringUtilities.h.

References m_first.

◆ data()

const_pointer otb::string_view::data ( ) const
inline

Returns a pointer to the first character of the view.

Warning
there is no guarantee ‘data()[size()] == ’\0'`

Definition at line 229 of file otbStringUtilities.h.

References m_first.

◆ empty()

bool otb::string_view::empty ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 191 of file otbStringUtilities.h.

References m_size.

Referenced by back(), otb::details::decode_uint(), otb::find(), front(), and otb::details::to_float().

◆ end()

const_iterator otb::string_view::end ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 196 of file otbStringUtilities.h.

References m_first, and m_size.

Referenced by back(), belongs_to(), otb::find(), otb::Wrapper::LearningApplicationBase< TInputValue, TOutputValue >::GetClassifierCategory(), otb::splitter_on_delim::operator()(), otb::operator+(), otb::part_iterator< Splitter >::operator++(), otb::operator<<(), otb::operator==(), otb::starts_with(), otb::to< std::string >(), otb::details::to_integer(), and otb::details::to_uinteger().

◆ front()

const_reference otb::string_view::front ( ) const
inline

Returns first character of the view.

Precondition
!empty(), checked with an assertion.

Definition at line 219 of file otbStringUtilities.h.

References begin(), and empty().

Referenced by otb::details::decode_uint().

◆ null()

static string_view otb::string_view::null ( )
inlinestatic

Builds a peculiar empty view to points to nullptr.

Definition at line 167 of file otbStringUtilities.h.

References string_view().

Referenced by otb::contains(), otb::find(), and otb::part_iterator< Splitter >::operator++().

◆ operator[]()

const_reference otb::string_view::operator[] ( size_type  p)
inline

Indexed access.

Precondition
p < size(), checked with an assertion.

Definition at line 210 of file otbStringUtilities.h.

References m_first, and size().

◆ rbegin()

const_reverse_iterator otb::string_view::rbegin ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 202 of file otbStringUtilities.h.

References m_first, and m_size.

Referenced by otb::ends_with().

◆ remove_prefix()

void otb::string_view::remove_prefix ( std::vcl_size_t  n)
inline

Removes the n first characters.

Precondition
n <= size(), checked with an assertion
Postcondition
size is n characters more little
begin() iterator is n characters right.

Definition at line 236 of file otbStringUtilities.h.

References m_first, and m_size.

Referenced by otb::details::decode_uint().

◆ remove_suffix()

void otb::string_view::remove_suffix ( std::vcl_size_t  n)
inline

Removes the n last characters.

Precondition
n <= size(), checked with an assertion
Postcondition
size is n characters more little
end() iterator is n characters left.

Definition at line 243 of file otbStringUtilities.h.

References m_size.

◆ rend()

const_reverse_iterator otb::string_view::rend ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 203 of file otbStringUtilities.h.

References m_first.

Referenced by otb::ends_with().

◆ size()

size_type otb::string_view::size ( ) const
inline

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 190 of file otbStringUtilities.h.

References m_size.

Referenced by otb::ends_with(), otb::find(), otb::is_same_view(), otb::operator==(), operator[](), and otb::starts_with().

Member Data Documentation

◆ m_first

const_iterator otb::string_view::m_first
private

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 250 of file otbStringUtilities.h.

Referenced by begin(), cbegin(), cend(), crbegin(), crend(), data(), end(), operator[](), rbegin(), remove_prefix(), and rend().

◆ m_size

std::vcl_size_t otb::string_view::m_size
private

Tells whether a view is within another view. This functions doesn't test whether the characters from a view are found in the same relative positions in another view.

Definition at line 249 of file otbStringUtilities.h.

Referenced by cend(), crbegin(), empty(), end(), rbegin(), remove_prefix(), remove_suffix(), and size().


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