Adrian Nier Code

Back to overview

Upper case

Last modification: Monday, August 25, 2008 12:47 am

Converts a string to upper case.

Required parameters
Parameter 1 (string)
A string that is converted to upper case.

Implementation

on uppercase(_string)
   -- Define character sets
   set _lowercaseCharacters to "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
   set _uppercaseCharacters to "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
   set _lowercaseSpecialCharacters to {138, 140, 136, 139, 135, 137, 190, 141, 142, 144, 145, 143, 146, 148, 149, 147, 150, 154, 155, 151, 153, 152, 207, 159, 156, 158, 157, 216, 167}
   set _uppercaseSpecialCharacters to {128, 129, 203, 204, 231, 229, 174, 130, 131, 230, 232, 233, 234, 235, 236, 237, 132, 133, 205, 238, 239, 241, 206, 134, 242, 243, 244, 217}
   
   set _prvDlmt to AppleScript's text item delimiters
   
   -- Convert comma seperated strings into a list
   set AppleScript's text item delimiters to ","
   set _lowercaseCharacters to text items of _lowercaseCharacters
   set _uppercaseCharacters to text items of _uppercaseCharacters
   
   -- Add special characters to the character lists
   repeat with _i from 1 to count of _lowercaseSpecialCharacters
      set end of _lowercaseCharacters to ASCII character (item _i of _lowercaseSpecialCharacters)
   end repeat
   repeat with _i from 1 to count of _uppercaseSpecialCharacters
      set end of _uppercaseCharacters to ASCII character (item _i of _uppercaseSpecialCharacters)
   end repeat
   set end of _uppercaseCharacters to "SS"
   
   
   -- Loop through every lower case character
   repeat with _i from 1 to count of _lowercaseCharacters
      considering case
         if _string contains (item _i of _lowercaseCharacters) then
            -- Delimit string by lower case character
            set AppleScript's text item delimiters to (item _i of _lowercaseCharacters)
            set _stringItems to text items of _string
            -- Join list by upper case character
            set AppleScript's text item delimiters to (item _i of _uppercaseCharacters)
            set _string to _stringItems as string
         end if
      end considering
   end repeat
   
   set AppleScript's text item delimiters to _prvDlmt
   
   return _string
end uppercase