INM home

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: code : nettoyage de diacritique



On 2/12/05 9:18 am, "Sébastien Portebois" <sebastien.portebois@free.fr>
wrote:
> Le but : supprimer les diacritiques (par exemple pour faciliter 
>ensuite
> les recherches de texte insensibles aux diacritiques)
> 
> Par exemple ca transformera "Sébastien" en "Sebastien",

> Je n'ai pas encore eu le loisir de confronter les expressions 
>régulières
> du Javascript de Director, face à l'xtra PRegEx...

Kouki kouki Sébastien,

Je n'ai pas essayé d'utiliser PRegEx pour supprimer les diacritiques, 
mais
je l'ai utilisé pour convertir les caractères accentués sur Mac en
caractères accentués sur Windows et d'ajouter des Line Feed aux retours 
de
chariots, et vice versa.

C'est très rapide : pour convertir le manuscrit du roman de ma femme
(<http://www.erny-newton.com> dans vos libraires à partir de la semaine
prochaine), qui pèse 384 Ko, les méthodes ConvertToWin() et 
ConvertToMac()
(voir ci-dessous) ne demandent que 80 millisecondes, et ce sur un 
machine à
876 Mhz.

Pour faire ce que tu souhaites, il suffirait d'utiliser quelquechose
comme...

 vStringList = ["Sébastiên"]
 re_tr(vStringList, "EÈÉÊËèéêë", "EEEEEeeeee")
 put vStringList[1]
 -- "Sebastien"

... mais il faudrait inclure tous les diacritiques dans la première 
chaîne,
et toutes leur traductions dans la deuxième.

Cordialement,

James


-- 
====================================================================== 
--


on GetHighANSIStrings() ----------------------------------------------
  -- OUTPUT: Returns a list with the format...
  --         [#mac: "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü...",
  --          #win: "Ÿ‰«Š‹÷зý’”“ÂÁÈËÍÎÌÏÓÔÒÛÚÙ–ž™˜š¸..."]
  --         ... corresponding to the character mappings on Macintosh
  --         and Windows for the numToChar(128 - 255)
  --------------------------------------------------------------------
  
  vWinString = ""
  vMacString = ""
  
  if (the platform starts "Mac") then
    vWinFontMap = [ \
196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, \
231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, \
246, 245, 250, 249, 251, 252, 134, 176, 162, 163, 167, 149, 182, \
223, 174, 169, 153, 180, 168, 141, 198, 216, 144, 177, 143, 142, \
165, 181, 240, 221, 222, 254, 138, 170, 186, 253, 230, 248, 191, \
161, 172, 175, 131, 188, 208, 171, 187, 133, 160, 192, 195, 213, \
140, 156, 173, 151, 147, 148, 145, 146, 247, 215, 255, 159, 158, \
164, 139, 155, 128, 129, 135, 183, 130, 132, 137, 194, 202, 193, \
203, 200, 205, 206, 207, 204, 211, 212, 157, 210, 218, 219, 217, \
166, 136, 152, 150, 154, 178, 190, 184, 189, 179, 185]
    
    repeat with i = 1 to 128
      vNum = vWinFontMap[i]
      put numToChar(vNum) after vWinString
      
      put numToChar(i + 127) after vMacString
    end repeat
    
  else
    vMacFontMap = [ \
219, 223, 226, 196, 227, 201, 160, 224, 246, 228, 186, 220, 206, \
173, 179, 178, 176, 212, 213, 210, 211, 165, 248, 209, 247, 170, \
249, 221, 207, 240, 218, 217, 202, 193, 162, 163, 219, 180, 245, \
164, 172, 169, 187, 199, 194, 208, 168, 195, 161, 177, 250, 254, \
171, 181, 166, 225, 252, 255, 188, 200, 197, 253, 251, 192, 203, \
231, 229, 204, 128, 129, 174, 130, 233, 131, 230, 232, 237, 234, \
235, 236, 198, 132, 241, 238, 239, 205, 133, 215, 175, 244, 242, \
243, 134, 183, 184, 167, 136, 135, 137, 139, 138, 140, 190, 141, \
143, 142, 144, 145, 147, 146, 148, 149, 182, 150, 152, 151, 153, \
155, 154, 214, 191, 157, 156, 158, 159, 189, 185, 216]
    
    repeat with i = 1 to 128
      vNum = vMacFontMap[i]
      put numToChar(vNum) after vMacString
      
      put numToChar(i + 127) after vWinString
    end repeat
  end if
  
  return [#mac: vMacString, #win: vWinString]
end GetHighANSIStrings



on ConvertToWin(aString) ---------------------------------------------
  -- INPUT: <aString> must be a string.  This is expected to be in
  --         Macintosh format
  -- OUTPUT: Returns a string in Windows format.  LineFeed characters
  --         will be added to the string after RETURN characters.
  --------------------------------------------------------------------
  
  vStringList = list(aString)
  vStrings    = GetHighANSIStrings()
  
  re_tr(vStringList, vStrings.mac, vStrings.win)
  re_s (vStringList, RETURN, "g", RETURN&numToChar(10))
  
  return vStringList.getLast()
end ConvertToWin



on ConvertToMac(aString)---------------------------------------------
  -- INPUT: <aString> must be a string.  This is expected to be in
  --         Windows format
  -- OUTPUT: Returns a string in Macintosh format.  LineFeed
  --         characters in the string will be deleted.
  --------------------------------------------------------------------
  
  vStringList = list(aString)
  vStrings    = GetHighANSIStrings()
  
  re_tr(vStringList, vStrings.win, vStrings.mac)
  re_s (vStringList, numToChar(10), "g", "")
  
  return vStringList.getLast()
end ConvertToMac



pistes-l List Home | Main Index | Thread Index
Search archives

 

 


© 2002 Integration New Media. All rights reserved.
Legal | Sitemap

 

Services Solutions Products Support Gallery Store Download Feedback Contact About Us