home *** CD-ROM | disk | FTP | other *** search
-
- ; Trim any space, tab or newline characters from the left
- ; side of a string.
-
- Function ltrim
- Begin
-
- If ne (argc () 1)
- Then
- put ("usage ltrim (string)")
- return ("")
- EndThen
- EndIf
-
- set (pd
- patcre (
- patgrp (" \t\n" 0 100)
- patset (string patrem ())
- )
- )
-
- set (found patmatch (pd argv (1)))
- patfre (pd)
-
- If found
- Then
- return (string)
- EndThen
- Else
- return ("")
- EndElse
- EndIf
-
- EndFunction
-
- ; Trim any space, tab or newline characters from the right
- ; side of a string.
-
- Function rtrim
- Begin
-
- If ne (argc () 1)
- Then
- put ("usage rtrim (string)")
- return ("")
- EndThen
- EndIf
-
- set (string argv (1))
-
- ; Note: do not use
- ; patset (result patarb (1 100))
- ; patgrp (" \t\n" 0 100)
- ; because patgrp will always return true on a match
- ; of zero characters and patarb will only match the
- ; minimum. To get patarb to advance and re-evaluate
- ; requires that the remainder of the pattern does
- ; not return true until it matches something.
- ; Therefore it should not be used after a patarb because
- ; the patarb will match the minimum.
-
- ; Another problem with:
- ; patset (result patarb (1 100))
- ; patgrp (" \t\n" 1 100)
- ; is that if there is more than one leading space then
- ; the patgrp will match the leading spaces and not the
- ; trailing ones.
-
- set (pd
- patcre (
- patset (result patarb ())
- patgrp (" \t\n" 1 100) pateol ()
- )
- )
-
- set (found patmatch (pd string))
- patfre (pd)
-
- If found
- Then
- return (result)
- EndThen
- Else
- return (string)
- EndElse
- EndIf
-
- EndFunction
-
- ; Trim any space, tab or newline characters from both
- ; left and right sides of a string.
-
- Function trim
- Begin
-
- If ne (argc () 1)
- Then
- put ("usage: trim (string)")
- return ("")
- EndThen
- EndIf
-
- set (string argv (1))
- set (result "")
-
- set (pd
- patcre (
- patgrp (" \t\n" 0 100)
- patset (result patarb ())
- patalt (
- patpat (patgrp (" \t\n" 1 100) pateol ())
- pateol ()
- )
- )
- )
-
- set (found patmatch (pd string))
- patfre (pd)
-
- return (result)
-
- EndFunction
-