-- _sequence_.e
-- _sequence_.e
Following global functions are defined:
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()
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 given number of characters at the right of a string
Params:string to look at
sequence: extracted sub-string
left(), mid()
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
indicates that separator is the whole string instead of each character
separately. Defaults to 0 (each character separately).
indicates that separator is kept in result. Defaults to 0 (no).
splitted sequence
analyze_object(split_string("my name is Bond", ' '), "split_string")
split_string =
. [1] "my"
. [2] "name"
. [3] "is"
. [4] "Bond"
analyze_object(split_string("my name is Bond", ' ', , 1), "split_string")
split_string =
. [1] "my"
. [2] " "
. [3] "name"
. [4] " "
. [5] "is"
. [6] " "
. [7] "Bond"
analyze_object(split_string("my name is: Bond", ": "), "split_string")
split_string =
. [1] "my"
. [2] "name"
. [3] "is"
. [4] "Bond"
analyze_object(split_string("my name is: Bond", ": ", 1), "split_string")
split_string =
. [1] "my name is"
. [2] "Bond"
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]
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()
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()
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()
extract a column of an array
Params:array to extract column from
column to be extracted from array
this is fetch function from OpenEuphoria 4
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" }
}