PStringList Class Reference

Detailed Description

The PStringList class represents a list of PString; NOT thread-safe.

Definition at line 26 of file PStringList.h.

#include <PStringList.h>

Constructor & Destructor Documentation

◆ PStringList() [1/3]

PStringList::PStringList ( )

Constructs an empty list of strings.

◆ PStringList() [2/3]

PStringList::PStringList ( const PString s0,
const PString s1 = PString::Empty(),
const PString s2 = PString::Empty(),
const PString s3 = PString::Empty(),
const PString s4 = PString::Empty(),
const PString s5 = PString::Empty(),
const PString s6 = PString::Empty(),
const PString s7 = PString::Empty(),
const PString s8 = PString::Empty(),
const PString s9 = PString::Empty() 
)

Constructs a list of strings from the specified arguments.

◆ PStringList() [3/3]

PStringList::PStringList ( const PStringList other)

Constructs a shared copy of other (copy-on-write).

◆ ~PStringList()

PStringList::~PStringList ( )

Destroys this object.

Member Function Documentation

◆ Add()

PStringList& PStringList::Add ( const PString s)

Adds the specified string to the end of this list.

Calls to Add() can be chained.

◆ AddAll()

PStringList& PStringList::AddAll ( const PStringList l)

Adds all the strings of the specified list to the end of this list.

◆ Clear()

void PStringList::Clear ( )

Clears this list of strings.

See also
IsEmpty()

◆ Clone()

PStringList PStringList::Clone ( ) const

Returns a deep copy of this object.

◆ Contains()

bool PStringList::Contains ( const PString s) const

Returns true if the list contains the specified string, false otherwise.

◆ Filter()

PStringList PStringList::Filter ( const PString regexp) const

Returns a list of all strings that match the specified Perl-like regular expression.

◆ FromTextFile()

static PResult PStringList::FromTextFile ( const PString textFilename,
PStringList l 
)
static

Builds a PStringList from a text file (reads the text file line by line).

If the specified list already contains some elements, then lines coming from the file are appended.

Returns PResult::C_OK if index is valid, something else otherwise.

◆ Get()

const PString& PStringList::Get ( const papillon::int32  index) const

Returns the string at the specified index or an unspecified string if the index is invalid.

Negative indices count backwards from the end of the list. Last element has index -1, second to last has index -2 etc.

◆ IsEmpty()

bool PStringList::IsEmpty ( ) const

Returns true if this list of strings is empty, false otherwise.

See also
Size()

◆ Join()

PString PStringList::Join ( const PString separator) const

Joins all the string list's strings into a single string with each element separated by the specified separator (which can be an empty string).

◆ operator!=()

bool PStringList::operator!= ( const PStringList other) const

Returns true if this PStringList is different from other; otherwise returns false.

Note: 2 PStringList are equal if they have exactly the same elements in the same order.

◆ operator=()

PStringList& PStringList::operator= ( const PStringList other)

Performs a shared copy of other to this object (copy-on-write).

◆ operator==()

bool PStringList::operator== ( const PStringList other) const

Returns true if this PStringList is equal to other; otherwise returns false.

Note: 2 PStringList are equal if they have exactly the same elements in the same order.

◆ RemoveAll()

PStringList& PStringList::RemoveAll ( const PString s)

Removes all occurrences of the specified string from this list.

Calls to RemoveAll() can be chained.

◆ RemoveDuplicates()

PStringList& PStringList::RemoveDuplicates ( )

Removes duplicate entries from a list.

The entries do not have to be sorted. They will retain their original order.

◆ RemoveFirst()

PStringList& PStringList::RemoveFirst ( )

Removes the first element of this list.

Do nothing if the list is empty. Calls to RemoveFirst() can be chained.

◆ RemoveLast()

PStringList& PStringList::RemoveLast ( )

Removes the last element of this list.

Do nothing if the list is empty. Calls to RemoveLast() can be chained.

◆ RemoveOne()

PStringList& PStringList::RemoveOne ( const PString s)

Removes the first occurrence of the specified string from this list.

Calls to RemoveOne() can be chained.

◆ Set()

PResult PStringList::Set ( const int32  index,
const PString s 
)

Sets the string at the specified index to the specified string if the index is valid.

Returns PResult::C_OK if index is valid, something else otherwise.

◆ Shuffled()

PStringList PStringList::Shuffled ( ) const

Returns a reordered copy of this list, such that each possible permutation of those elements has equal probability of appearance.

◆ Size()

papillon::int32 PStringList::Size ( ) const

Returns the number of strings in this list.

See also
IsEmpty()

◆ Sorted()

PStringList PStringList::Sorted ( ) const

Returns a sorted copy of this list, in ascending order.

Sorting is performed using the STL's std::sort() algorithm, which averages linear-logarithmic time, i.e. O(n log n).

◆ ToUpper()

PStringList PStringList::ToUpper ( ) const

Returns a copy of this list in which all elements have been converted to upper case.