Errors in function trim() (ESL0.01)
- Posted by Julio C. Galaret Viera <galaret at adinet.com.uy> Mar 27, 2006
- 484 views
I couldn't find a more recent version of ESL but I found errors both in syntax and algorithm in the trim() function (string.e). In ESL0.01 appears as:
-- Routine: trim -- Syntax: s = trim(s) -- Description: Takes a string and returns the string minus leading and trailing spaces. global function trim(sequence s) atom trim1 sequence s2 s2 = s for i = 1 to length(s) do if (s[i] != " ") then trim1 = i + 1 exit end if end for s2 = s2[trim1..$] trim1 = 0 for i = length(s) to 1 by -1 do if s[i] != " " then trim1 = i + 1 exit end if end for s2 = s2[1..$-trim1] return s2 end function
It should be:
global function xtrim(sequence s) atom trim1 sequence s2 s2 = s trim1 = 0 for i = 1 to length(s) do if not find(s2[i], " ") then trim1 = i exit end if end for s2 = s2[trim1..length(s2)] trim1 = 0 for i = length(s2) to 1 by -1 do if not find(s2[i], " ") then trim1 = i exit end if end for s2 = s2[1..trim1] return s2 end function
Or even better:
global function trim(sequence s) sequence s2 s2 = trim_left(s) s2 = trim_right(s2) return s2 end function
JG