5 #include <FBaseCharacter.h>
6 #include <FBaseResult.h>
7 #include <FBaseUtilScanner.h>
8 #include "FBaseUtilRegularExpression.h"
9 #include <FBaseColArrayList.h>
10 #include <FBaseSysLog.h>
11 #include "FBaseUtil_ScannerImpl.h"
14 using namespace Tizen::Base::Collection;
15 using namespace Tizen::Base::Utility;
16 using namespace Tizen::Base;
18 namespace Tizen { namespace Base { namespace Utility
20 Scanner::Scanner(void)
28 delete __pScannerImpl;
29 __pScannerImpl = null;
32 result Scanner::Construct(const String& inputStr)
35 SysAssertf(__pScannerImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
36 SysTryReturnResult(NID_BASE_UTIL, !inputStr.IsEmpty(), E_INVALID_ARG, "[%s] The length of the input data is zero.", GetErrorMessage(E_INVALID_ARG));
37 __pScannerImpl = new (std::nothrow) _ScannerImpl();
38 SysTryReturnResult(NID_BASE_UTIL, __pScannerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
40 r = __pScannerImpl->Construct(inputStr);
44 result Scanner::Construct(const String& inputFilePath, const String& encodingScheme)
47 SysAssertf(__pScannerImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
48 SysTryReturn(NID_BASE_UTIL, !inputFilePath.IsEmpty(), r = E_INVALID_ARG, E_INVALID_ARG, "[%s] The length of the file name is zero.", GetErrorMessage(E_INVALID_ARG));
49 SysTryReturn(NID_BASE_UTIL, !encodingScheme.IsEmpty(), r = E_INVALID_ARG, E_INVALID_ARG, "[%s] The length of the encoding scheme is zero.", GetErrorMessage(E_INVALID_ARG));
51 __pScannerImpl = new (std::nothrow) _ScannerImpl();
52 SysTryReturnResult(NID_BASE_UTIL, __pScannerImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
54 r = __pScannerImpl->Construct(inputFilePath, encodingScheme);
58 bool Scanner::HasNextToken(void) const
60 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
61 return __pScannerImpl->HasNextToken();
64 bool Scanner::HasNextToken(const RegularExpression& pattern) const
66 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
67 return __pScannerImpl->HasNextToken(pattern);
70 bool Scanner::HasNextToken(const String& pattern) const
72 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
73 return __pScannerImpl->HasNextToken(pattern);
77 result Scanner::GetNextToken(String& nextTok) const
79 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
80 return __pScannerImpl->GetNextToken(nextTok);
83 result Scanner::GetNextToken(const RegularExpression& pattern, String& nextTok) const
85 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
86 return __pScannerImpl->GetNextToken(pattern, nextTok);
89 result Scanner::GetNextToken(const String& pattern, String& nextTok) const
91 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
92 return __pScannerImpl->GetNextToken(pattern, nextTok);
95 result Scanner::GetNextSignedChar(signed char& nextSignedChar) const
97 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
98 return __pScannerImpl->GetNextSignedChar(nextSignedChar );
101 result Scanner::GetNextSignedChar(signed char& nextSignedChar, int radix) const
103 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
104 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
105 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
106 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
108 return __pScannerImpl->GetNextSignedChar(nextSignedChar, radix);
111 bool Scanner::IsNextTokenConvertibleToSignedChar(void) const
113 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
115 return __pScannerImpl->IsNextTokenConvertibleToSignedChar();
118 bool Scanner::IsNextTokenConvertibleToSignedChar(int radix) const
120 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
121 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
122 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
123 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
125 return __pScannerImpl->IsNextTokenConvertibleToSignedChar(radix);
128 result Scanner::GetNextInt(int& nextInt) const
130 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
131 return __pScannerImpl->GetNextInt(nextInt);
134 result Scanner::GetNextInt(int& nextInt, int radix) const
136 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
137 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
138 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
139 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
141 return __pScannerImpl->GetNextInt(nextInt, radix);
144 bool Scanner::IsNextTokenConvertibleToInt(void) const
146 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
147 return __pScannerImpl->IsNextTokenConvertibleToInt();
150 bool Scanner::IsNextTokenConvertibleToInt(int radix) const
152 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
153 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
154 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
155 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
157 return __pScannerImpl->IsNextTokenConvertibleToInt(radix);
160 result Scanner::GetNextShort(short& nextShort) const
162 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
163 return __pScannerImpl->GetNextShort(nextShort);
166 result Scanner::GetNextShort(short& nextShort, int radix) const
168 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
169 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
170 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
171 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
173 return __pScannerImpl->GetNextShort(nextShort, radix);
176 bool Scanner::IsNextTokenConvertibleToShort(void) const
178 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
179 return __pScannerImpl->IsNextTokenConvertibleToShort();
182 bool Scanner::IsNextTokenConvertibleToShort(int radix) const
184 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
185 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
186 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
187 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
190 return __pScannerImpl->IsNextTokenConvertibleToShort(radix);
193 result Scanner::GetNextLongLong(long long& nextLongLong) const
195 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
196 return __pScannerImpl->GetNextLongLong(nextLongLong);
199 result Scanner::GetNextLongLong(long long& nextLongLong, int radix) const
201 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
202 SysTryReturnResult(NID_BASE_UTIL, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) || (radix == Character::RADIX_DECIMAL) ||
203 (radix == Character::RADIX_HEXADECIMAL)), E_NUM_FORMAT,
204 "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_NUM_FORMAT), radix);
206 return __pScannerImpl->GetNextLongLong(nextLongLong, radix);
209 bool Scanner::IsNextTokenConvertibleToLongLong(void) const
211 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
212 return __pScannerImpl->IsNextTokenConvertibleToLongLong();
215 result Scanner::GetNextFloat(float& nextFloat) const
217 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
218 return __pScannerImpl->GetNextFloat(nextFloat);
222 bool Scanner::IsNextTokenConvertibleToFloat(void) const
224 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
225 return __pScannerImpl->IsNextTokenConvertibleToFloat();
228 result Scanner::GetNextDouble(double& nextDouble) const
230 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
231 return __pScannerImpl->GetNextDouble(nextDouble);
234 bool Scanner::IsNextTokenConvertibleToDouble(void) const
236 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
237 return __pScannerImpl->IsNextTokenConvertibleToDouble();
240 result Scanner::GetNextBool(bool& nextBool) const
242 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
243 return __pScannerImpl->GetNextBool(nextBool);
246 bool Scanner::IsNextTokenConvertibleToBool(void) const
248 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
249 return __pScannerImpl->IsNextTokenConvertibleToBool();
252 bool Scanner::HasNextLine(void) const
254 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
255 return __pScannerImpl->HasNextLine();
259 result Scanner::GetNextLine(String& nextLine) const
261 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
262 return __pScannerImpl->GetNextLine(nextLine);
266 result Scanner::FindInLine(const String& patternStr, String& matchedStr)
268 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
269 SysTryReturnResult(NID_BASE_UTIL, !patternStr.IsEmpty(), E_INVALID_ARG, "[%s] The length of the input data is zero.", GetErrorMessage(E_INVALID_ARG));
270 return __pScannerImpl->FindInLine(patternStr, matchedStr);
273 result Scanner::FindInLine(const RegularExpression& pattern, String& matchedStr)
275 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
276 String str(pattern.GetPattern());
277 SysTryReturnResult(NID_BASE_UTIL, !str.IsEmpty(), E_INVALID_ARG, "[%s] The length of the input data is zero.", GetErrorMessage(E_INVALID_ARG));
278 return __pScannerImpl->FindInLine(pattern, matchedStr);
281 void Scanner::Skip(const String& patternStr)
283 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
284 SysTryReturn(NID_BASE_UTIL, !patternStr.IsEmpty(), , E_INVALID_ARG, "[%s] The length of the input data is zero.", GetErrorMessage(E_INVALID_ARG));
285 __pScannerImpl->Skip(patternStr);
289 void Scanner::Skip(const RegularExpression& pattern)
291 String str(pattern.GetPattern());
292 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
293 SysTryReturn(NID_BASE_UTIL, !str.IsEmpty(), , E_INVALID_ARG, "[%s] The length of the input data is zero.", GetErrorMessage(E_INVALID_ARG));
294 __pScannerImpl->Skip(pattern);
298 int Scanner::GetRadix(void) const
300 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
301 return __pScannerImpl->GetRadix();
304 String Scanner::GetDelimiter(void) const
306 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
307 return __pScannerImpl->GetDelimiter();
310 void Scanner::SetDelimiter(const String& patternStr)
312 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
313 __pScannerImpl->SetDelimiter(patternStr);
316 void Scanner::SetDelimiter(const RegularExpression& pattern)
318 SysAssertf(__pScannerImpl != null, "Not yet constructed! Construct() should be called before use.");
319 String delimPat(pattern.GetPattern());
320 __pScannerImpl->SetDelimiter(delimPat);
323 void Scanner::SetRadix(int radix)
327 if(((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) ||
328 (radix == Character::RADIX_DECIMAL) || (radix == Character::RADIX_HEXADECIMAL)))
330 __pScannerImpl->SetRadix(radix);
334 }}} // Osp::Base::Utility