2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseUtilStringTokenizer.h
19 * @brief This is the header file for the %StringTokenizer class.
21 * This header file contains the declarations of the %StringTokenizer class.
23 * @see Tizen::Base::String
26 #ifndef _FBASE_UTIL_STRING_TOKENIZER_H_
27 #define _FBASE_UTIL_STRING_TOKENIZER_H_
29 #include <FBaseObject.h>
30 #include <FBaseString.h>
33 namespace Tizen { namespace Base { namespace Utility
36 * @class StringTokenizer
37 * @brief This class is used to break a %String into tokens.
41 * The %StringTokenizer class is used to break a String into tokens. It also provides ways to count the number of tokens.
43 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/string_tokenizer.htm">String Tokenizer</a>.
45 * The following example demonstrates how to use the %StringTokenizer class.
50 * using namespace Tizen::Base;
51 * using namespace Tizen::Base::Utility;
54 * MyClass::StringTokenizerSample(void)
56 * String str(L"Tizen-StringTokenizer/Sample code");
57 * String delim(L" /-");
59 * // Creates a StringTokenizer instance
60 * StringTokenizer strTok(str, delim);
62 * int count = strTok.GetTokenCount(); // count == 4
65 * while (strTok.HasMoreTokens())
67 * strTok.GetNextToken(token); // Tizen, StringTokenizer, Sample, code
75 class _OSP_EXPORT_ StringTokenizer
80 * Initializes an instance of %StringTokenizer with the specified parameters.
84 * @param[in] value An instance of String to parse
85 * @param[in] delimiters The delimiters
86 * @param[in] isToken The flag that indicates whether to return the delimiters as tokens @n
87 * Set to @c true to treat the delimiters as tokens, @n
88 * else @c false to skip the delimiters.
91 StringTokenizer(const String& value, const String& delimiters = L" \t\n\r\f", bool isToken = false);
94 * This destructor overrides Tizen::Base::Object::~Object().
98 * @remarks The internally allocated memory block is freed when the instance is destroyed.
100 virtual ~StringTokenizer(void);
103 * Gets the token count that indicates the number of times the %GetNextToken() method can be called before it returns an error code.
107 * @return The integer value that indicates the number of times the GetNextToken() method can be called
109 int GetTokenCount(void);
112 * Checks whether there are any more tokens in the string after the current position.
116 * @return @c true if there is at least one more token in the string after the current position, @n
119 bool HasMoreTokens(void);
122 * Gets the next token from the string tokenizer.
126 * @return An error code
127 * @param[out] token The next token
128 * @exception E_SUCCESS The method is successful.
129 * @exception E_OUT_OF_RANGE The string tokenizer has no more tokens.
131 result GetNextToken(String& token);
134 * Sets the new delimiters.
138 * @return An error code
139 * @param[in] delimiters The new delimiters
140 * @exception E_SUCCESS The method is successful.
141 * @exception E_INVALID_ARG The specified input parameter is invalid.
143 * The following example demonstrates how to use the %SetDelimiters() method.
147 * String str(L"Tizen-Framework-Utility::StringTokenizer/class");
148 * String delim(L":-");
152 * StringTokenizer strTok(str, delim);
154 * for (int i = 0; i < 3; i++)
156 * strTok.GetNextToken(token); // Tizen, Framework, Utility
159 * String newDelim(L"/");
161 * strTok.SetDelimiters(newDelim);
162 * strTok.GetNextToken(token); // token == L"::StringTokenizer"
166 result SetDelimiters(const String& delimiters);
170 // Sets the maximum characters of delimiters.
172 // @return An @c wchar_t value indicating the maximum characters
174 wchar_t SetMaxDelimChar(void);
177 // Skips the delimiters starting from the specified position.
179 // @return If the delimiter is not regarded as a token, the method returns the index of the first non-delimiter character. @n
180 // If the delimiter is regarded as a token, the method returns the starting position.
181 // @param[in] position The position from where the delimiters need to skip
183 int SkipDelimiters(int position);
186 // Scans the tokens starting from the specified position.
188 // @return The index of the next delimiter after the specified position
189 // @param[in] position The position to start scan
191 int ScanToken(int position);
200 wchar_t __maxDelimChar;
202 bool __isDelimChanged;
204 friend class _StringTokenizerImpl;
205 class _StringTokenizerImpl* __pStringTokenizerImpl;
207 }; // StringTokenizer
209 }}} // Tizen::Base::Utility
211 #endif //_FBASE_UTIL_STRING_TOKENIZER_H_