' String conversion utilities
'
' These are temporary, and will be replaced with better assembly versions in the future.
' The replacements might not have the same syntax as these originals.
'


Sub LPad(s() As String, ch As uInteger,length As uInteger)
	' Pad "s" by inserting character "ch" to the left end
	' of the string, until the string reaches a length of "length"
	
	Dim sLen,needed As uInteger
	sLen = len(s)					' save the length of s
	If sLen<length Then				' do we even need any more characters ?
					
		needed = length - sLen			' calculate the number of characters needed
		
		Dim i As Integer			' make enough space (use Integer in case we go down to 0)
		For i=slen+needed To needed Step -1
			s(i) = s(i-needed)		' move the characters up the required number of spaces
		Next
		
		needed = needed-1			' now fill in the characters
		For i = 0 To needed
			s(i) = ch
		Next
		
	End If
End Sub

Function len(s() As String) As uInteger
	' calculate the length of a string
	Dim ret As uInteger

	ret=0
	While s(ret)<>0: ret+=1: End While
	
End Function ret

Sub append(s() As String, ch As uInteger)
	' append a character (ch) to the end of a string
	Dim i As uInteger
	i=0
	
	While s(i)<>0			' find the ending of the string
		i+=1
	End While
	s(i) = ch			' append the character
	s(i+1) = 0			' mark the new ending of the string
End Sub



Sub ui2a(i As uInteger,st() As String)
	' convert a long to a string in st()
	Dim j,mult As uInteger
	Dim index As uInteger
	Dim flg As Boolean
	flg=0
	
	index=0
	mult = 10000
	While mult<>1
		j=i/mult

		If j<>0 Or flg=1 Then
			st(index) = "0"+j
			index +=1
			i=i-(j*mult)
		End If
		
		mult /=10
	End While
	st(index) = i+"0"
	st(index+1) = 0
End Sub