Anadromes: Difference between revisions
m
→{{header|AppleScript}}: Minor optimisation.
Catskill549 (talk | contribs) (added AWK) |
m (→{{header|AppleScript}}: Minor optimisation.) |
||
Line 153:
set theText to |⌘|'s class "NSString"'s stringWithContentsOfFile:(textFile's POSIX path) ¬
usedEncoding:(missing value) |error|:(missing value)
-- Lose paragraphs (one word per paragraph)
set theText to theText's stringByReplacingOccurrencesOfString:("(?m)^.{0," & minLength - 1 & "}\\R") withString:("") ¬
options:(|⌘|'s NSRegularExpressionSearch) range:({0, theText's |length|()})
-- Get the remaining paragraphs as an array.
set wordArray to (theText's componentsSeparatedByCharactersInSet:(|⌘|'s class "NSCharacterSet"'s controlCharacterSet()))
-- Derive a list of reversed words.
Line 169:
end repeat
--
set reversedWordSet to |⌘|'s class "NSSet"'s setWithArray:(o's wordList)
set filter to |⌘|'s class "NSPredicate"'s predicateWithFormat_("self IN %@", reversedWordSet)
--
set output to {}
repeat with i from 1 to (count o's wordList)
Line 182 ⟶ 180:
set o's wordList's item i to missing value
set reversedWord to (thisWord's characters's reverse) as text
if ({reversedWord} is in o's wordList) then set output's end to thisWord & " <--> " & reversedWord
end repeat
set AppleScript's text item delimiters to linefeed
Line 211 ⟶ 209:
revotes <--> setover
sallets <--> stellas"</lang>
=={{header|AWK}}==
<lang AWK>
|