indexing description: "String utils" license: "MIT license (see ../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_STRING_UTILS feature {NONE} -- String utils trim (a_source: STRING) is -- Remove all leading and trailing whitespace from `a_source' require Source_valid: a_source /= Void do -- remove leading white space from until a_source.is_empty or (a_source.item (1) /= ' ' and a_source.item (1) /= '%T' and a_source.item (1) /= '%N' and a_source.item (1) /= '%R') loop a_source.remove (1) end -- remove trailing white space from until a_source.is_empty or (a_source.item (a_source.count) /= ' ' and a_source.item (a_source.count) /= '%T' and a_source.item (a_source.count) /= '%N' and a_source.item (a_source.count) /= '%R') loop a_source.remove (a_source.count) end end trimmed (a_source: STRING): STRING is -- A trimmed copy of `a_source' (all leading and trailing whitespace removed) do if a_source /= Void then Result := a_source.twin trim (Result) end ensure Result_set: a_source /= Void implies (Result /= Void and Result.count <= a_source.count) end to_string (a_source: ANY): STRING is -- `a_source'.out or an empty string, if `a_source' void do if a_source /= Void then Result := a_source.out end if Result = Void then create Result.make_empty end ensure Result_valid: Result /= Void end end