|
0
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
* This component and the accompanying materials are made available
|
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
|
6 |
* which accompanies this distribution, and is available
|
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
8 |
*
|
|
|
9 |
* Initial Contributors:
|
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
|
11 |
*
|
|
|
12 |
* Contributors:
|
|
|
13 |
*
|
|
|
14 |
* Description:
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
#ifndef __UTILS_H__
|
|
|
20 |
#define __UTILS_H__
|
|
|
21 |
|
|
|
22 |
#ifdef __WIN__
|
|
|
23 |
#pragma warning(disable:4786)
|
|
|
24 |
#endif
|
|
|
25 |
|
|
|
26 |
#include <stdio.h>
|
|
|
27 |
#include <string>
|
|
|
28 |
#include <list>
|
|
|
29 |
#include <map>
|
|
|
30 |
#include <vector>
|
|
|
31 |
#include <stdarg.h>
|
|
|
32 |
|
|
|
33 |
using namespace std;
|
|
|
34 |
|
|
|
35 |
#define _X(s) XMLString::transcode(s)
|
|
|
36 |
#define _XX(s) XMLString::release(&s)
|
|
|
37 |
|
|
|
38 |
#define __FUN_MANGLED__ "__MANGLED__"
|
|
|
39 |
|
|
|
40 |
// Mostly used for implementation of headeranalyser
|
|
|
41 |
enum TValue
|
|
|
42 |
{
|
|
|
43 |
ELeftValue = 0,
|
|
|
44 |
ERightValue
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
// Used for implementation of testing program for headeranalyser
|
|
|
48 |
const string KEmpty = "_DEADBEEF_DEADBEEF_";
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Convert integer to string
|
|
|
53 |
* @param value value to convert
|
|
|
54 |
* @param str reference to string where to convert
|
|
|
55 |
* @param radix numeric base into which to convert
|
|
|
56 |
* @return number converted to string
|
|
|
57 |
*/
|
|
|
58 |
string itoa(int value, string& str, int radix);
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Convert long to string
|
|
|
62 |
* @param value value to convert
|
|
|
63 |
* @param str reference to string where to convert
|
|
|
64 |
* @param radix numeric base into which to convert
|
|
|
65 |
* @return number converted to string
|
|
|
66 |
*/
|
|
|
67 |
string ltoa(long value, string& str, int radix);
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Find from list
|
|
|
71 |
* @param aValue value to find
|
|
|
72 |
* @param aList where to find
|
|
|
73 |
* @param comparator comparator funtion
|
|
|
74 |
* @param comparatorparam true, if comparator is used
|
|
|
75 |
* @return string list
|
|
|
76 |
*/
|
|
|
77 |
list<string>::iterator FindFromList(const string& aValue, list<string>& aList, bool(*comparator)(const string&,const string&,bool)=0, bool comparatorparam=true);
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Find from list of paired string
|
|
|
81 |
* @param aValue value to find
|
|
|
82 |
* @param aList where to find
|
|
|
83 |
* @param comparator comparator funtion
|
|
|
84 |
* @param comparatorparam true, if comparator is used
|
|
|
85 |
* @return string list
|
|
|
86 |
*/
|
|
|
87 |
list<pair<string, string> >::iterator FindFromList(const string& aValue, list<pair<string,string> >& aList, bool(*comparator)(const string&,const string&,bool)=0, bool comparatorparam=true);
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Find from list
|
|
|
91 |
* @param aValue value to find
|
|
|
92 |
* @param aList where to find
|
|
|
93 |
* @param compareTo compare left or right value
|
|
|
94 |
* @param comparator comparator funtion
|
|
|
95 |
* @param comparatorparam true, if comparator is used
|
|
|
96 |
* @return string list
|
|
|
97 |
*/
|
|
|
98 |
list<pair<string, string> >::iterator FindFromList(const string& aValue, list<pair<string, string> >& aList, TValue compareTo, bool(*comparator)(const pair<string,string>&, const string&,bool)=0, bool comparatorparam=true, bool comparewholeString=false);
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Find from list of paired string
|
|
|
102 |
* @param aValue value to find
|
|
|
103 |
* @param aList where to find
|
|
|
104 |
* @param compareTo compare left or right value
|
|
|
105 |
* @param comparator comparator funtion
|
|
|
106 |
* @param comparatorparam true, if comparator is used
|
|
|
107 |
* @return string list
|
|
|
108 |
*/
|
|
|
109 |
list<pair<pair<string, string>,string> >::iterator FindFromList(const string& aValue, list<pair<pair<string, string>,string> >& aList, TValue compareTo, bool(*comparator)(const pair<string,string>&, const string&,bool)=0, bool comparatorparam=true, bool comparewholeString=false);
|
|
|
110 |
/**
|
|
|
111 |
* Convert integer to string
|
|
|
112 |
* @param aString string to convert
|
|
|
113 |
* @return lowercase string
|
|
|
114 |
*/
|
|
|
115 |
string toLowerCaseWin(string aString);
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Convert integer to string
|
|
|
119 |
* @param aString string to convert
|
|
|
120 |
* @return lowercase string
|
|
|
121 |
*/
|
|
|
122 |
string toLowerCase(string aString);
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* Convert integer to string
|
|
|
126 |
* @param aString string to convert
|
|
|
127 |
* @return uppercase string
|
|
|
128 |
*/
|
|
|
129 |
string toUpperCase(string aString);
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* Compare files
|
|
|
133 |
* @param tocompare to which to compare
|
|
|
134 |
* @param comparestr what to compare
|
|
|
135 |
* @param tryfilename if this is true, bare filenames are compared to each other
|
|
|
136 |
* @return true if match found
|
|
|
137 |
*/
|
|
|
138 |
bool compareFiles(const string& tocompare, const string& comparestr, bool tryfilename = true);
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
* Compare files
|
|
|
142 |
* @param tocompare to which to compare
|
|
|
143 |
* @param comparestr what to compare
|
|
|
144 |
* @param tryfilename if this is true, bare filenames are compared to each other
|
|
|
145 |
* @return true if match found
|
|
|
146 |
*/
|
|
|
147 |
bool compareFiles(const pair<string, string>& tocompare, const string& comparestr, bool tryfilename = true);
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Return the index of the rightmost directory separator in
|
|
|
151 |
* the given string
|
|
|
152 |
*
|
|
|
153 |
* @param aFilename filename to search for
|
|
|
154 |
* @return index
|
|
|
155 |
*/
|
|
|
156 |
string::size_type rightmostDirSeparatorIndex(const string& aFilename);
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
* Removes leading and trailing whitespace from given string between start and
|
|
|
160 |
* end position and returns that trimmed string (without parts outside specified
|
|
|
161 |
* scope).
|
|
|
162 |
*
|
|
|
163 |
* @param aString value
|
|
|
164 |
* @param aStartpos where to start trimming
|
|
|
165 |
* @param aEndpos where to end trimming
|
|
|
166 |
* @return trimmed string
|
|
|
167 |
*/
|
|
|
168 |
string trimWhiteSpace(string& aString, string::size_type aStartpos = 0, string::size_type aEndpos = string::npos);
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* Get line from input stream
|
|
|
173 |
* @param aInput value
|
|
|
174 |
* @return line as string
|
|
|
175 |
*/
|
|
|
176 |
string getLine(istream& aInput);
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
* Parses commandline parameters
|
|
|
181 |
* @param args commandline arguments as string
|
|
|
182 |
* @return command line parameters as list
|
|
|
183 |
*/
|
|
|
184 |
//list<string> parseCommandlineParameters(string args);
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* Check if the given string is numeric
|
|
|
189 |
* @param str string to check
|
|
|
190 |
* @return true, if string is numeric
|
|
|
191 |
*/
|
|
|
192 |
bool isNum(string str);
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* Check if the given string is alpha
|
|
|
197 |
* @param str string to check
|
|
|
198 |
* @return true, if string is alpha
|
|
|
199 |
*/
|
|
|
200 |
bool isAlpha(string str);
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* Check if the given string is alphanumeric
|
|
|
205 |
* @param str string to check
|
|
|
206 |
* @return true, if string is alphanumeric
|
|
|
207 |
*/
|
|
|
208 |
bool isAlphaNum(string str);
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
/**
|
|
|
212 |
* Split string
|
|
|
213 |
* @param str string to split
|
|
|
214 |
* @param separator separator char
|
|
|
215 |
* @return splitted string
|
|
|
216 |
*/
|
|
|
217 |
vector<string> splitString(const string& str, char separator=' ');
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
/**
|
|
|
221 |
* Trims white space
|
|
|
222 |
* @param aControlString format string
|
|
|
223 |
* @return formated string
|
|
|
224 |
*/
|
|
|
225 |
//string printToString(string& aControlString, ...);
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* Trims white space
|
|
|
230 |
* @param aControlString format string
|
|
|
231 |
* @param params list of params to format
|
|
|
232 |
* @return formatted string
|
|
|
233 |
*/
|
|
|
234 |
string printToString(string& aControlString, list<string> params);
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Replaces all occurences of the given character in a string by another one.
|
|
|
238 |
* @param str reference to the string, which should be converted.
|
|
|
239 |
* @param replaceFrom character that should be replaced by another.
|
|
|
240 |
* @param replaceTo The replacing character.
|
|
|
241 |
*/
|
|
|
242 |
void replaceChar(string& str, char replaceFrom, char replaceTo);
|
|
|
243 |
|
|
|
244 |
/**
|
|
|
245 |
* Remove base part from a string
|
|
|
246 |
* @param aString string to be processed
|
|
|
247 |
* @param aBase string to be removed
|
|
|
248 |
* @return string with base part removed
|
|
|
249 |
*/
|
|
|
250 |
string removeBase(string aString, string aBase);
|
|
|
251 |
|
|
|
252 |
/**
|
|
|
253 |
* Remove any leading directory separators from a string
|
|
|
254 |
* @param aString string to be trimmed
|
|
|
255 |
* @return leading directory separator trimmed string
|
|
|
256 |
*/
|
|
|
257 |
string trimLeadingDirSeparator(string aString);
|
|
|
258 |
|
|
|
259 |
/**
|
|
|
260 |
* Comare base file with current file
|
|
|
261 |
* after excluding sub dirs each time until string ends
|
|
|
262 |
* @param aBasestr base file string
|
|
|
263 |
* @param aCurstr base file string
|
|
|
264 |
* @return true if base string matches with current string anytime after
|
|
|
265 |
* excluding sub dirs.Else false.
|
|
|
266 |
*/
|
|
|
267 |
bool compareWholeFileStrings(const string& aBasestr,const string& aCurstr);
|
|
|
268 |
|
|
|
269 |
#define KEY_STRUCT "struct "
|
|
|
270 |
#define KEY_ENUM "enum"
|
|
|
271 |
#define KEY_MACRO "#define "
|
|
|
272 |
|
|
|
273 |
#endif
|