2016-12-05 22:15:40 +01:00
|
|
|
use framework "Foundation"
|
|
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
-- TEST -----------------------------------------------------------------------
|
|
|
|
|
on run
|
|
|
|
|
|
|
|
|
|
ap({toLower, toTitle, toUpper}, {"alphaBETA αβγδΕΖΗΘ"})
|
|
|
|
|
|
|
|
|
|
--> {"alphabeta αβγδεζηθ", "Alphabeta Αβγδεζηθ", "ALPHABETA ΑΒΓΔΕΖΗΘ"}
|
2016-12-05 22:15:40 +01:00
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
end run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- GENERIC FUNCTIONS ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
-- toLower :: String -> String
|
|
|
|
|
on toLower(str)
|
2016-12-05 22:15:40 +01:00
|
|
|
set ca to current application
|
|
|
|
|
((ca's NSString's stringWithString:(str))'s ¬
|
|
|
|
|
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
2017-09-23 10:01:46 +02:00
|
|
|
end toLower
|
2016-12-05 22:15:40 +01:00
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
-- toTitle :: String -> String
|
|
|
|
|
on toTitle(str)
|
2016-12-05 22:15:40 +01:00
|
|
|
set ca to current application
|
|
|
|
|
((ca's NSString's stringWithString:(str))'s ¬
|
|
|
|
|
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
2017-09-23 10:01:46 +02:00
|
|
|
end toTitle
|
2016-12-05 22:15:40 +01:00
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
-- toUpper :: String -> String
|
|
|
|
|
on toUpper(str)
|
|
|
|
|
set ca to current application
|
|
|
|
|
((ca's NSString's stringWithString:(str))'s ¬
|
|
|
|
|
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
|
|
|
|
end toUpper
|
|
|
|
|
|
|
|
|
|
-- A list of functions applied to a list of arguments
|
|
|
|
|
-- (<*> | ap) :: [(a -> b)] -> [a] -> [b]
|
|
|
|
|
on ap(fs, xs)
|
|
|
|
|
set {nf, nx} to {length of fs, length of xs}
|
|
|
|
|
set lst to {}
|
|
|
|
|
repeat with i from 1 to nf
|
|
|
|
|
tell mReturn(item i of fs)
|
|
|
|
|
repeat with j from 1 to nx
|
|
|
|
|
set end of lst to |λ|(contents of (item j of xs))
|
|
|
|
|
end repeat
|
|
|
|
|
end tell
|
|
|
|
|
end repeat
|
|
|
|
|
return lst
|
|
|
|
|
end ap
|
2016-12-05 22:15:40 +01:00
|
|
|
|
|
|
|
|
-- Lift 2nd class handler function into 1st class script wrapper
|
|
|
|
|
-- mReturn :: Handler -> Script
|
|
|
|
|
on mReturn(f)
|
|
|
|
|
if class of f is script then
|
|
|
|
|
f
|
|
|
|
|
else
|
|
|
|
|
script
|
2017-09-23 10:01:46 +02:00
|
|
|
property |λ| : f
|
2016-12-05 22:15:40 +01:00
|
|
|
end script
|
|
|
|
|
end if
|
|
|
|
|
end mReturn
|