/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ #include "nsStringTokenizer.h" nsStringTokenizer::nsStringTokenizer(const char* aFieldSep,const char* aRecordSep) : mDataStartDelimiter(""), mDataEndDelimiter(""), mSubstrStartDelimiter(""), mSubstrEndDelimiter(""), mFieldSeparator(aFieldSep), mRecordSeparator(aRecordSep) { mBuffer=0; mOffset=0; mValidChars[0]=mValidChars[1]=mValidChars[2]=mValidChars[3]=0; mInvalidChars[0]=mInvalidChars[1]=mInvalidChars[2]=mInvalidChars[3]=0; mCharSpec=eGivenChars; } nsStringTokenizer::~nsStringTokenizer(){ } /** * This method can tell you whether a given char is in the valid set * given by the user in the constructor * @update gess7/10/99 */ void nsStringTokenizer::SetBuffer(nsString& aBuffer) { mBuffer=&aBuffer; } /** * Call this to add a token specifier to this tokenizer. * Ultimately -- this method will be callable any number of times * so that you can have multiple token types. * * @update gess7/10/99 */ void nsStringTokenizer::AddTokenSpec(const char* aTokenSpec) { if(aTokenSpec) { ExpandDataSpecifier(aTokenSpec); } } /** * This method can tell you whether a given char is in the valid set * given by the user in the constructor * @update gess7/10/99 */ inline PRBool nsStringTokenizer::IsValidDataChar(PRUnichar aChar) { PRBool result=PR_FALSE; switch(mCharSpec) { case eGivenChars: { PRInt32 theByteNum=aChar/32; PRInt32 theBitNum=aChar-(theByteNum*32); PRInt32 shift=(1<0); } break; case eAllChars: result=PR_TRUE; break; case eExceptChars: break; } return result; } inline void SetChars(PRInt32 array[3],PRUnichar aStart,PRUnichar aStop){ PRInt32 theChar; for(theChar=aStart;theChar<=aStop;theChar++){ PRInt32 theByteNum=theChar/32; PRInt32 theBitNum=theChar-(theByteNum*32); PRInt32 shift=(1<Length()) result=PR_TRUE; } return result; } PRInt32 nsStringTokenizer::GetChar(PRUnichar& aChar){ PRInt32 result=kEOF; if(mBuffer) { if(mOffsetLength()) { aChar=(*mBuffer)[mOffset++]; result=0; } } return result; } void nsStringTokenizer::UnGetChar(PRUnichar aChar){ if(mOffset>0) mOffset--; } /* * Call this method if you want the tokenizer to iterate your string * and automatically call you back with each token * * @parm aFunctor is the object you want me to notify * @update gess 07/10/99 * RETURNS: 0 if all went well */ PRInt32 nsStringTokenizer::Iterate(nsString& aBuffer,ITokenizeFunctor& aFunctor) { PRInt32 result=0; PRInt32 theRecordNum=-1; nsString* theOldBuffer=mBuffer; mBuffer=&aBuffer; FirstRecord(); while(HasNextToken()){ theRecordNum++; PRInt32 theTokenNum=-1; while(HasNextToken()){ theTokenNum++; nsAutoString theString; GetNextToken(theString); aFunctor(theString,theRecordNum,theTokenNum); } NextRecord(); } mBuffer=theOldBuffer; return result; }