Re: About type()
- Posted by jpartridge Jun 02, 2018
- 1185 views
_tom said...
- a simple view of a valid number for a character is 0 to 255
... if st[i] < 0 or st[i] > 255 then return 0 end if ...
the "and" in the first example does not make sense
- ascii is 0 to 127
(I am excluding the historical extended ascii values)
- looks like utf8 has a few tricks to it
nominally the range is 0 to 255
But, looking at https://en.wikipedia.org/wiki/UTF-8 they describe "red" values
192 to 193 245 to 255
A better type definition is then:
-- permitted values for ascii text -- 0 to 127 -- utf8 text -- "red" values 192-193 245-255 -- ref: https://en.wikipedia.org/wiki/UTF-8 type string( sequence str ) for i=1 to length(str) do atom chr = str[i] if not integer(chr) then return 0 end if if chr<0 or chr>244 then return 0 end if if chr=192 or chr=193 then return 0 end if end for return 1 end type
_tom
As an old professor used to say, "here's a very crisp piece of code". :)