All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringTool.h
Go to the documentation of this file.
1 /*
2  * StringTool.h
3  *
4  * This file is part of the HausmiSEP project
5  *
6  * Copyright (C) 2012, 2013 Marco Alvarado (malvcr@gmail.com)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef STRINGTOOL_H_
23 #define STRINGTOOL_H_
24 
25 #include <HSEP/Dictionary.h>
26 #include <HSEP/Array.h>
27 #include <HSEP/ErrorCode.h>
28 
29 using namespace std;
30 
31 namespace HSEP {
32 
33 #define MAXTOKEN_SIZE 128
34 #define MAXVALUE_SIZE 512
36 const char HEXVALUES[22] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'};
37 
41 const char REVHEX[256] =
42 {
43  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
44  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
45  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 -
46  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, // 48 - 63 // NUMBERS (0 ... 9)
47  0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 64 - 79 // UPPERCASE (A ... F)
48  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // - 95
49  0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 96 - 111 // LOWERCASE (a ... f)
50  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // - 127
51  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128 -
52  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // - 159
53  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 -
54  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // - 191
55  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192 -
56  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // - 223
57  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224 -
58  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // - 255
59 };
60 
64  class StringTool {
65  public:
83  static ErrorCode split(char* pSourcePtr, const char* pSepLevelsPtr, StringDictionary& pDestRef);
84 
95  static ErrorCode split(string& pSourceRef, const string pSeparator, StringArray& pDestRef);
96 
97  static ErrorCode toHex(void* pSource,size_t pSize,string& pDestination);
98 
99  static ErrorCode fromHex(string& pSource, void* pDestination, size_t pDestinationSize);
100 
108  static ErrorCode ltrim(string& pStringRef);
109 
117  static ErrorCode drop(string& pStringRef, const char* pDropHead);
118 
119  }; // StringTool class
120 
121 } // HSEP namespace
122 
123 #endif /* STRINGTOOL_H_ */