Fix TRIM bug with multiple lines

This is a slightly reduced version (without the unrelated post-increment to pre-increment changes) of a fix done by @CCX, originally submitted as pull request #76.

--

Example code exhibiting the bug:

    >> trim "  x ^/"
    == "x x^/"  ;; Expected: "x^/"

The fix changes some variable names, to make the algorithm easier to understand. head and tail are now trimmed first, because it is simpler this way.

This fixes CureCode issue #1948.