libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
stringlist.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <promeki/core/string.h>
12#include <promeki/core/list.h>
13
15
21class StringList : public List<String> {
22 public:
23 using List::List;
24 using List::operator+=;
25 using List::operator=;
26
32 StringList(size_t ct, const char **list) {
33 reserve(ct);
34 for(size_t i = 0; i < ct; ++i) pushToBack(list[i]);
35 }
36
42 String join(const String& delimiter) const {
43 String result;
44 for(auto it = constBegin(); it != constEnd(); ++it) {
45 result += *it;
46 if(it + 1 != constEnd()) result += delimiter;
47 }
48 return result;
49 }
50
57 StringList result;
58 for(const auto &item : *this) {
59 if(func(item)) result.pushToBack(item);
60 }
61 return result;
62 }
63
69 int indexOf(const String &val) const {
70 for(size_t i = 0; i < size(); ++i) {
71 if((*this)[i] == val) return static_cast<int>(i);
72 }
73 return -1;
74 }
75
76};
77
79
Dynamic array container wrapping std::vector.
Definition list.h:40
ConstIterator constEnd() const noexcept
Returns a const iterator to one past the last element.
Definition list.h:213
ConstIterator constBegin() const noexcept
Returns a const iterator to the first element.
Definition list.h:173
void reserve(size_t newCapacity)
Pre-allocates storage for at least newCapacity elements.
Definition list.h:314
List()=default
Default constructor. Creates an empty list.
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
std::function< bool(const String &)> TestFunc
Predicate function type used by removeIf().
Definition list.h:62
void pushToBack(const String &value)
Pushes an item onto the back of the list.
Definition list.h:455
Manages a list of strings.
Definition stringlist.h:21
StringList(size_t ct, const char **list)
Constructs a StringList from a C-style string array.
Definition stringlist.h:32
int indexOf(const String &val) const
Returns the index of the first occurrence of a string, or -1 if not found.
Definition stringlist.h:69
String join(const String &delimiter) const
Joins all strings using the given delimiter.
Definition stringlist.h:42
List()=default
Default constructor. Creates an empty list.
StringList filter(TestFunc func) const
Returns a new StringList containing only strings that match the predicate.
Definition stringlist.h:56
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19