# # # # string_util # # # # # # # strip # # # subroutine(strip( string s), ( debug_message("\n#### strip() \n"); # Note, this should be used for all values which are expected to span multiple # lines, respectively contain the line feed "\n" character. # # This removes leading and trailing white space from string s, # It also removes carriage return characters which could have been added manually # or by Internet Explorer prior Sawmill 8.5.0. Later Sawmill versions # remove carriage return values on the client side by util.getF(). # # Note, string s may be a node as string with multiple lines. The POSIX # matches_regular_expression() looks to have problems with this, # hence we use a saver substring approach to handle this. # # Remove all carriage return characters # if (matches_regular_expression(s, "[\r]")) then ( s = replace_all(s, "\r", ""); ); # # Handle leading space # # debug_message("#### first character is \"" . substr(s, 0, 1) . "\"\n"); while (substr(s, 0, 1) eq " " or substr(s, 0, 1) eq "\n") ( # debug_message("#### removing leading space \"" . substr(s, 0, 1) . "\"\n"); # Remove first character s = substr(s, 1); ); # # Handle trailing space # # debug_message("#### last character is \"" . substr(s, length(s) - 1) . "\"\n"); while (substr(s, length(s) - 1) eq " " or substr(s, length(s) - 1) eq "\n") ( # debug_message("#### removing trailing space \"" . substr(s, length(s) - 1) . "\"\n"); # Remove last character s = substr(s, 0, length(s) - 1); ); # debug_message("\n#### FINAL FIRST CHARACTER IS \"" . char_to_ascii(substr(s, 0, 1)) . "\"\n"); # debug_message("#### FINAL LAST CHARACTER IS \"" . char_to_ascii(substr(s, length(s) - 1)) . "\"\n\n"); # return s; ));