Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FBaseUtilStringTokenizer.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FBaseUtilStringTokenizer.h
19  * @brief               This is the header file for the %StringTokenizer class.
20  *
21  * This header file contains the declarations of the %StringTokenizer class.
22  *
23  * @see                 Tizen::Base::String
24  */
25
26 #ifndef _FBASE_UTIL_STRING_TOKENIZER_H_
27 #define _FBASE_UTIL_STRING_TOKENIZER_H_
28
29 #include <FBaseObject.h>
30 #include <FBaseString.h>
31
32
33 namespace Tizen { namespace Base { namespace Utility
34 {
35 /**
36  * @class       StringTokenizer
37  * @brief       This class is used to break a %String into tokens.
38  *
39  * @since 2.0
40  *
41  * The %StringTokenizer class is used to break a String into tokens. It also provides ways to count the number of tokens.
42  *
43  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/string_tokenizer.htm">String Tokenizer</a>.
44  *
45  * The following example demonstrates how to use the %StringTokenizer class.
46  *
47  * @code
48  *      #include <FBase.h>
49  *
50  *      using namespace Tizen::Base;
51  *      using namespace Tizen::Base::Utility;
52  *
53  *      void
54  *      MyClass::StringTokenizerSample(void)
55  *      {
56  *              String str(L"Tizen-StringTokenizer/Sample code");
57  *              String delim(L" /-");
58  *
59  *              // Creates a StringTokenizer instance
60  *              StringTokenizer strTok(str, delim);
61  *
62  *              int count = strTok.GetTokenCount();             // count == 4
63  *
64  *              String token;
65  *              while (strTok.HasMoreTokens())
66  *              {
67  *                      strTok.GetNextToken(token);                     // Tizen, StringTokenizer, Sample, code
68  *              }
69  *      }
70  * @endcode
71  *
72  *
73  */
74
75 class _OSP_EXPORT_ StringTokenizer
76         : public Object
77 {
78 public:
79         /**
80          * Initializes an instance of %StringTokenizer with the specified parameters.
81          *
82          * @since 2.0
83          *
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.
89          *
90          */
91         StringTokenizer(const String& value, const String& delimiters = L" \t\n\r\f", bool isToken = false);
92
93         /**
94          * This destructor overrides Tizen::Base::Object::~Object().
95          *
96          * @since 2.0
97          *
98          * @remarks             The internally allocated memory block is freed when the instance is destroyed.
99          */
100         virtual ~StringTokenizer(void);
101
102         /**
103          * Gets the token count that indicates the number of times the %GetNextToken() method can be called before it returns an error code.
104          *
105          * @since 2.0
106          *
107          * @return              The integer value that indicates the number of times the GetNextToken() method can be called
108          */
109         int GetTokenCount(void);
110
111         /**
112          * Checks whether there are any more tokens in the string after the current position.
113          *
114          * @since 2.0
115          *
116          * @return              @c true if there is at least one more token in the string after the current position, @n
117          *                              else @c false
118          */
119         bool HasMoreTokens(void);
120
121         /**
122          * Gets the next token from the string tokenizer.
123          *
124          * @since 2.0
125          *
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.
130          */
131         result GetNextToken(String& token);
132
133         /**
134          * Sets the new delimiters.
135          *
136          * @since 2.0
137          *
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.
142          *
143          * The following example demonstrates how to use the %SetDelimiters() method.
144          *
145          * @code
146          *
147          *      String str(L"Tizen-Framework-Utility::StringTokenizer/class");
148          *      String delim(L":-");
149          *
150          *      String token;
151          *
152          *      StringTokenizer strTok(str, delim);
153          *
154          *      for (int i = 0; i < 3; i++)
155          *      {
156          *              strTok.GetNextToken(token);                     // Tizen, Framework, Utility
157          *      }
158          *
159          *      String newDelim(L"/");
160          *
161          *      strTok.SetDelimiters(newDelim);
162          *      strTok.GetNextToken(token);                             // token == L"::StringTokenizer"
163          *
164          * @endcode
165          */
166         result SetDelimiters(const String& delimiters);
167
168 private:
169         //
170         // Sets the maximum characters of delimiters.
171         //
172         // @return      An @c wchar_t value indicating the maximum characters
173         //
174         wchar_t SetMaxDelimChar(void);
175
176         //
177         // Skips the delimiters starting from the specified position.
178         //
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
182         //
183         int SkipDelimiters(int position);
184
185         //
186         // Scans the tokens starting from the specified position.
187         //
188         // @return              The index of the next delimiter after the specified position
189         // @param[in] position  The position to start scan
190         //
191         int ScanToken(int position);
192
193
194 private:
195         String __string;
196         String __delimiters;
197         int __curPosition;
198         int __newPosition;
199         int __maxStrLen;
200         wchar_t __maxDelimChar;
201         bool __isToken;
202         bool __isDelimChanged;
203
204         friend class _StringTokenizerImpl;
205         class _StringTokenizerImpl* __pStringTokenizerImpl;
206
207 }; // StringTokenizer
208
209 }}} // Tizen::Base::Utility
210
211 #endif //_FBASE_UTIL_STRING_TOKENIZER_H_