#pragma once

//===========================================================================//
// File:	 GmlParsedString.h												 //
// Project:  gosGml				                                         //
// Contents:																 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 4/10/00   DP     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 2000 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "GmlParsedString.h"
#include "GQueue.h"
#include "GStack.h"

//#define GmlParser_HaltOnBadString


typedef void (GmlParserAppendFlushFunction)(TextDrawBuffer* Text);
typedef void (GmlParserAppendLinkFunction)(TextDrawBuffer* Text, char* Dest);

class GmlParser{
	public:
		bool Parse(char* Gml, GQueue<GmlParsedString>* DisplayQueueT, TextDrawBuffer* TextBufferT, GmlFont* Default); //true if success
		GmlParser(char* fontPath, char* imagePath);
		void SetCallback(ParserCallback* PCB);
		~GmlParser();

#ifndef GosGML_InternalTest
	private:
#endif
		char* FontPath;
		char* ImagePath;

		GmlParser(); //call me not
		GQueue<GmlParsedString>* DisplayQueue;
		TextDrawBuffer* TextBuffer;
		ParserCallback* TagCallback;

		GStack<GmlFont>* GmlFontStack;
		char* FindNext(char* Text, char Target);
		char* FindPrev(char* Text, char Target, char* Limit);
		char* FindNextInTag(char* Text, char Target);
		char* FindPrevInTag(char* Text, char Target, char* Limit);
		char* FindMNext(char* Text, char Target, char Target2);
		char* FindMPrev(char* Text, char Target, char Target2, char* Limit);
		char* FindMNextInTag(char* Text, char Target, char Target2);
		char* FindMPrevInTag(char* Text, char Target, char Target2, char* Limit);
		char* FindNextStr(char* Text, char* Str);
		char* FindPrevStr(char* Text, char* Str);
		char* FindNextStrInTag(char* Text, char* Str);
		char* FindNextUnQuotedStr(char* Text, char* Str);
		char* FindPrevUnQuotedStr(char* Text, char* Str);
		char* GrabNextQ(char* Text);
		char* GrabPrevQ(char* Text);
		char* GrabTag(char* Text);
		GmlFont* ParseGmlFontTag(char* StartOfTag);
		void AppendGmlFont(GmlFont* f,TextDrawBuffer* TextBuffer);
		void BufferText(char* StartOfTag, char* StartOfPlainText);
		char* Chomp(char* Text);
		char* ChompN(char* Text);
		char* ChompToTag(char* Text);
		char* RChomp(char* Text);
		void DealWithGmlFontTag(char*& Text);
		bool FindEQ(char*& StartOfTag,char*& StartOfData);
		void Flush(int DType, int Extra=NULL);
		void Flush(int DType, char* Dest, char* Alt=NULL);
		GmlParser& operator= (GmlParser const &); //don't call the assignment operator
		GmlParser(GmlParser&);//don't call this
		void FlushAppendFail(TextDrawBuffer* Text);
		GmlImageParsedTag* ParseGmlImageTag(char* StartOfTag); //right now this only parses out the src="file.ext" flag

};