📄 tokenizer.h
字号:
//**************************************************************************************************************************
//* Blue Xml Extension
//* Copyright (c) 2002-2004 Josh Harler
//*
//* Blue - General Purpose C++ Library
//* Copyright (c) 2002-2004 Josh Harler
//*
//* This software is provided 'as-is', without any express or implied warranty. In no event
//* will the authors be held liable for any damages arising from the use of this software.
//*
//* Permission is granted to anyone to use this software for any purpose, including commercial
//* applications, and to alter it and redistribute it freely, subject to the following restrictions:
//*
//* 1. The origin of this software must not be misrepresented; you must not claim that you
//* wrote the original software. If you use this software in a product, an acknowledgment in the
//* product documentation would be appreciated but is not required.
//*
//* 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
//* being the original software.
//*
//* 3. This notice may not be removed or altered from any source distribution.
//*
//*
//* file Blue/Extension/Xml/internal/Tokenizer.h
//**
#ifndef __blue_ext_xml_Tokenizer_h_included__
#define __blue_ext_xml_Tokenizer_h_included__
// Public Headers ==========================================================================================================
// Extension headers
#include "../Xml.h"
// Blue library headers
#include "Blue/Data/InputStream.h"
// Public Defines/Enums/Typedefs/Etc. ======================================================================================
// Public Classes/Structs ==================================================================================================
namespace blue {
namespace ext {
namespace xml {
/****
* \class Tokenizer
* \brief Breaks data received into XML tokens.
* \ingroup Xml
*/
class Tokenizer
{
public:
/**
* Identifies the type of token being returned.
*/
enum token_type_e
{
TOKEN_UNKNOWN, // The token type is unknown
TOKEN_BRACKET_L, // Left bracket: '<'
TOKEN_BRACKET_R, // Right bracket: '>'
TOKEN_SLASH, // Slash: '/'
TOKEN_EQUALS, // Equal sign: '='
TOKEN_QUOTED, // Quoted text. The text returned is not quoted, but was in the stream.
TOKEN_QUESTION, // Question mark: '?'
TOKEN_EXCLAMATION, // Exclamation point: '!'
TOKEN_WHITESPACE, // Whitespace: ' ', '\t', '\r', '\n'
TOKEN_ALPHANUMERIC, // Alphanumeric
};
// ===========================================================
// creation/destruction
// ===========================================================
/** Constructor. */
Tokenizer();
/** Constructor. */
Tokenizer( data::InputStream* input );
/** Destructor. */
~Tokenizer();
// ===========================================================
// query
// ===========================================================
/** Returns the InputStream being read from. */
data::InputStream* getInputStream() const;
/** Returns the type of the given token. */
token_type_e getTokenType( String token );
// ===========================================================
// manipulation
// ===========================================================
/** Sets the InputStream to read from. */
void setInputStream( data::InputStream* input );
/**
* Reads from the InputStream and returns the next valid XML
* token. If the InputStream cannot be read from, the given
* String variable will contain what was read and the function
* will return false. In this case, if the InputStream will
* eventually have data to read again, the String passed back
* into the function during the next call should contain the
* value that was previously set to it.
*/
bool getNextToken( String& str, token_type_e& type );
/**
* Passes over all data until the given text is encountered,
* returning the data skipped as the token.
*/
void readUntil( String text, bool ignoreQuotes, bool include = true );
private:
/**
* Copy constructor. Private because Tokenizers should not be
* manipulated by more than one instance.
*/
Tokenizer( const Tokenizer& );
/** Private assignment operator. See copy constructor documentation. */
const Tokenizer& operator=( const Tokenizer& );
void writeToBuffer( uint8_t byte );
String getBufferString( bool asConst = true );
data::InputStream* m_input;
uint8_t m_lastChar;
String m_readUntil;
bool m_readInclude;
bool m_readIgnoreQuotes;
Buffer m_buffer;
int m_bufferIdx;
};
/****
* \class XmlTokenizeException
* \brief Thrown when tokenizer encounters an error.
* \ingroup XmlExceptions
*/
class XmlTokenizeException :public Exception
{
public:
XmlTokenizeException( String desc )
:Exception(desc) {}
virtual String getException() const {
return (String("XmlTokenizeException", String::STATIC));
}
};
}}} // namespaces
// Public External Variables ===============================================================================================
// Public Function Prototypes ==============================================================================================
// Public Inline Functions =================================================================================================
#endif // include guard
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -