Anadromes: Difference between revisions

m
→‎{{header|AppleScript}}: Minor optimisation.
m (→‎{{header|AppleScript}}: Nicer logic in the second repeat.)
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)
-- Split it intoLose paragraphs. (There's one "word" per line.paragraph) with fewer than minLength characters.
set theText to theText's stringByReplacingOccurrencesOfString:("(?m)^.{0," & minLength - 1 & "}\\R") withString:("") ¬
set wordArray to theText's componentsSeparatedByString:(linefeed)
options:(|⌘|'s NSRegularExpressionSearch) range:({0, theText's |length|()})
-- Lose words that are less than the minimum specified length.
-- Get the remaining paragraphs as an array.
set filter to |⌘|'s class "NSPredicate"'s predicateWithFormat:("self MATCHES '.{" & minLength & ",}+'")
set wordArray to (wordArraytheText's filteredArrayUsingPredicatecomponentsSeparatedByCharactersInSet:(filter|⌘|'s class "NSCharacterSet"'s controlCharacterSet())
-- Derive a list of the reversed remaining words. This is what takes most of the time.
script o
property wordList : (wordArray) as list
end script
set astid to AppleScript's text item delimiters
557

edits