sources/mystring.h

changeset 87
53c2aecb9704
parent 83
08bfc3d9d2ae
child 88
08ccaf26cffd
equal deleted inserted replaced
86:3c02a728a681 87:53c2aecb9704
92 bool ends_with (const String &other); 92 bool ends_with (const String &other);
93 int index_difference (int a, int b) { modify_index (a); modify_index (b); return b - a; } 93 int index_difference (int a, int b) { modify_index (a); modify_index (b); return b - a; }
94 void insert (int pos, char c) { m_string.insert (m_string.begin() + pos, c); } 94 void insert (int pos, char c) { m_string.insert (m_string.begin() + pos, c); }
95 void insert (int pos, const char*c) { m_string.insert (pos, c); } 95 void insert (int pos, const char*c) { m_string.insert (pos, c); }
96 void modify_index (int &a) { if (a < 0) { a = length() - a; } } 96 void modify_index (int &a) { if (a < 0) { a = length() - a; } }
97 void normalize (int (*filter)(int) = &std::isspace); 97 void normalize (int (*filter)(int) = &isspace);
98 void prepend (String a) { m_string = (a + m_string).std_string(); } 98 void prepend (String a) { m_string = (a + m_string).std_string(); }
99 void remove (int pos, int len) { m_string.replace (pos, len, ""); } 99 void remove (int pos, int len) { m_string.replace (pos, len, ""); }
100 void remove_at (int pos) { m_string.erase (m_string.begin() + pos); } 100 void remove_at (int pos) { m_string.erase (m_string.begin() + pos); }
101 void remove_from_end (int len) { remove (length() - len, len); } 101 void remove_from_end (int len) { remove (length() - len, len); }
102 void remove_from_start (int len) { remove (0, len); } 102 void remove_from_start (int len) { remove (0, len); }
143 // ------------------------------------------------------------------------------------------------- 143 // -------------------------------------------------------------------------------------------------
144 // 144 //
145 class StringList : public List<String> 145 class StringList : public List<String>
146 { 146 {
147 public: 147 public:
148 using Super = List<String>; 148 typedef List<String> Super;
149 using Super::Super;
150 149
151 StringList() {} 150 StringList() {}
151
152 StringList (int numvalues) :
153 Super (numvalues) {}
152 154
153 StringList (const Super& other) : 155 StringList (const Super& other) :
154 Super (other) {} 156 Super (other) {}
155 157
156 String join (const String& delim); 158 String join (const String& delim);

mercurial