String case: Difference between revisions
→{{header|AppleScript}}: Updated primitives
No edit summary |
(→{{header|AppleScript}}: Updated primitives) |
||
Line 329:
=={{header|AppleScript}}==
{{Trans|JavaScript}}
AppleScript lacks built in string case functions, but since OS X 10.10 (Yosemite version, Oct 2014) it has been possible to use ObjC Foundation class methods directly in AppleScript code.
<lang applescript>use framework "Foundation"
on toUpperCase(str)▼
set ca to current application▼
((ca's NSString's stringWithString:(str))'s ¬▼
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text▼
on toLowerCase(str)▼
set ca to current application▼
((ca's NSString's stringWithString:(str))'s ¬▼
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text▼
set ca to current application▼
((ca's NSString's stringWithString:(str))'s ¬▼
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text▼
-- TEST -----------------------------------------------------------------------
on run
-- testCase :: Handler -> String
script testCase
on
mReturn(f)'s
end
end script
map(testCase, {
end run
-- GENERIC FUNCTIONS ----------------------------------------------------------
-- toLower :: String -> String
▲ set ca to current application
▲ ((ca's NSString's stringWithString:(str))'s ¬
▲ lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower
-- toTitle :: String -> String
▲ set ca to current application
▲ ((ca's NSString's stringWithString:(str))'s ¬
▲ capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toTitle
-- 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
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
Line 379:
set lst to {}
repeat with i from 1 to lng
set end of lst to
end repeat
return lst
Line 392:
else
script
property
end script
end if
end mReturn</lang>
{{Out}}
<lang AppleScript>{"ALPHABETA ΑΒΓΔΕΖΗΘ", "alphabeta αβγδεζηθ", "Alphabeta Αβγδεζηθ"}</lang>
|