Re: Ignoring Smart Quotes
Re: Ignoring Smart Quotes
- Subject: Re: Ignoring Smart Quotes
- From: has <email@hidden>
- Date: Thu, 2 Oct 2008 22:37:22 +0100
Simon Topliss wrote:
I was hoping that 'ingoring
" something would let me evaluate text
that contains smart quotes against regular hyphens would let me test
to equality of a Unicode text string.
However, this code evaluates to false.
set t1 to "Apple's" -- regular hyphen (ASCII #39 Unicode 0027)
set t2 to "Apple’s" -- U+2019 (8217)
ignoring punctuation and diacriticals
t1 = t2
end ignoring
Does anyone have any code snippets that would help or recommend
another approach.
Normalise the strings yourself before comparing them (this is what
'ignoring' blocks do under the hood), e.g.:
on straightenQuotes(str)
repeat with pattsRef in {{"[“”]", "\""}, {"[‘’]", "'"}}
set {findPatt, newStr} to pattsRef
tell application "TextCommands"
set str to search str for findPatt replacing with newStr with regex
end tell
end repeat
return str
end straightenQuotes
straightenQuotes("Apple's") = straightenQuotes("Apple’s)
--> true
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
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