// Copyright 2001-2003, Danger, Inc.  All Rights Reserved.
// This file is subject to the Danger, Inc. Sample Code License,
// which is provided in the file SAMPLE_CODE_LICENSE.
// Copies are also available from http://developer.danger.com/

package com.danger.livejournal;

//*	The Danger StringTokenizer class can't handle the case
//*	of a blank token between two delimiters.  LJ often sends
//*	us blank lines.  This totally throws off StringTokenizer
//*	so I have implemented my own which is much simpler.

public class ResponseTokenizer
{
	//*	--------------------	ResponseTokenizer

	public
	ResponseTokenizer(String inText, char inDelimiter)
	{
		mText = inText;
		mLength = inText.length();
		mDelimiter = inDelimiter;
		mCursor = 0;
	}

	//*	--------------------	Next

	public final String
	Next()
	{
	StringBuffer	s = new StringBuffer();

		if (mCursor == mLength)
			return null;
	
		while (mCursor < mLength)
		{
		char	c = mText.charAt(mCursor++);
		
			if (mDelimiter == c)		//*	Semicolon delimits all vcard/vcal lines
				break;
			
			s.append(c);
		}
		
		return s.toString();
	}

	//*	--------------------------------	Instance Variables

	private String	mText;
	private char	mDelimiter;
	private int		mLength;
	private int		mCursor;
}