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