view countstring.rhope @ 189:d0e3a13c1bd9 default tip

Remove old calculator example
author Mike Pavone <pavone@retrodev.com>
date Fri, 07 Oct 2011 00:24:04 -0700
parents 0a4682be2db2
children
line wrap: on
line source


Blueprint Count String
{
	Text
	Line
	Column
}

Count String[text:out]
{
	out <- Count String At Pos[text, 0, 0]
}

Count String At Pos[text,line,col:out]
{
	out <- [[[Build[Count String()]]Text <<[text]]Line <<[line]]Column <<[col]
}

Slice@Count String[string,index:left,right]
{
	
	If[[index] = [0]]
	{
		left <- [string]Text <<[""]
		right <- Val[string]
	}{
		ltext,rtext <- [[string]Text >>]Slice[index]
		left <- [string]Text <<[ltext]
		parts <- [ltext]Split["\n"]
		last line <- [[parts]Length] - [1]
		rline <- [[string]Line >>] + [last line]
		prercol <- [[parts]Index[last line]]Length
		If[[last line] > [0]]
		{
			rcol <- Val[prercol]
		}{
			rcol <- [prercol] + [[string]Column >>]
		}
		right <- Count String At Pos[rtext, rline, rcol]
	}
}

Length@Count String[string:out]
{
	out <- Length[[string]Text >>]
}

Byte Length@Count String[string:out]
{
	out <- Byte Length[[string]Text >>]
}

Byte@Count String[string,index:out,invalid]
{
	out,invalid <- Byte[[string]Text >>, index]
}

Append@Count String[left,right:out]
{
	If[[[left]Length] > [0]]
	{
		out <- [left]Text << [ [String[left]]Append[String[right]] ]
	}{
		out <- right
	}
}

=@Count String[left,right:out]
{
	out <- [String[left]] = [String[right]]
}

_Slice=@Count String[left,right:out]
{
	out <- _Slice=[String[left], String[right]]
}

_Flat=@Count String[left,right:out]
{
	out <- _Flat=[String[left], String[right]]
}

_Flatten@Count String[string,dest,offset,count:out]
{
	out <- _Flatten[[string]Text >>, dest, offset, count]
}

/*Partition@Count String[string, delims:before,delim,after,nomatch]
{
	,delim,,nomatch <- [[string]Text >>]Partition[delims]
	{
                before <- [string]Text <<[~]
                bparts <- [~]Split["\n"]
                preblines <- [[bparts]Length] - [1]
                If[[preblines] > [-1]]
                {
                        blines <- Val[preblines]
                        bcols <- Length[[bparts]Index[blines]]
                }{
                        bcols <- 0
                        blines <- 0
                }
        }{
		dparts <- [~]Split["\n"]
		dlines <- [[dparts]Length]-[1]
		dcols <- Length[[dparts]Index[dlines]]
	}{
		If[[dlines] > [0]]
		{
			cols <- Val[dcols]
		}{
			If[[blines] > [0]]
			{
				cols <- [bcols] + [dcols]
			}{
				cols <- [[bcols] + [dcols]] + [[string]Column >>]
			}
		}
		after <- Count String At Pos[~, [[blines]+[dlines]] + [[string]Line >>], cols]
	}
}*/

String@Count String[string:out]
{
	out <- [string]Text >>
}

Empty@Count String[string:out]
{
	out <- Count String[""]
}