Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
CStringArray.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * CStringArray.h
8  *
9  * @author: 2018 - Mikee47 <mike@sillyhouse.net>
10  *
11  ****/
12 
13 #ifndef _SMING_CORE_DATA_C_STRING_ARRAY_H_
14 #define _SMING_CORE_DATA_C_STRING_ARRAY_H_
15 
16 #include "WString.h"
17 
33 class CStringArray : protected String
34 {
35 public:
36  // Inherit all constructors
37  using String::String;
38 
44  bool add(const char* str, unsigned length = 0);
45 
50  bool add(const String& str)
51  {
52  return add(str.c_str(), str.length());
53  }
54 
60  int indexOf(const char* str) const;
61 
67  int indexOf(const String& str) const
68  {
69  return indexOf(str.c_str());
70  }
71 
77  bool contains(const char* str) const
78  {
79  return indexOf(str) >= 0;
80  }
81 
87  bool contains(const String& str) const
88  {
89  return indexOf(str) >= 0;
90  }
91 
96  const char* getValue(unsigned index) const;
97 
102  const char* operator[](unsigned index) const
103  {
104  return getValue(index);
105  }
106 
109  void clear()
110  {
111  invalidate();
112  stringCount = 0;
113  }
114 
118  unsigned count() const;
119 
120 private:
121  mutable unsigned stringCount = 0;
122 };
123 
124 #endif // _SMING_CORE_DATA_C_STRING_ARRAY_H_
unsigned count() const
Get quantity of strings in array.
void clear()
Empty the array.
Definition: CStringArray.h:109
bool contains(const char *str) const
Check if array contains a string.
Definition: CStringArray.h:77
int indexOf(const String &str) const
Find the given string and return its index.
Definition: CStringArray.h:67
The string class.
Definition: WString.h:104
const char * operator[](unsigned index) const
Get string at the given position.
Definition: CStringArray.h:102
const char * getValue(unsigned index) const
Get string at the given position.
bool add(const char *str, unsigned length=0)
Append a new string to the end of the array.
bool add(const String &str)
Append a new string to the end of the array.
Definition: CStringArray.h:50
bool contains(const String &str) const
Check if array contains a string.
Definition: CStringArray.h:87
Class to manage a double null-terminated list of strings, such as "one\0two\0three".
Definition: CStringArray.h:33
int indexOf(const char *str) const
Find the given string and return its index.