Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_CharTokenizer_h |
michael@0 | 7 | #define mozilla_CharTokenizer_h |
michael@0 | 8 | |
michael@0 | 9 | #include "nsDependentSubstring.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | template<char16_t delimiter> |
michael@0 | 14 | class CharTokenizer |
michael@0 | 15 | { |
michael@0 | 16 | public: |
michael@0 | 17 | CharTokenizer(const nsSubstring& aSource) |
michael@0 | 18 | { |
michael@0 | 19 | aSource.BeginReading(mIter); |
michael@0 | 20 | aSource.EndReading(mEnd); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Checks if any more tokens are available. |
michael@0 | 25 | */ |
michael@0 | 26 | bool hasMoreTokens() |
michael@0 | 27 | { |
michael@0 | 28 | return mIter != mEnd; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Returns the next token. |
michael@0 | 33 | */ |
michael@0 | 34 | const nsDependentSubstring nextToken() |
michael@0 | 35 | { |
michael@0 | 36 | nsSubstring::const_char_iterator begin = mIter; |
michael@0 | 37 | while (mIter != mEnd && (*mIter) != delimiter) { |
michael@0 | 38 | ++mIter; |
michael@0 | 39 | } |
michael@0 | 40 | nsSubstring::const_char_iterator end = mIter; |
michael@0 | 41 | if (mIter != mEnd) { |
michael@0 | 42 | ++mIter; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return Substring(begin, end); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | private: |
michael@0 | 49 | nsSubstring::const_char_iterator mIter, mEnd; |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | template<char delimiter> |
michael@0 | 53 | class CCharTokenizer |
michael@0 | 54 | { |
michael@0 | 55 | public: |
michael@0 | 56 | CCharTokenizer(const nsCSubstring& aSource) |
michael@0 | 57 | { |
michael@0 | 58 | aSource.BeginReading(mIter); |
michael@0 | 59 | aSource.EndReading(mEnd); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Checks if any more tokens are available. |
michael@0 | 64 | */ |
michael@0 | 65 | bool hasMoreTokens() |
michael@0 | 66 | { |
michael@0 | 67 | return mIter != mEnd; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Returns the next token. |
michael@0 | 72 | */ |
michael@0 | 73 | const nsDependentCSubstring nextToken() |
michael@0 | 74 | { |
michael@0 | 75 | nsCSubstring::const_char_iterator begin = mIter; |
michael@0 | 76 | while (mIter != mEnd && (*mIter) != delimiter) { |
michael@0 | 77 | ++mIter; |
michael@0 | 78 | } |
michael@0 | 79 | nsCSubstring::const_char_iterator end = mIter; |
michael@0 | 80 | if (mIter != mEnd) { |
michael@0 | 81 | ++mIter; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | return Substring(begin, end); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | private: |
michael@0 | 88 | nsCSubstring::const_char_iterator mIter, mEnd; |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | } // namespace mozilla |
michael@0 | 92 | |
michael@0 | 93 | #endif /* mozilla_CharTokenizer_h */ |