aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 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 | #ifndef __STRING_TOKENIZER_H__ |
| 18 | #define __STRING_TOKENIZER_H__ |
| 19 | |
| 20 | #include <drm/drm_framework_common.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | /** |
| 25 | * This is an utility class for String manipulation. |
| 26 | * |
| 27 | */ |
| 28 | class StringTokenizer { |
| 29 | public: |
| 30 | /** |
| 31 | * Iterator for string tokens |
| 32 | */ |
| 33 | class Iterator { |
| 34 | friend class StringTokenizer; |
| 35 | private: |
| 36 | Iterator(StringTokenizer* StringTokenizer) |
| 37 | : mStringTokenizer(StringTokenizer), mIndex(0) {} |
| 38 | |
| 39 | public: |
| 40 | Iterator(const Iterator& iterator); |
| 41 | Iterator& operator=(const Iterator& iterator); |
| 42 | virtual ~Iterator() {} |
| 43 | |
| 44 | public: |
| 45 | bool hasNext(); |
| 46 | String8& next(); |
| 47 | |
| 48 | private: |
| 49 | StringTokenizer* mStringTokenizer; |
| 50 | unsigned int mIndex; |
| 51 | }; |
| 52 | |
| 53 | public: |
| 54 | /** |
| 55 | * Constructor for StringTokenizer |
| 56 | * |
| 57 | * @param[in] string Complete string data |
| 58 | * @param[in] delimeter Delimeter used to split the string |
| 59 | */ |
| 60 | StringTokenizer(const String8& string, const String8& delimeter); |
| 61 | |
| 62 | /** |
| 63 | * Destructor for StringTokenizer |
| 64 | */ |
| 65 | ~StringTokenizer() {} |
| 66 | |
| 67 | private: |
| 68 | /** |
| 69 | * Splits the string according to the delimeter |
| 70 | */ |
| 71 | void splitString(const String8& string, const String8& delimeter); |
| 72 | |
| 73 | public: |
| 74 | /** |
| 75 | * Returns Iterator object to walk through the split string values |
| 76 | * |
| 77 | * @return Iterator object |
| 78 | */ |
| 79 | Iterator iterator(); |
| 80 | |
| 81 | private: |
| 82 | Vector<String8> mStringTokenizerVector; |
| 83 | }; |
| 84 | |
| 85 | }; |
| 86 | #endif /* __STRING_TOKENIZER_H__ */ |
| 87 | |