sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::Strings Class Reference

#include <Strings.h>

Inheritance diagram for sptk::Strings:

Public Types

enum class  SortOrder : uint8_t { UNSORTED , ASCENDING , DESCENDING }
 
enum class  SplitMode : uint8_t { DELIMITER , ANYCHAR , REGEXP }
 

Public Member Functions

 Strings ()=default
 
 Strings (const Strings &other)=default
 
 Strings (Strings &&other)=default
 
 Strings (std::initializer_list< String > list)
 
 Strings (const String &src, const char *delimiter, SplitMode mode=SplitMode::DELIMITER) noexcept
 
virtual ~Strings ()=default
 
void fromString (const String &src, const char *delimiter, SplitMode mode)
 
virtual int indexOf (const String &needle) const
 
void saveToFile (const fs::path &fileName) const
 
void loadFromFile (const fs::path &fileName)
 
int64_t argument () const
 
void argument (int64_t d)
 
iterator remove (size_t i)
 
iterator remove (const String &str)
 
Stringsoperator= (const Strings &other)=default
 
Stringsoperator= (Strings &&other)=default
 
String join (const String &delimiter) const
 
Strings grep (const String &pattern) const
 
void sort (bool ascending=true)
 
void clear ()
 
void resize (size_t size)
 
void push_back (const String &str)
 
void push_back (String &&str)
 
template<typename... Args>
void emplace_back (Args &&... args)
 
Stringoperator[] (size_t index)
 
const Stringoperator[] (size_t index) const
 

Detailed Description

List of strings with ids

General string list. Based on vector<idstring>. Stores strings with (optional) integer Ids. Includes several extra methods to construct it from string or load/save from/to file.

Member Enumeration Documentation

◆ SortOrder

enum class sptk::Strings::SortOrder : uint8_t
strong

Sort order enumeration

◆ SplitMode

enum class sptk::Strings::SplitMode : uint8_t
strong

String split mode

Enumerator
DELIMITER 

Split by the whole delimiter

ANYCHAR 

Split by any char in delimiter

REGEXP 

Regular expression

Constructor & Destructor Documentation

◆ Strings() [1/5]

sptk::Strings::Strings ( )
default

Default constructor

◆ Strings() [2/5]

sptk::Strings::Strings ( const Strings other)
default

Copy constructor

◆ Strings() [3/5]

sptk::Strings::Strings ( Strings &&  other)
default

Move constructor

◆ Strings() [4/5]

sptk::Strings::Strings ( std::initializer_list< String list)
inline

Initializer list constructor

Parameters
listInitializer list

◆ Strings() [5/5]

sptk::Strings::Strings ( const String src,
const char *  delimiter,
SplitMode  mode = SplitMode::DELIMITER 
)
noexcept

Constructor from a string with elements separated by a delimiter string

Parameters
srcSource string
delimiterDelimiter string
modeDelimiter string usage

◆ ~Strings()

virtual sptk::Strings::~Strings ( )
virtualdefault

Destructor

Member Function Documentation

◆ argument() [1/2]

int64_t sptk::Strings::argument ( ) const
inline

Returns user data as integer

◆ argument() [2/2]

void sptk::Strings::argument ( int64_t  d)
inline

Sets user data as integer

Parameters
dNew value for user data

◆ clear()

void sptk::Strings::clear ( )
inline

Clear strings

◆ emplace_back()

template<typename... Args>
void sptk::Strings::emplace_back ( Args &&...  args)
inline

Emplace back a string

◆ fromString()

void sptk::Strings::fromString ( const String src,
const char *  delimiter,
SplitMode  mode 
)

Assigns strings from a string with elements separated by a delimiter string

Parameters
srcSource string
delimiterDelimiter string
modeDelimiter string usage

◆ grep()

Strings sptk::Strings::grep ( const String pattern) const

Returns strings matching regex pattern

Parameters
patternRegex pattern

◆ indexOf()

virtual int sptk::Strings::indexOf ( const String needle) const
virtual

Returns an index of the string in strings, or -1 if not found. If strings were sorted prior to calling this method, and not modified since that, then binary search is used.

Parameters
needleString to find
Returns
String index, or -1

◆ join()

String sptk::Strings::join ( const String delimiter) const

Returns concatenated string

Parameters
delimiterDelimiter

◆ loadFromFile()

void sptk::Strings::loadFromFile ( const fs::path &  fileName)

Loads strings from file. String ids are not loaded.

Parameters
fileNameThe name of the file

◆ operator[]() [1/2]

String & sptk::Strings::operator[] ( size_t  index)
inline

Index operator

Parameters
indexString index
Returns
string by the index

◆ operator[]() [2/2]

const String & sptk::Strings::operator[] ( size_t  index) const
inline

Index operator

Parameters
indexString index
Returns
string by the index

◆ push_back() [1/2]

void sptk::Strings::push_back ( const String str)
inline

Push back a string

Referenced by sptk::Tar::fileList().

◆ push_back() [2/2]

void sptk::Strings::push_back ( String &&  str)
inline

Push back a string

◆ remove() [1/2]

iterator sptk::Strings::remove ( const String str)
inline

Removes a string from this object

Parameters
strString to remove from the string vector

◆ remove() [2/2]

iterator sptk::Strings::remove ( size_t  i)
inline

Removes a string from this object

Parameters
iString index in the string vector

◆ resize()

void sptk::Strings::resize ( size_t  size)
inline

Change size of the collection

Parameters
sizeNew number of strings in the collection

◆ saveToFile()

void sptk::Strings::saveToFile ( const fs::path &  fileName) const

Saves strings to file. String ids are discarded.

Parameters
fileNameThe name of the file

◆ sort()

void sptk::Strings::sort ( bool  ascending = true)

Sort strings inside this object


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

Fri Oct 14 2022 09:58:45: SPTK 5.4.1