2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseUtilStringTokenizer.h
20 * @brief This is the header file for the %StringTokenizer class.
24 * This header file contains the declarations of the %StringTokenizer class.
27 #ifndef _FBASE_UTIL_STRING_TOKENIZER_H_
28 #define _FBASE_UTIL_STRING_TOKENIZER_H_
30 #include <FBaseObject.h>
31 #include <FBaseString.h>
34 namespace Tizen { namespace Base { namespace Utility
37 * @class StringTokenizer
38 * @brief This class is used to break a String into tokens.
42 * The %StringTokenizer class is used to break a String into tokens. It also provides ways to count the number of tokens.
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/string_tokenizer.htm">String Tokenizer</a>.
46 * The following example demonstrates how to use the %StringTokenizer class.
51 * using namespace Tizen::Base;
52 * using namespace Tizen::Base::Utility;
55 * MyClass::StringTokenizerSample(void)
57 * String str(L"Tizen-StringTokenizer/Sample code");
58 * String delim(L" /-");
60 * // Creates a StringTokenizer instance
61 * StringTokenizer strTok(str, delim);
63 * int count = strTok.GetTokenCount(); // count == 4
66 * while (strTok.HasMoreTokens())
68 * strTok.GetNextToken(token); // Tizen, StringTokenizer, Sample, code
76 class _OSP_EXPORT_ StringTokenizer
81 * Initializes an instance of %StringTokenizer with the specified parameters.
85 * @param[in] value An instance of String to parse
86 * @param[in] delimiters The delimiters
87 * @param[in] isToken A flag indicating whether to return the delimiters as tokens @n
88 * Set to @c true to treat the delimiters as tokens, @n
89 * else @c false to skip the delimiters.
92 StringTokenizer(const String& value, const String& delimiters = L" \t\n\r\f", bool isToken = false);
95 * This destructor overrides Tizen::Base::Object::~Object().
99 * @remarks The internally allocated memory block is freed when the instance is destroyed.
101 virtual ~StringTokenizer(void);
104 * Gets the token count indicating the number of times the GetNextToken() method can be called before it returns an error code.
108 * @return An integer value indicating the number of times the GetNextToken() method can be called
110 int GetTokenCount(void);
113 * Checks whether there are any more tokens in the string after the current position.
117 * @return @c true if there is at least one more token in the string after the current position, @n
120 bool HasMoreTokens(void);
123 * Gets the next token from the string tokenizer.
127 * @return An error code
128 * @param[out] token The next token
129 * @exception E_SUCCESS The method is successful.
130 * @exception E_OUT_OF_RANGE The string tokenizer has no more tokens.
132 result GetNextToken(String& token);
135 * Sets the new delimiters.
139 * @return An error code
140 * @param[in] delimiters The new delimiters
141 * @exception E_SUCCESS The method is successful.
142 * @exception E_INVALID_ARG The specified input parameter is invalid.
144 * The following example demonstrates how to use the %SetDelimiters() method.
148 * String str(L"Tizen-Framework-Utility::StringTokenizer/class");
149 * String delim(L":-");
153 * StringTokenizer strTok(str, delim);
155 * for (int i = 0; i < 3; i++)
157 * strTok.GetNextToken(token); // Tizen, Framework, Utility
160 * String newDelim(L"/");
162 * strTok.SetDelimiters(newDelim);
163 * strTok.GetNextToken(token); // token == L"::StringTokenizer"
167 result SetDelimiters(const String& delimiters);
171 // Sets the maximum characters of delimiters.
173 // @return An @c wchar_t value indicating the maximum characters
175 wchar_t SetMaxDelimChar(void);
178 // Skips the delimiters starting from the specified position.
180 // @return If the delimiter is not regarded as a token, the method returns the index of the first non-delimiter character. @n
181 // If the delimiter is regarded as a token, the method returns the starting position.
182 // @param[in] position The position from where the delimiters need to skip
184 int SkipDelimiters(int position);
187 // Scans the tokens starting from the specified position.
189 // @return The index of the next delimiter after the specified position
190 // @param[in] position The position to start scan
192 int ScanToken(int position);
201 wchar_t __maxDelimChar;
203 bool __isDelimChanged;
205 friend class _StringTokenizerImpl;
206 class _StringTokenizerImpl* __pStringTokenizerImpl;
208 }; // StringTokenizer
210 }}} // Tizen::Base::Utility
212 #endif //_FBASE_UTIL_STRING_TOKENIZER_H_