Optimizing Character Matching
Optimizing Character Matching
- Subject: Optimizing Character Matching
- From: Rick Gordon <email@hidden>
- Date: Fri, 3 Nov 2006 16:55:15 -0800
Title: Optimizing Character Matching
I've created an InDesign script to parse paragraph styles for the
purpose of creating XML-compatible tag names, deleting illegal
characters or unneeded styles along the way. My question concerns how
I might optimize the script (the
red-highlighted areas) so that I have more flexibility in
modifying my search elements -- like eliminating any spaces or
punctuation.
It would seem as though I could create some kind of match to the
contents of a string, like
if myString contains any character in " <>()-_**~"
then
...
end if
... but that generates an error. Suggestions are
appreciated.
The (almost) full script is below:
----
tell application "Adobe InDesign CS2"
tell active document
set tempList to {}
set nameList to name of every paragraph style
repeat with eachItem in nameList
tell contents of eachItem
set
pStyleName to contents of eachItem as text
tell
pStyleName to set tempName to it
set pStyleName
to tempName
tell
pStyleName
if it contains " " or it contains "-"
or it contains "_" or it contains "<" or it
contains ">" or it contains "(" or it contains
")" or it contains "*" or it contains "*"
or it contains "~" then
set tempName to pStyleName
set charCount to count characters in
pStyleName
repeat with i from charCount to 1 by -1
tell pStyleName
if character i is in "
<>()-_**~" then
try
set tempName to (characters 1 thru (i - 1) of tempName as text) &
(characters (i + 1) thru -1 of tempName as text)
end try
end if
end tell
end repeat
end
if
end tell
set pStyleName
to tempName
tell character
1 of pStyleName
if it contains " " or it contains "-"
or it contains "_" or it contains "<" or it
contains ">" or it contains "(" or it contains
")" or it contains "*" or it contains "*"
or it contains "~" then
set tempName to (characters 2 thru -1 of
pStyleName as text)
end
if
end tell
copy
tempName to end of tempList
end tell
end repeat
tell tempList
set listLength to length of it
set tagList to {}
repeat with i from 1 to
listLength
if item i does not contain "[" or does not contain
"last" or item i does not contain "first" or item
i does not contain "Normal" then
copy item
i to end of tagList
end if
end repeat
end tell
return tagList
end tell
end tell
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden