123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- Strict
- Rem
- bbdoc: BASIC/BASIC compatibility
- End Rem
- Module BRL.Retro
- ModuleInfo "Version: 1.09"
- ModuleInfo "Author: Mark Sibly"
- ModuleInfo "License: zlib/libpng"
- ModuleInfo "Copyright: Blitz Research Ltd"
- ModuleInfo "Modserver: BRL"
- ModuleInfo "History: 1.09 Release"
- ModuleInfo "History: Cleaned up Mid$"
- ModuleInfo "History: 1.08 Release"
- ModuleInfo "History: Deleted network stuff"
- Import BRL.Basic
- Rem
- bbdoc: Extract substring from a string
- returns: A sequence of characters from @str starting at position @pos and of length @size
- about:
- The Mid command returns a substring of a String.
- Given an existing string, a @position from the start of the string and
- an optional @size, #Mid creates a new string equal to the section specified.
- If no size if given, #Mid returns the characters in the existing string from
- @position to the end of the string.
- For compatibility with classic BASIC, the @pos parameter is 'one based'.
- End Rem
- Function Mid:String( str:String,pos,size=-1 )
- If pos>Len( str ) Return Null
- pos:-1
- If( size<0 ) Return str[pos..]
- If pos<0 size=size+pos;pos=0
- If pos+size>Len( str ) size=Len( str )-pos
- Return str[pos..pos+size]
- End Function
- Rem
- bbdoc: Find a string within a string
- returns: The position within @str of the first matching occurance of @sub
- about:
- The @start parameter allows you to specifying a starting index for the search.
- For compatiblity with classic BASIC, the @start parameter and returned position
- are both 'one based'.
- End Rem
- Function Instr( str:String,sub:String,start=1 )
- Return str.Find( sub,start-1 )+1
- End Function
- Rem
- bbdoc: Extract characters from the beginning of a string
- returns: @size leftmost characers of @str
- about:
- The Left command returns a substring of a String.
- Given an existing String and a @size, Left returns the first @size
- characters from the start of the String in a new String.
- End Rem
- Function Left:String( str:String,n )
- If n>Len(str) n=Len(str)
- Return str[..n]
- End Function
- Rem
- bbdoc: Extract characters from the end of a string
- returns: @size rightmost characters of @str
- about:
- The Right command returns a substring of a String.
- Given an existing String and a @size, Right returns the last @size
- characters from the end of the String.
- End Rem
- Function Right:String( str:String,n )
- If n>Len(str) n=Len(str)
- Return str[Len(str)-n..]
- End Function
- Rem
- bbdoc: Left justify string
- returns: A string of length @n, padded with spaces
- endrem
- Function LSet:String( str:String,n )
- Return str[..n]
- End Function
- Rem
- bbdoc: Right justify string
- returns: A string of length @n, padded with spaces
- endrem
- Function RSet:String( str:String,n )
- Return str[Len(str)-n..]
- End Function
- Rem
- bbdoc: Performs a search and replace function
- returns: A string with all instances of @sub replaced by @replace
- about:
- The Replace command replaces all instances of one string with another.
- End Rem
- Function Replace:String( str:String,sub:String,replaceWith:String )
- Return str.Replace( sub,replaceWith )
- End Function
- Rem
- bbdoc: Remove unprintable characters from ends a string
- returns: @str with leading and trailing unprintable characters removed
- End Rem
- Function Trim:String( str:String )
- Return str.Trim()
- End Function
- Rem
- bbdoc: Convert string to lowercase
- returns: Lowercase equivalent of @str
- End Rem
- Function Lower:String( str:String )
- Return str.ToLower()
- End Function
- Rem
- bbdoc: Convert string to uppercase
- returns: Uppercase equivalent of @str
- End Rem
- Function Upper:String( str:String )
- Return str.ToUpper()
- End Function
- Rem
- bbdoc: Convert an integer value to a hexadecimal string
- returns: The hexadecimal string representation of @val
- End Rem
- Function Hex:String( val )
- Local buf:Short[8]
- For Local k=7 To 0 Step -1
- Local n=(val&15)+Asc("0")
- If n>Asc("9") n=n+(Asc("A")-Asc("9")-1)
- buf[k]=n
- val:Shr 4
- Next
- Return String.FromShorts( buf,8 )
- End Function
- Rem
- bbdoc: Convert an integer value to a binary string
- returns: The binary string representation of @val
- End Rem
- Function Bin:String( val )
- Local buf:Short[32]
- For Local k=31 To 0 Step -1
- buf[k]=(val&1)+Asc("0")
- val:Shr 1
- Next
- Return String.FromShorts( buf,32 )
- End Function
- Rem
- bbdoc: Convert a 64 bit long integer value to a hexadecimal string
- returns: The hexadecimal string representation of @val
- End Rem
- Function LongHex:String( val:Long )
- Return Hex( Int(val Shr 32) )+Hex( Int(val) )
- End Function
- Rem
- bbdoc: Convert a 64 bit long integer value to a binary string
- returns: The binary string representation of @val
- End Rem
- Function LongBin:String( val:Long )
- Return Bin( Int(val Shr 32) )+Bin( Int(val) )
- End Function
|