-- _sequence_.e
-- _sequence_.e
Following global functions are defined:
remove space chars from the beginning of a string
Params:string to modify
modified string
trim_tail(), trim(), trim_spaces()
remove space chars from the end of a string
Params:string to modify
modified string
trim_head(), trim(), trim_spaces()
remove space chars from both ends of a string
Params:string to modify
modified string
trim_head(), trim_tail(), trim_spaces()
string to modify
remove space chars from both ends of a string
and removes exceeding space chars between words
tab spaces are converted to normal spaces before removal
modified string
trim_head(), trim_tail(), trim()
Return a string left-padded to length len
Params:string to modify
length of string to reach
modified string
pad_tail()
Return a string right-padded to length len
Params:string to modify
length of string to reach
modified string
pad_head()
returns the given number of characters at the left of a string
Params:string to look at
sequence: extracted sub-string
mid(), right()
returns the sub-string at given position and given length of a string
Params:string to look at
start index
sub-string length
sequence: extracted sub-string
left(), right()
returns the given number of characters at the right of a string
Params:string to look at
sequence: extracted sub-string
left(), mid()
insert string between quotes
Params:string to modify
optional "delims" specifies the quotes to remove: defaults to '"'
delims can be an integer when starting and ending quotes are equal (most cases)
delims is a sequence with starting and ending quotes if these are different
modified string
dequote()
remove specified quotes if existing
Params:string to modify
optional "delims" specifies the quotes to remove: defaults to '"'
delims can be an integer when starting and ending quotes are equal (most cases)
delims is a sequence with starting and ending quotes if these are different
modified string
quote()
checks whether a string begins with given sub-string
Params:object to search for
string to search in
1 if string begins with given object, 0 if not
ends()
checks whether a string ends with given sub-string
Params:object to search for
string to search in
1 if string ends with given object, 0 if not
begins()
splits a string according to a separator
Params:string to split
separator
either an object or a sequence
if separator is a sequence then:
* if as_is is set then the whole string is the separator
* is as_is is not set then each character of the string is considered
optional "keep" indicates that separator is kept in result. Defaults to 0 (no).
optional "as_is" indicates that separator is the wole string instead of each character separately.
splitted sequence
analyze_object(split("my name is Bond", ' ', {}), "split", {})
split =
. [1] "my"
. [2] "name"
. [3] "is"
. [4] "Bond"
analyze_object(split("my name is Bond", ' ', {{"keep",1}}), "split", {})
split =
. [1] "my"
. [2] " "
. [3] "name"
. [4] " "
. [5] "is"
. [6] " "
. [7] "Bond"
analyze_object(split("my name is: Bond", ": ", {}), "split", {})
split =
. [1] "my"
. [2] "name"
. [3] "is"
. [4] ""
. [5] "Bond"
analyze_object(split("my name is: Bond", ": ", {{"as_is",1}}), "split", {})
split =
. [1] "my name is"
. [2] "Bond"
escape chars from a string
Params:string to convert chars from
escaped sequence
escape("\"string1\string2\"") => \"string1\\string2\"
escape("'char'") => \'char\'
escape(col1\tcol2) => col1\\tcol2
escape(line1\rline2) => line1\\rline2
escape(line1\nline2) => line1\\nline2
escape(line\n) => line\\n
unescape()
unescape chars from a string
Params:string to convert escaped chars from
unescaped sequence
unescape(\"string1\\string2\") => "string1\string2"
unescape(\'char\') => 'char'
unescape(col1\tcol2) => col1[tab]col2
unescape(line1\rline2) => line1[cr]line2
unescape(line1\nline2) => line1[lf]line2
unescape(line\n) => line[lf]
escape()
splits a string in objects according to given separator
Params:string to split
separator
splitted elements are converted to atoms when possible
splitted sequence
analyze_object(split_n_convert("my,code,is,7", ","), "split_n_convert", {})
split_n_convert =
. [1] "my"
. [2] "code"
. [3] "is"
. [4] 7
convert_n_join()
merges sub-strings with given separator into a global string
Params:list of sub-strings
separator
merged string
puts(1, join({"my","code","is","007"}, " ") & "\n")
my code is 007
split()
merge converted objects in a string with given separator
Params:sequence of objects
separator
objects are converted to strings before being joined
merged string
puts(1, convert_n_join({"my","code","is", 7}, ",") & "\n")
"my","code","is",7
split_n_merge()
insert an object at given index in a sequence
Params:sequence to modify
object to insert
position to insert object
modified sequence
puts(1, insert("George Bush", "W. ", 8) & "\n")
George W. Bush
remove from start index to stop index in given sequence
Params:sequence to modify
start index
stop index
modified sequence
puts(1, remove("George W. Bush", 8, 10) & "\n")
George Bush
replaces first occurence of sub-sequence old by new in sequence target
Params:sequence to replace in
sub-sequence to be replaced
new sub-sequence
modified sequence
puts(1, replace("George W. Bush", "W. ", "") & "\n")
George Bush
replaces all occurences of sub-sequence old by new in sequence target
Params:sequence to replace in
sub-sequence to be replaced
new sub-sequence
modified sequence
puts(1, replace_all("atoms, integers and objects", "s", "") & "\n")
atom, integer and object
append an object to a sequence only if not already present
Params:sequence to append to
object to append
modified sequence
puts(1, append_if_new("abcdefghij", 'a') & "\n")
abcdefghij
puts(1, append_if_new("abcdefghij", 'k') & "\n")
abcdefghijk
append()
store an object in a sequence at given nested position
Params:sequence to store in
nested position to store at
object to store
this is store function from OpenEuphoria 4
modified sequence
analyze_object(store({1,{2,{3}}}, {2, 2, 1}, 4), "store 2.2.1", {})
store 2.2.1 =
. [1] 1
. [2]
. . [1] 2
. . [2] {4}
fetch()
get an object in a sequence from its nested position
Params:sequence to fetch from
nested position to get at
this is fetch function from OpenEuphoria 4
object searched for
? fetch({1,{2,{3,4}}}, {2, 2, 1})
3
store()
extract a column of an array
Params:array to extract column from
column to be extracted from array
sequence: selected column of array
puts(1, extract_column({"Start","Tank","Own","Patent"}, 1) & "\n")
STOP
store()
extract variables from a string according to a template
Params:sequence to be parsed
reference template
Variables are encoded as XML tags in the template
Example: "http://
sequence: list of pairs {name, value} of all encountered variables in string
parse_sequence("http://www.google.com:80/search?q=euphoria",
"http://:/search?q=")
will return
{{"", "www.google.com"}, {"", "80"}, {"", "euphoria"}}
compares lines2 to lines1 and returns differences
Params:reference sequence
sequence to be compared to first one
Comparison does not take spaces into account but tabs are sigificant.
sequence: list of differences as sequences in following format:
{comparison, line1, sequence1, line2, sequence 2}
where
* comparison is either:
* '-' if reference line was removed in line2
* '+' if compared line was added to line1
* '#' if reference line differs from compared line
* line1 is number of reference line in line1
* sequence1 is reference line in line1
* line2 is number of compared line in line2
* sequence2 is compared line in line1
constant SEQ1 = {
"First",
"Second",
"Third",
"Fourth",
"Fifth"
}
constant SEQ2 = {
"First",
"Third",
"Not Fourth",
"Fifth",
"Sixth"
}
compare_lines(SEQ1, SEQ2)
will return
{
{ '-', 2, "Second", 0, "" },
{ '#', 4, "Fourth", 3, "Not Fourth" },
{ '+', 0, "", 5, "Sixth" }
}