2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-02 07:39:41 +00:00
|
|
|
|
2007-07-26 22:20:29 +00:00
|
|
|
#ifndef __nsWhitespaceTokenizer_h
|
|
|
|
#define __nsWhitespaceTokenizer_h
|
2005-11-02 07:39:41 +00:00
|
|
|
|
|
|
|
#include "nsDependentSubstring.h"
|
|
|
|
|
2007-07-26 22:20:29 +00:00
|
|
|
class nsWhitespaceTokenizer
|
2005-11-02 07:39:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-07-26 22:20:29 +00:00
|
|
|
nsWhitespaceTokenizer(const nsSubstring& aSource)
|
2005-11-02 07:39:41 +00:00
|
|
|
{
|
|
|
|
aSource.BeginReading(mIter);
|
|
|
|
aSource.EndReading(mEnd);
|
|
|
|
|
2007-07-26 22:20:29 +00:00
|
|
|
while (mIter != mEnd && isWhitespace(*mIter)) {
|
2005-11-02 07:39:41 +00:00
|
|
|
++mIter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if any more tokens are available.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasMoreTokens()
|
2005-11-02 07:39:41 +00:00
|
|
|
{
|
2007-07-26 22:20:29 +00:00
|
|
|
return mIter != mEnd;
|
2005-11-02 07:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next token.
|
|
|
|
*/
|
2005-11-02 07:42:03 +00:00
|
|
|
const nsDependentSubstring nextToken()
|
2005-11-02 07:39:41 +00:00
|
|
|
{
|
2007-07-26 22:20:29 +00:00
|
|
|
nsSubstring::const_char_iterator begin = mIter;
|
|
|
|
while (mIter != mEnd && !isWhitespace(*mIter)) {
|
2005-11-02 07:39:41 +00:00
|
|
|
++mIter;
|
|
|
|
}
|
2007-07-26 22:20:29 +00:00
|
|
|
nsSubstring::const_char_iterator end = mIter;
|
|
|
|
while (mIter != mEnd && isWhitespace(*mIter)) {
|
2005-11-02 07:39:41 +00:00
|
|
|
++mIter;
|
|
|
|
}
|
|
|
|
return Substring(begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2006-10-02 21:50:44 +00:00
|
|
|
nsSubstring::const_char_iterator mIter, mEnd;
|
2007-07-26 22:20:29 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isWhitespace(PRUnichar aChar)
|
2007-07-26 22:20:29 +00:00
|
|
|
{
|
|
|
|
return aChar <= ' ' &&
|
|
|
|
(aChar == ' ' || aChar == '\n' ||
|
|
|
|
aChar == '\r'|| aChar == '\t');
|
|
|
|
}
|
2005-11-02 07:39:41 +00:00
|
|
|
};
|
|
|
|
|
2007-07-26 22:20:29 +00:00
|
|
|
class nsCWhitespaceTokenizer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCWhitespaceTokenizer(const nsCSubstring& aSource)
|
|
|
|
{
|
|
|
|
aSource.BeginReading(mIter);
|
|
|
|
aSource.EndReading(mEnd);
|
|
|
|
|
|
|
|
while (mIter != mEnd && isWhitespace(*mIter)) {
|
|
|
|
++mIter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if any more tokens are available.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasMoreTokens()
|
2007-07-26 22:20:29 +00:00
|
|
|
{
|
|
|
|
return mIter != mEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next token.
|
|
|
|
*/
|
|
|
|
const nsDependentCSubstring nextToken()
|
|
|
|
{
|
|
|
|
nsCSubstring::const_char_iterator begin = mIter;
|
|
|
|
while (mIter != mEnd && !isWhitespace(*mIter)) {
|
|
|
|
++mIter;
|
|
|
|
}
|
|
|
|
nsCSubstring::const_char_iterator end = mIter;
|
|
|
|
while (mIter != mEnd && isWhitespace(*mIter)) {
|
|
|
|
++mIter;
|
|
|
|
}
|
|
|
|
return Substring(begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCSubstring::const_char_iterator mIter, mEnd;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isWhitespace(char aChar)
|
2007-07-26 22:20:29 +00:00
|
|
|
{
|
|
|
|
return aChar <= ' ' &&
|
|
|
|
(aChar == ' ' || aChar == '\n' ||
|
|
|
|
aChar == '\r'|| aChar == '\t');
|
|
|
|
}
|
|
|
|
};
|
2005-11-02 07:39:41 +00:00
|
|
|
|
2007-07-26 22:20:29 +00:00
|
|
|
#endif /* __nsWhitespaceTokenizer_h */
|