Request addition to the NewLisp Manual: trim

Pondering the philosophy behind the language

Request addition to the NewLisp Manual: trim

Postby TedWalther » Thu Apr 23, 2015 6:33 pm

Sometimes when I am parsing dirty text, there are tabs mixed with spaces, and even other whitespace characters. So, the "trim" function almost does what I want, but because it is limited to a single character, it doesn't work on such dirty text.

So, I request that in the "trim" section, you add words similar to this:

To trim arbitrary whitespace from the beginning and end of a string, you can do this:

Code: Select all
(set 'str "  \t  Hello World!\t  \t")
(replace "^\s+|\s+$" str "")
=> "Hello World!"


I suggest you add this to the documentation, because as a new user, when I want to "trim" the whitespace from the edges of my strings, the "trim" function is the first place I look. And I imagine this isn't an uncommon case. I actually haven't ever needed to use the trim function in its current form.

Or if you added a "regex" version of trim, with a trailing regex options parameter, then I could do

Code: Select all
(trim " \t foo \t " "\s" 0) => "foo"
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther
 
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: Request addition to the NewLisp Manual: trim

Postby Lutz » Fri Apr 24, 2015 7:11 pm

In version 10.6.3, the simple trim syntax trims all white-space. But embedded white-space is not affected:
Code: Select all
> (trim "  \n \t  h e l l o \r   ")
"h e l l o"
>

http://www.newlisp.org/downloads/develo ... nprogress/
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Request addition to the NewLisp Manual: trim

Postby TedWalther » Sat Apr 25, 2015 1:31 am

Thank you Lutz! No joy on a regex enabled version of trim? :) True, true, we do have (replace) for that. Perhaps a note and a link in the Manual telling people that "for more complex cases, (replace) will do the job...".
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther
 
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: Request addition to the NewLisp Manual: trim

Postby Lutz » Sat May 16, 2015 2:24 pm

Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to Whither newLISP?

Who is online

Users browsing this forum: No registered users and 2 guests

cron