OpenStructure
Public Types | Public Member Functions
StringRef Class Reference

#include <string_ref.hh>

Inherited by LPadded, and RPadded.

Public Types

typedef char * iterator
 
typedef const char * const_iterator
 
typedef char value_type
 

Public Member Functions

 StringRef (const char *begin, size_t len)
 
 StringRef ()
 
const char * begin () const
 
const char * end () const
 
const char * data () const
 
size_t size () const
 
size_t length () const
 
char front () const
 
const_iterator find (char p) const
 
StringRef substr (size_t pos, size_t n=std::string::npos) const
 
std::string str () const
 
char back () const
 
const char & operator[] (int index) const
 
bool operator== (const StringRef &rhs) const
 
bool operator!= (const StringRef &rhs) const
 
StringRef rtrim () const
 
StringRef ltrim () const
 
StringRef trim () const
 
std::pair< bool, int > to_int () const
 
std::pair< bool, float > to_float () const
 
bool empty () const
 
std::vector< StringRefsplit (char p) const
 
std::vector< StringRefsplit () const
 
std::string str_no_whitespace () const
 

Detailed Description

convenient datatype for referencing character data

Note
it is not in general safe to store a StringRef as it does not guarantee that the character data it points to stays alive.

Definition at line 39 of file string_ref.hh.

Member Typedef Documentation

◆ const_iterator

typedef const char* const_iterator

Definition at line 43 of file string_ref.hh.

◆ iterator

typedef char* iterator

Definition at line 42 of file string_ref.hh.

◆ value_type

typedef char value_type

Definition at line 44 of file string_ref.hh.

Constructor & Destructor Documentation

◆ StringRef() [1/2]

StringRef ( const char *  begin,
size_t  len 
)
inline

Definition at line 46 of file string_ref.hh.

◆ StringRef() [2/2]

StringRef ( )
inline

Definition at line 47 of file string_ref.hh.

Member Function Documentation

◆ back()

char back ( ) const
inline

Definition at line 98 of file string_ref.hh.

◆ begin()

const char* begin ( ) const
inline

Definition at line 50 of file string_ref.hh.

◆ data()

const char* data ( ) const
inline

Definition at line 52 of file string_ref.hh.

◆ empty()

bool empty ( ) const
inline

Definition at line 146 of file string_ref.hh.

◆ end()

const char* end ( ) const
inline

Definition at line 51 of file string_ref.hh.

◆ find()

const_iterator find ( char  p) const
inline

find character in StringRef

Returns
iterator position when found, else iterator pointing to the end

Definition at line 65 of file string_ref.hh.

◆ front()

char front ( ) const
inline

Definition at line 57 of file string_ref.hh.

◆ length()

size_t length ( ) const
inline

Definition at line 55 of file string_ref.hh.

◆ ltrim()

StringRef ltrim ( ) const
inline

strip space characters on the left

Definition at line 122 of file string_ref.hh.

◆ operator!=()

bool operator!= ( const StringRef rhs) const
inline

Definition at line 111 of file string_ref.hh.

◆ operator==()

bool operator== ( const StringRef rhs) const
inline

Definition at line 106 of file string_ref.hh.

◆ operator[]()

const char& operator[] ( int  index) const
inline

Definition at line 104 of file string_ref.hh.

◆ rtrim()

StringRef rtrim ( ) const
inline

strip space characters on the right

Definition at line 115 of file string_ref.hh.

◆ size()

size_t size ( ) const
inline

Definition at line 54 of file string_ref.hh.

◆ split() [1/2]

std::vector<StringRef> split ( ) const

split string into chunks delimited by whitespace

◆ split() [2/2]

std::vector<StringRef> split ( char  p) const

split string into chunks delimited by p

◆ str()

std::string str ( ) const
inline

Definition at line 94 of file string_ref.hh.

◆ str_no_whitespace()

std::string str_no_whitespace ( ) const

returns a new string with all whitespace removed from this StringRef

◆ substr()

StringRef substr ( size_t  pos,
size_t  n = std::string::npos 
) const
inline

returns a substring of the string

Parameters
posthe starting position of the substring
nis the length of the string. if std::string::npos, the substring goes from pos to the end of the string The function does on purpose not perform any boundary check in release mode. It's the duty of the caller to make sure the string has the required length.

Definition at line 84 of file string_ref.hh.

◆ to_float()

std::pair<bool, float> to_float ( ) const

convert to float

Returns
a tuple with first set to true and second set to the float if the conversion succeeds. If the conversion fails, first is set to false.

◆ to_int()

std::pair<bool, int> to_int ( ) const

convert to integer

Returns
a tuple with first set to true and second set to the int if the conversion succeeds. If the conversion fails, first is set to false.

◆ trim()

StringRef trim ( ) const
inline

strip space characters on the left and the right

Definition at line 130 of file string_ref.hh.


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