Chars categories
Primitives
Strings
Objects, Classes and Slots
Objects and Entities

Strings

In CLAIRE strings are represented using a C char*, that is a sequence of 8 bit characters. The length of a string is computed by the general method length @ string :
 length("toto"-> 4
[XL] Starting with XL CLAIRE strings may contain null char under certain restriction. Indeed XL CLAIRE makes difference between strings that are dynamically allocated and strings that are are statically compiled :
 s0 :: "a static string" // would compile as a static string
 s1 :: ("a string" /+ string!('\0') /+ "another string"// dynamically built string
In the above example s0 would be compiled statically, that is the string content would be allocated outside claire memory (e.g. in the data space of the program). In addition s1 is allocated dynamically and stored in a chunk of the claire memory. The important difference between these two string is the handling of their length :

Notice that inside the interpreter all strings are dynamically allocated which can give different behavior between the interpreted and the compiled code, for instance :
 s :: "a\0b" // dangerous !!! static string that contain a null
 (printf("~S\n"length(s)))
In the interpreter this code would print 3 whereas the compiled code would print 1. Indeed s would be compiled statically (outside claire memory) and its length would handled by strlen.

As a general rule, any method that returns a new string returns a dynamic string. This is especially true for the port interface (fread and friends) which is particularly convenient to handle binary streams without having to deal with the null.


categories Stringsnormal dispatch operationKernel method

/(s:string, s2:string) -> string

s1 / s2 returns the concatenation of two path components. it is equivalent two s1 /+ *fs* /+ s2 where *fs* is the file separator ('/' under UNIX and '<'>under win32)
 "toto" / "titi" -> "toto/titi".


categories Stringsnormal dispatch operationKernel method

/+(s1:string, s2:string) -> string

s1 /+ s2 returns a new string that is the concatenation of the two strings.
 "toto" /+ "titi" -> "tototiti".


categories Stringsnormal dispatch operation[XL] Core method

/-(s1:string, s2:string) -> string

s1 /- s2 returns the concatenation of two path components where the last path component of s1 has been removed. For instance
 "toto/tata" /- "titi" -> "toto/titi".


categories Stringsnormal dispatch operationKernel method

<(x:string, y:string) -> boolean

returns true if x is lower than y according to the lexicographic order induced by the ASCII order on characters.


categories Stringsnormal dispatch operationKernel method

<=(x:string, y:string) -> boolean

returns true if x is lower or equal to y according to the lexicographic order induced by the ASCII order on characters.


categories Stringsnormal dispatch operationKernel method

>(x:string, y:string) -> boolean

returns true if x is greater than y according to the lexicographic order induced by the ASCII order on characters.


categories Stringsnormal dispatch operationKernel method

>=(x:string, y:string) -> boolean

returns true if x is greater or equal to y according to the lexicographic order induced by the ASCII order on characters.


categories Stringsnormal dispatch [XL] Kernel method

alpha?(s:string) -> boolean

alpha?(s) returns true if for all char c in s alpha?(c) is true.


categories Stringsnormal dispatch Kernel method

copy(s:string) -> string

The copy of a string is ... a copy of a string!


categories Stringsnormal dispatch [XL] Kernel method

digit?(s:string) -> boolean

digit?(s) returns true if for all c in s digit?(c) is true.


categories Stringsnormal dispatch [XL] Kernel method

escape(s:string) -> string

escape(s) encode the string s according to ISO-8859-1.


categories Stringsnormal dispatch [XL] Kernel method

explode(s:string, sep:string) -> list[string]

explode(s, sep) returns the list of substrings of s that are separated by sep. When sep is found at the beginning of the string s an empty match is added to the result list unlike if sep was found at the end of s. Last, if sep isn't found in s the result is a list that contain s as unique element. For instance :
 explode("CLAIRE--CLAIRE","--"-> list<string>("CLAIRE","CLAIRE")
 explode(";titi;toto",";"-> list<string>("","titi","toto")
 explode(";titi;toto;",";"-> list<string>("","titi","toto")
 explode("titi",";"-> list<string>("titi")


categories Stringsnormal dispatch [XL] Kernel method

explode_wildcard(s:string, w:string) -> list[string]

like match_wildcard?, explode_wildcard(s, w) matches the string s against the wildcard w. It return the list of matches or nil if the string s doesn't match. A match is made for each '*' and each sequence of '?'. For instance :
 explode_wildcard("CLAIRE""C*RE"-> list<string>("LAI")
 explode_wildcard("CLAIRE""C*TE"-> nil
 explode_wildcard("CLAIRE""C???RE"-> list<string>("LAI")
 explode_wildcard("CLAIRE""C???TE"-> nil


categories Stringsnormal dispatch [XL] Kernel method

find(s:string, x:string) -> integer

find(s,x) returns the position in s where the first occurrence of x is found and 0 otherwise.
 find("toto","to"-> 1
 find("toto","oto"-> 2
 find("toto","ti"-> 0


categories Stringsnormal dispatch [XL] Kernel method

find(s:string, x:string, from:integer) -> integer

find(s,x,from) returns the position in s starting at from where the first occurrence of x is found and 0 otherwise.
 find("toto","to",2-> 3
 find("toto","oto",2-> 2
 find("toto","ti"2-> 0


categories Stringsnormal dispatch Kernel method

float!(self:string) -> float

transforms a string into a float.


categories Stringsnormal dispatch Kernel method

get(s:string, c:char) -> integer

get(l, x) returns the lowest i such that s[i] = c (if no such i exists, 0 is returned).


categories Stringsnormal dispatch Kernel method

integer!(s:string) -> integer

integer!(s) returns the integer denoted by the string s if s is a string formed by a sign and a succession of digits.


categories Stringsnormal dispatch [XL] Kernel method

left(s:string, i:integer) -> string

left(s,i) is equivalent to substring(s, 1, i).
 left("123456"2-> "12"
 left("6"2-> "6"


categories Stringsnormal dispatch Kernel method

length(self:string) -> integer

returns the length of a string


categories Stringsnormal dispatch [XL] Kernel method

lower(s:string) -> string

lower(s) returns a copy of s where all uppercase letters are converted to lowercase.


categories Stringsnormal dispatch [XL] Kernel method

lower?(s:string) -> boolean

lower?(s) returns true if for all char c in s lower?(c) is true.


categories Stringsnormal dispatch [XL] Kernel method

ltrim(s:string) -> void

ltrim(s) (say left trim) returns a copy of s where heading blank chars (' ', '\n', '\t', '\r') have been removed.
 ltrim("toto"-> "toto"
 ltrim(" toto  "-> "toto  "
 ltrim(" \ttoto\n"-> "toto\n"


categories Stringsnormal dispatch Kernel method

make_string(i:integer, c:char) -> string

make_string(i, c) returns a string of length i filled with the character c.


categories Stringsnormal dispatch [XL] Kernel method

match_wildcard?(s:string, w:string) -> boolean

match_wildcard?(s, w) returns true if the string s matches the wildcard w. The wildcard is a string that understand special chars :

For instance :
 match_wildcard?("CLAIRE""C*RE"-> true
 match_wildcard?("CLAIRE""C*TE"-> false
 match_wildcard?("CLAIRE""C???RE"-> true
 match_wildcard?("CLAIRE""C???TE"-> false


categories Stringsnormal dispatch [XL] Kernel method

mime_decode(s:string) -> string

decode the string s that is assumed to be mime encoded (see RFC2047).


categories Stringsnormal dispatch [XL] Kernel method

mime_encode(s:string) -> string

return a mime encoded representation of s (see RFC2047).


categories Stringsinline Kernel method

nth(s:string, i:integer) => any

nth(s,i) returns the ithcharacter of the string s. nth(s,i) is equivalent to s[i].


categories Stringsinline Kernel method

nth=(s:string, i:integer, c:char) => any

nth=(s,i,c) sets the ithcharacter of the string s to c. nth=(s,i,c) is equivalent to s[i] := c.


categories Stringsnormal dispatch [XL] Kernel method

occurrence(s:string, z:string) -> integer

occurrence(s, z) returns the number of times when the substring z appears in s.
 occurrence("toto""to"-> 2
 occurrence("toto""tot"-> 1
 occurrence("toto""t1"-> 0


categories Stringsnormal dispatch [XL] Kernel method

replace(src:string, s:string, rep:string) -> string

returns a copy of the string src where all occurrence of s have been replaced by rep.
 replace("toto""to""ti"-> "titi"
 replace("tototiti""to"""-> "titi"
 replace("totitoti""tot""t"-> "titi"


categories Stringsnormal dispatch [XL] Kernel method

rfind(s:string, x:string) -> integer

find(s,x) returns the position in s where the last occurrence of x is found and 0 otherwise.
 rfind("toto","to"-> 3
 rfind("toto","tot"-> 1
 rfind("toto","ti"-> 0


categories Stringsnormal dispatch [XL] Kernel method

rfind(s:string, x:string, from:integer) -> integer

find(s,x,from) returns the position in s where the last occurrence of x is found before the position from and 0 otherwise.
 rfind("toto","to"4-> 3
 rfind("toto","to"3-> 3
 rfind("toto","to"2-> 1
 rfind("toto","ti"4-> 0


categories Stringsnormal dispatch [XL] Kernel method

right(s:string, i:integer) -> string

right(s,i) is equivalent to substring(s, length(s) - i + 1, length(s)).
 right("123456"2-> "56"
 right("6"2-> "6"


categories Stringsnormal dispatch [XL] Kernel method

rtrim(s:string) -> void

rtrim(s) (say right trim) returns a copy of s where tailing blank chars (' ', '\n', '\t', '\r') have been removed.
 rtrim("toto"-> "toto"
 rtrim(" toto  "-> " toto"
 rtrim(" \ttoto\n"-> " \ttoto"


categories Stringsnormal dispatch Kernel method

shrink(s:string, n:integer) -> string

The method shrink truncates the string s so that its length becomes n. This is a true side-effect and the value returned is always the same as the input.
 let s := "123"
 in (shrink(s2),
     assert(length(s= 2))


categories Stringsnormal dispatch [XL] Kernel method

space?(s:string) -> boolean

space?(s) returns true if for all c in s c is in {' ', '\t', '\r', '\n'}. space?(" ") -> true space?(" -> true space?(" t") -> false


categories Stringsnormal dispatch Kernel method

substring(s:string, i:integer, j:integer) -> string

substring(s,i,j) returns the substring of s starting at the ithcharacter and ending at the j th. For example :
 substring("CLAIRE"34-> "AI"
If i is negative, the empty string is returned and if j is out of bounds (j > length(s)), then the system takes j = length(s).


categories Stringsnormal dispatch Kernel method

substring(s1:string, s2:string, b:boolean) -> integer

substring(s1,s2,b) returns i if s2 is a subsequence of s1, starting at s1's ithcharacter. The boolean b is there to allow case-sensitiveness or not (identify 'a' and 'A' or not). In case s2 cannot be identified with any subsequence of s1, the returned value is 0.


categories Stringsnormal dispatch [XL] Kernel method

trim(s:string) -> void

trim(s) returns a copy of s where heading and tailing blank chars (' ', '\n', '\t', '\r') have been removed, one may use ltrim or rtrim that operate on left/right only.
 trim("toto"-> "toto"
 trim(" toto  "-> "toto"
 trim(" \ttoto\n"-> "toto"


categories Stringsnormal dispatch [XL] Kernel method

unescape(s:string) -> string

unescape(s) decode the string s assumed encoded according to ISO-8859-1.


categories Stringsnormal dispatch [XL] Kernel method

upper(s:string) -> string

returns a copy of the string s where all lowercase letters have been converted to uppercase.
 upper("toto"-> "TOTO"
 upper("a 1 % @ B"-> "A 1 % @ B"


categories Stringsnormal dispatch [XL] Kernel method

upper?(s:string) -> boolean

upper?(s) returns false if it exists a char c in s such c is a lowercase letter
 upper?("toto"-> false
 upper?("123"-> true
 upper?("1 % @ B"-> true


categories Stringsnormal dispatch [XL] Kernel method

url_decode(s:string) -> string

url_decode(s) returns a new string that is the decoded version of s according to RFC 1738.
 url_decode("toto"-> "toto"
 url_decode("toto+titi%3Dtata"-> "toto titi=tata"


categories Stringsnormal dispatch [XL] Kernel method

url_encode(s:string) -> string

url_encode(s) returns a new string that is a representation of s encoded according to RFC 1738.
 url_encode("toto"-> "toto"
 url_encode("toto titi=tata"-> "toto+titi%3Dtata"