Re: Trim space chars from start of line
Re: Trim space chars from start of line
- Subject: Re: Trim space chars from start of line
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 25 Jul 2011 17:20:46 -0400
So much unnecessary work! Our old friend "quoted form of" will take care of all the apostrophe-munging if you don't try to turn the string into a Ruby source code literal in addition to making it through the shell:
on stripLeadingWhiteSpace(str)
do shell script "ruby -pe '$_.lstrip!' <<<" & (quoted form of str)
end stripLeadingWhiteSpace
On Mon, Jul 25, 2011 at 4:18 PM, Stan Cleveland
<email@hidden> wrote:
on stripLeadingWhiteSpace(str)
-- escape single quotes, if present
if theText contains "'" then -- apostrophe
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "'" -- apostrophe
set textParts to text items of theText
set AppleScript's text item delimiters to "\\'" -- escaped backslash, apostrophe
set theText to textParts as text
set AppleScript's text item delimiters to oldTIDs
end if
-- removes leading whitespace
do shell script ("ruby -e \"puts('" & str & "'.lstrip)\"")
end stripLeadingWhiteSpace
Stan C.
--
Mark J. Reed <
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden