This encodes a string using steps

1) encode the string trimming whitespace
2) replace any + characters inserted by the URL encoding and replaces them with -
3) decodes and passes the string back leaving any - characters alone if they were ever meant to be there

(personally I prefer to comment line 8 out....)