/*

cls_2: Curl Like Syntax
Yauheni A. Akhotnikau (C) 2001-2003
eao197@yahoo.com
-------------------------------------------------

Permission is granted to anyone to use this software for any purpose on any
computer system, and to redistribute it freely, subject to the following
restrictions:

1. This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2. The origin of this software must not be misrepresented, either by
   explicit claim or by omission.

3. Altered versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

-------------------------------------------------

*/
#if !defined( _CLS_2__TAG_TEXT_HPP_ )
#define _CLS_2__TAG_TEXT_HPP_

#include <auto_ptr_3/h/vect_ptr.hpp>

#include <cls_2/h/cls.hpp>

namespace cls_2 {

//
// tag_text_t
//

/*
	Tag which accept token "SPACE", "NONSPACE" or "STRING"
	(string stored without quotes) and create contiguous
	text.
	All spaces replaced by one space character (0x20).
	Spaces in "STRING" token remain unchanged.
	First and last spaces ignored.
*/
class	tag_text_t :
	public tag_t {
	public :
		tag_text_t(
			const char * name,
			bool mandatory );
		/*! \since v.2.6.4 */
		tag_text_t(
			cls_2::tag_t & owner,
			const char * name,
			bool mandatory );
		virtual ~tag_text_t();

		// Returns c_semantic_error if tag is already defined
		virtual int
		on_start(
			parser_context_t & context );

		// Marks tag as defined.
		// Tag may have empty value
		virtual int
		on_finish(
			parser_context_t & context );

		virtual int
		on_tok_space(
			parser_context_t & context,
			const char * tok_value );

		virtual int
		on_tok_nonspace(
			parser_context_t & context,
			const char * tok_value );

		virtual int
		on_tok_string(
			parser_context_t & context,
			const char * tok_value );

		virtual bool
		is_mandatory() const;

		virtual bool
		is_defined() const;

		virtual void
		reset();

		const char *
		query_value() const;

		//! Установить значение тега.
		/*! \since v.2.6.4 */
		void
		make_defined( const char * value );

	protected :
		auto_ptr_3::vect_ptr_t< char >	m_value;
		size_t	m_len;
		bool	m_is_mandatory;
		bool	m_is_defined;
		// Set to true in on_tok_space
		bool	m_is_space_found;

		void
		append_value(
			const char * value );

		void
		concat(
			const char * value );

		// Called from format(fmt) to output values of tag.
		virtual void
		on_format(
			tag_formatter_t & fmt );
};

} /* namespace cls_2 */

#endif
