sources/mystring.h

changeset 179
7fc34735178e
parent 158
de7574d292ad
child 182
20ca0a6be175
equal deleted inserted replaced
173:248fba6d1e76 179:7fc34735178e
35 #include "basics.h" 35 #include "basics.h"
36 #include "list.h" 36 #include "list.h"
37 37
38 BEGIN_ZFC_NAMESPACE 38 BEGIN_ZFC_NAMESPACE
39 39
40 using StringList = std::vector<class String>;
40 41
41 class String 42 class String
42 { 43 {
43 public: 44 public:
44 typedef std::string::iterator Iterator; 45 typedef std::string::iterator Iterator;
84 void removeFromStart(int length); 85 void removeFromStart(int length);
85 void replace(const char* text, const char* replacement); 86 void replace(const char* text, const char* replacement);
86 void replace(int position, int amount, const String &text); 87 void replace(int position, int amount, const String &text);
87 String right(int length) const; 88 String right(int length) const;
88 void shrinkToFit(); 89 void shrinkToFit();
89 class StringList split(const String &delimeter) const; 90 StringList split(const String &delimeter) const;
90 class StringList split(char delimeter) const; 91 StringList split(char delimeter) const;
91 void __cdecl sprintf(const char* fmtstr, ...); 92 void __cdecl sprintf(const char* fmtstr, ...);
92 bool startsWith(const String &other) const; 93 bool startsWith(const String &other) const;
93 const std::string& stdString() const; 94 const std::string& stdString() const;
94 void strip(char unwanted);
95 void strip(const List<char> &unwanted);
96 const unsigned char* toBytes() const; 95 const unsigned char* toBytes() const;
97 double toDouble(bool* ok = nullptr) const; 96 double toDouble(bool* ok = nullptr) const;
98 float toFloat(bool* ok = nullptr) const; 97 float toFloat(bool* ok = nullptr) const;
99 long toInt(bool* ok = nullptr, int base = 10) const; 98 long toInt(bool* ok = nullptr, int base = 10) const;
100 String toLowerCase() const; 99 String toLowerCase() const;
132 131
133 private: 132 private:
134 std::string m_string; 133 std::string m_string;
135 }; 134 };
136 135
137 136 String join_string_list(const StringList& strings, const String& delim);
138 class StringList : public List<String>
139 {
140 public:
141 StringList();
142 StringList(int numvalues);
143 StringList(const List<String>& other);
144 String join(const String& delim);
145 };
146
147 137
148 inline bool operator==(const char* a, const String& b); 138 inline bool operator==(const char* a, const String& b);
149 inline String operator+(const char* a, const String& b); 139 inline String operator+(const char* a, const String& b);
150 140
151 // -------------------------------------------------------------------------------------------------------------------- 141 // --------------------------------------------------------------------------------------------------------------------
559 */ 549 */
560 inline const unsigned char* String::toBytes() const 550 inline const unsigned char* String::toBytes() const
561 { 551 {
562 return reinterpret_cast<const unsigned char*>(chars()); 552 return reinterpret_cast<const unsigned char*>(chars());
563 } 553 }
564
565 /*!
566 * \brief Constructs an empty string list.
567 */
568 inline StringList::StringList() {}
569
570 /*!
571 * \brief Constructs a string list containing \c numvalues empty strings.
572 * \param numvalues Amount of empty strings to fill.
573 */
574 inline StringList::StringList(int numvalues) :
575 List<String>(numvalues) {}
576
577 /*!
578 * \brief Constructs a string list from another list of strings.
579 * \param other The list of strings to use for construction.
580 */
581 inline StringList::StringList(const List<String>& other) :
582 List<String>(other) {}
583 554
584 /*! 555 /*!
585 * \brief An \c operator== implementation that allows a char-array to be at the left side of a string comparison 556 * \brief An \c operator== implementation that allows a char-array to be at the left side of a string comparison
586 * with a \c String. 557 * with a \c String.
587 * \param one A char-array representation of a string to compare. 558 * \param one A char-array representation of a string to compare.

mercurial