


function CStringStream( stream )
{
	this.stream = stream
	this.index = 0
	
	
	this.AtEndOfLine   	=   stream.length == 0  
	this.AtEndOfStream  =   stream.length == 0  
	
	this.close = function ()
	{}

	this.Close = function ()
	{}
	this.Column = 0 //property
	this.Line 	= 0//Current line number
	
	this.Read = function (i)
	{
		this.index += i
		this.AtEndOfStream  =   this.stream.length <= this.index
		this.AtEndOfLine	=	( this.stream.substr(this.index,1) == "\n"  ) || this.AtEndOfStream 
		
		if (this.AtEndOfLine	) 		this.Column = 0
		
		
		this.Column += i
		return this.stream.substr(this.index,i)

	}
	this.ReadAll = function ()
	{
		this.AtEndOfLine   	=   true
		this.AtEndOfStream  =   true
		return this.stream
	}
	this.ReadLine = function ()
	{
		var str = ""
		var ch
		for ( ;!this.AtEndOfLine;)
		{
			ch = this.Read(1) 
			if ( !this.AtEndOfLine ) 	str = str + ch
		}
		this.AtEndOfLine = false
		this.Line++
		return str
	}
	this.Skip = function (Characters)
	{
		for ( var i = 0 ; i < Characters ; i++) this.Read(1)
	}
	this.SkipLine = function ()
	{
		this.ReadLine()
	}
	this.Write  = function (Text)
	{
		this.stream = this.stream + Text
	}
	this.WriteBlankLines = function (Lines)
	{
		for ( var i = 0 ; i < Lines;i++) this.WriteLine()
	}
	this.WriteLine = function (Text)
	{
		if ( Text == null ) Text = ""
		this.Write( Text + "\n" )
	}
	
}






// old class . Contain method undo.

function CMyTextStream ( textstream )
{
	this.that = textstream
	this.buffer
	this.b_undo = false
	this.Index = 0
	
	this.ReadLine = function CMyTextStream_ReadLine()
	{
	//	var dbg_str = "CMyTextStream::ReadLine"
		if ( ! this.b_undo ) 
		{
			this.buffer = this.that.ReadLine()
			this.Index += this.buffer.length
	//		WScript.Echo ( "CMyTextStream::ReadLine() " + this.buffer )
		}
		this.b_undo = false
		return this.buffer
	}

	this.ReadLineIgnored = function CMyTextStream_ReadLineIgnored()
	{
		var str
		str = this.ReadLine()
		if (str=="")
		{
			if ( ! this.AtEndOfStream() )
			{
				str = this.ReadLine()
			}
		}
		return str
	}

	this.undo = function CMyTextStream_undo()
	{
		
	//	WScript.Echo ( "CMyTextStream::undo() "+ this.buffer)
		if ( this.b_undo )
		{
			throw "operace undo jiz byla zvolena"
		}
		this.b_undo = true
	}



	this.AtEndOfStream = function CMyTextStream_AtEndOfStream()
	{
		return this.that.AtEndOfStream
	}

	this.WriteLine = function ( str )
	{
		this.that.Write( str + "\n" )
	}

	this.close = function CMyTextStream_close()
	{
		this.that.close()
	}

}



function test_stream()
{
	var fso = new ActiveXObject( "Scripting.FileSystemObject")
	var xxx = fso.OpenTextFile ( WScript.ScriptFullName).ReadAll ()
	var stream = new CStringStream ( xxx )
	WScript.Echo( "test")
	for ( ;!stream.AtEndOfStream; )
		WScript.Echo ( stream.ReadLine() )
	WScript.Echo( "test")
	
}


try
{
if ( WScript.ScriptName.toLowerCase() == "stream.js" ) 	test_stream()
}
catch ( e ) {}
