Backed out changeset 4c2bc5ae8f95 (bug 945562) for device image bustage.
[gecko.git] / xpcom / ds / CharTokenizer.h
blob37967df7c72e31e302f81265a797dc243d7c9894
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<PRUnichar delimiter>
14 class CharTokenizer
16 public:
17 CharTokenizer(const nsSubstring& aSource)
19 aSource.BeginReading(mIter);
20 aSource.EndReading(mEnd);
23 /**
24 * Checks if any more tokens are available.
26 bool hasMoreTokens()
28 return mIter != mEnd;
31 /**
32 * Returns the next token.
34 const nsDependentSubstring nextToken()
36 nsSubstring::const_char_iterator begin = mIter;
37 while (mIter != mEnd && (*mIter) != delimiter) {
38 ++mIter;
40 nsSubstring::const_char_iterator end = mIter;
41 if (mIter != mEnd) {
42 ++mIter;
45 return Substring(begin, end);
48 private:
49 nsSubstring::const_char_iterator mIter, mEnd;
52 template<char delimiter>
53 class CCharTokenizer
55 public:
56 CCharTokenizer(const nsCSubstring& aSource)
58 aSource.BeginReading(mIter);
59 aSource.EndReading(mEnd);
62 /**
63 * Checks if any more tokens are available.
65 bool hasMoreTokens()
67 return mIter != mEnd;
70 /**
71 * Returns the next token.
73 const nsDependentCSubstring nextToken()
75 nsCSubstring::const_char_iterator begin = mIter;
76 while (mIter != mEnd && (*mIter) != delimiter) {
77 ++mIter;
79 nsCSubstring::const_char_iterator end = mIter;
80 if (mIter != mEnd) {
81 ++mIter;
84 return Substring(begin, end);
87 private:
88 nsCSubstring::const_char_iterator mIter, mEnd;
91 } // namespace mozilla
93 #endif /* mozilla_CharTokenizer_h */