1:- module(md_trim, [
    2    trim_left/2,  % +Codes, -Result
    3    trim_right/2, % +Codes, -Result
    4    trim/2        % +Codes, -Result
    5]).

Code list whitespace trimming

Helper module to trim whitespaces from lists of codes. */

 trim_left(+Codes, -Result) is det
Trims whitespaces from the beginning of the list of codes.
   18trim_left([Code|Codes], Result):-
   19    code_type(Code, space), !,
   20    trim_left(Codes, Result).
   21
   22trim_left(Codes, Codes).
 trim_right(+Codes, -Result) is det
Trims whitespace from the end of the list of codes.
   29trim_right(Codes, Result):-
   30    reverse(Codes, CodesR),
   31    trim_left(CodesR, ResultR),
   32    reverse(ResultR, Result).
 trim(+Codes, -Result) is det
Trims whitespace from both sides of the list of codes.
   39trim(Codes, Result):-
   40    trim_left(Codes, Tmp1),
   41    reverse(Tmp1, Tmp2),
   42    trim_left(Tmp2, Tmp3),
   43    reverse(Tmp3, Result)