1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved. 2 * 3 * Use of this source code is governed by a zlib-style license that can 4 * be found in the License.txt file in the root of the source tree. 5 */ 6 7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 // 9 // More methods for std::vector<std::(w)string> 10 // 11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 12 13 //--------------------------------------------------------------------------- 14 #ifndef ZenLib_ZtringListH 15 #define ZenLib_ZtringListH 16 //--------------------------------------------------------------------------- 17 18 //--------------------------------------------------------------------------- 19 #include "ZenLib/Ztring.h" 20 #include <vector> 21 //--------------------------------------------------------------------------- 22 23 namespace ZenLib 24 { 25 26 //*************************************************************************** 27 /// @brief Vector of strings manipulation (based on std::vector<std::(w)string>) 28 //*************************************************************************** 29 30 class ZtringList : public std::vector<Ztring> 31 { 32 public : 33 //Constructors/destructor 34 ZtringList (); 35 ZtringList (const ZtringList &Source); 36 ZtringList (const Ztring &Source); 37 ZtringList (const Char *Source); 38 #ifdef _UNICODE 39 ZtringList (const char *Source); //convert a UTF-8 string into Unicode 40 #endif 41 42 //Operators 43 bool operator == (const ZtringList &Source) const; 44 bool operator != (const ZtringList &Source) const; 45 ZtringList &operator += (const ZtringList &Source); 46 ZtringList &operator = (const ZtringList &Source); 47 48 Ztring &operator () (size_type Pos); ///< Same as [], but write a empty string if Pos doesn't exist yet 49 50 //In/out 51 Ztring Read () const; /// Read all 52 const Ztring &Read (size_type Pos) const; /// Read a string 53 void Write (const Ztring &ToWrite); /// Write all 54 void Write (const Ztring &ToWrite, size_type Pos); /// Write a string 55 /// @brief Insert a string at position Pos0 Insert(const Ztring & ToInsert,size_type Pos0)56 void Insert (const Ztring &ToInsert, size_type Pos0) {insert(begin()+Pos0, ToInsert);} 57 /// @brief Delete a string at position Pos0 Delete(size_type Pos0)58 void Delete (size_type Pos0) {erase(begin()+Pos0);} 59 60 //Edition 61 /// @brief Swap 2 positions 62 void Swap (size_type Pos0_A, size_type Pos0_B); 63 /// @brief Sort 64 void Sort (ztring_t Options=Ztring_Nothing); 65 66 //Information 67 /// @brief Find the position of the string in the vector 68 size_type Find (const Ztring &ToFind, size_type PosBegin=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing) const; 69 /// @brief Return the length of the longest string in the list. 70 size_type MaxStringLength_Get (); 71 72 //Configuration 73 /// @brief Set the Separator character 74 void Separator_Set (size_type Level, const Ztring &NewSeparator); 75 /// @brief Set the Quote character 76 /// During Read() or Write() method, if Separator is in the sequence, we must quote it 77 void Quote_Set (const Ztring &NewQuote); 78 /// @brief Set the Maximum number of element to read 79 /// During Read() or Write() method, if there is more elements, merge them with the last element 80 void Max_Set (size_type Level, size_type Max_New); 81 82 protected : 83 Ztring Separator[1]; 84 Ztring Quote; 85 size_type Max[1]; 86 }; 87 88 } //namespace 89 #endif 90