sort accent char correctly

Jan Decroos jan.decroos at groepvanroey.be
Thu Sep 26 03:05:06 EDT 2002


You can use the "sort  ... by function(each)" command.
See scripts below.

Change the LocInitUpLowGlobals function if you want to add or remove chars.

***put this in a btn script ********************************
on mouseUp
  put "crayon,câble,canon" into lList
  sort items of lList by MyUpper(each)
  answer lList
end mouseUp
******************************************************

****this can be in a stack script, stackinuse script, ...*****************
function MyUpper pData
  return(uplow("u",pData))
end MyUpper

function MyLower pData
  return(uplow("l",pData))
end MyLower

global gLowerChars, gLower2UpperChars, gUpperChars, gUpper2LowerChars

on LocInitUpLowGlobals
  put "abcdefghijklmnopqrstuvwxyzáàâäãåçéèêëíìîïñóòôöõúùûüæøœÿ" into gLowerChars
  put "ABCDEFGHIJKLMNOPQRSTUVWXYZAAAAAACEEEEIIIINOOOOOUUUUÆØŒY" into
gLower2UpperChars
  put "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÆØŒŸ" into gUpperChars
  put "abcdefghijklmnopqrstuvwxyzaaaaaaceeeeiiiinooooouuuuæøœy" into
gUpper2LowerChars
end LocInitUpLowGlobals

-- pOtion "u[pper]","l[ower]" or "i[nitialcaps]"
-- pString : data to convert
-- pChars : in case initialcaps : the chars after which a new word starts
(default : space, return, tab and "-")
function upLow pOption, pString, pChars
  put toLower(char 1 of pOption) into pOption
  if the paramCount > 2 and pOption <> "i" then
	StopWithMessage "UpLow : Using a third argument requires 'i' as first argument
!"
  end if
  if gLowerChars = "" then LocInitUpLowGlobals
  set the casesensitive to true
  put 0 into xx
  if pOption = "u" then
    repeat for each char lChar in gLowerChars
      add 1 to xx
      replace lChar with char xx of gLower2UpperChars in pString
    end repeat
  else if pOption = "l" then
    repeat for each char lChar in gUpperChars
      add 1 to xx
      replace lChar with char xx of gUpper2LowerChars in pString
    end repeat
  else if pOption = "i" then
    put "" into lResult
    if pChars = "" then put " -"&CR&tab into pChars
    put char 1 of pChars into lPrevChar -- force first char  to be uppercase
    repeat for each char lChar in pString
      if lPrevChar is in pChars then
        if lChar is in gLowerChars then put char offset(lChar,gLowerChars) of
gLower2UpperChars after lResult
        else put lChar after lResult
      else
        if lChar is in gUpperChars then put char offset(lChar,gUpperChars) of
gUpper2LowerChars after lResult
        else put lChar after lResult
      end if
      put lChar into lPrevChar
    end repeat
    put lResult into pString
  end if
  return pString
end upLow

on StopWithMessage pMess
  answer error pMess
  exit to top
end StopWithMessage
************************************************************

Hope this helps,
Jan Decroos




More information about the use-livecode mailing list