Le 26 sept. 2006 à 00:14, T&B a écrit :
And now a shorter one using some complementary handlers.
property sticky : ASCII character (202) set textBlock to "item1 item2 'item 3' [item 4]" set delimiter to " " set quotePairList to {{quote, quote}, {"'", "'"}, {"[", "]"}} --
set textBlock to normalize(textBlock, quotePairList)
set liste to spaces2space(textBlock)
on spaces2space(T) repeat while T contains " " set T to my remplace(" ", space, T) end repeat -- here, TID is space set lt to text items of T set AppleScript's text item delimiters to "" return lt -- TID is "" end spaces2space
on normalize(T, L) repeat with ba in L set {b, a} to ba if b is in T then set lt to my decoupe(T, b) if b = a then repeat with i from 2 to ((count of lt) - 1) by 2 if lt's item i contains space then set lt's item i to my remplace(space, sticky, lt's item i) end repeat -- i else repeat with i from 2 to (count of lt) if lt's item i contains a then set lt2 to my decoupe(lt's item i, a) if lt2's item 1 contains space then set lt2's item 1 to my remplace(space, sticky, lt2's item 1) set lt's item i to my recolle(lt2, "") end if end repeat -- i end if -- b=a set T to my recolle(lt, "") end if -- b is in T end repeat -- ba return T -- TID is "" end normalize
on remplace(b, a, T) set AppleScript's text item delimiters to b set {L, AppleScript's text item delimiters} to {text items of T, a} return L as text -- TID is a end remplace
on decoupe(T, d) set AppleScript's text item delimiters to d return text items of T -- TID is d end decoupe
on recolle(L, d) set AppleScript's text item delimiters to d return L as text -- TID is d end recolle
Yvan KOENIG |