Eliminating Unicode accents in Apex

Is there a published way to take text that may have accent marks and remove the accent marks?

For example:

System.assertEquals('Hello', transform('Ḧéļḻṏ'));

I believe there is an equivalent method in Java, C# and JavaScript.
I can’t seem to find the Apex equivalent and I’m disturbed that I might have to do it on my own.

Answer

This is a newer revision of Adrian Larson’s previous answer for benchmark comparison.

This should work quite well for short-ish text fields quite well at the expense of some bytes of heap. For a longer text field, it takes longer.

Long story short, if you have very limited heap space (or disk space), it might make sense to use Adrian’s method. Also, if you can spare performance in exchange for legibility, Adrian’s is certainly better! If you have ~19kB of disk space and 17kB heap, this is more performant.

Test results

Environment: CS61 sandbox through anonymous apex on Spring ’17 Patch 4

Test Suite: Strings with an unusually-high percentage of accented characters. Taken from TextMechanic.com.

This code

  • Heap: 16980
  • Disk: 18664
  • Runs on 660-char: 2.6ms
  • Runs on 255-char: 1ms
  • Runs on shortish strings: 0.2ms

Adrian’s code

  • Heap: 3154
  • Disk: 6933
  • Runs on 660-char: 8.1ms (surprisingly bad Regex perf!)
  • Runs on 255-char: 3.3ms
  • Runs on shortish strings: 1.2ms
  static Integer[] A_CHARS_U = new Integer[]{65};
  static Integer[] AA_CHARS_UU = new Integer[]{65,65};
  static Integer[] AE_CHARS_UU = new Integer[]{65,69};
  static Integer[] AO_CHARS_UU = new Integer[]{65,79};
  static Integer[] AU_CHARS_UU = new Integer[]{65,85};
  static Integer[] AV_CHARS_UU = new Integer[]{65,86};
  static Integer[] AY_CHARS_UU = new Integer[]{65,89};
  static Integer[] B_CHARS_U = new Integer[]{66};
  static Integer[] C_CHARS_U = new Integer[]{67};
  static Integer[] D_CHARS_U = new Integer[]{68};
  static Integer[] DZ_CHARS_UU = new Integer[]{68,90};
  static Integer[] DZ_CHARS_UL = new Integer[]{68,122};
  static Integer[] E_CHARS_U = new Integer[]{69};
  static Integer[] F_CHARS_U = new Integer[]{70};
  static Integer[] G_CHARS_U = new Integer[]{71};
  static Integer[] H_CHARS_U = new Integer[]{72};
  static Integer[] I_CHARS_U = new Integer[]{73};
  static Integer[] J_CHARS_U = new Integer[]{74};
  static Integer[] K_CHARS_U = new Integer[]{75};
  static Integer[] L_CHARS_U = new Integer[]{76};
  static Integer[] LJ_CHARS_UU = new Integer[]{76,74};
  static Integer[] LJ_CHARS_UL = new Integer[]{76,106};
  static Integer[] M_CHARS_U = new Integer[]{77};
  static Integer[] N_CHARS_U = new Integer[]{78};
  static Integer[] NJ_CHARS_UU = new Integer[]{78,74};
  static Integer[] NJ_CHARS_UL = new Integer[]{78,106};
  static Integer[] O_CHARS_U = new Integer[]{79};
  static Integer[] OI_CHARS_UU = new Integer[]{79,73};
  static Integer[] OO_CHARS_UU = new Integer[]{79,79};
  static Integer[] OU_CHARS_UU = new Integer[]{79,85};
  static Integer[] P_CHARS_U = new Integer[]{80};
  static Integer[] Q_CHARS_U = new Integer[]{81};
  static Integer[] R_CHARS_U = new Integer[]{82};
  static Integer[] S_CHARS_U = new Integer[]{83};
  static Integer[] T_CHARS_U = new Integer[]{84};
  static Integer[] TZ_CHARS_UU = new Integer[]{84,90};
  static Integer[] U_CHARS_U = new Integer[]{85};
  static Integer[] V_CHARS_U = new Integer[]{86};
  static Integer[] VY_CHARS_UU = new Integer[]{86,89};
  static Integer[] W_CHARS_U = new Integer[]{87};
  static Integer[] X_CHARS_U = new Integer[]{88};
  static Integer[] Y_CHARS_U = new Integer[]{89};
  static Integer[] Z_CHARS_U = new Integer[]{90};
  static Integer[] A_CHARS_L = new Integer[]{97};
  static Integer[] AA_CHARS_LL = new Integer[]{97,97};
  static Integer[] AE_CHARS_LL = new Integer[]{97,101};
  static Integer[] AO_CHARS_LL = new Integer[]{97,111};
  static Integer[] AU_CHARS_LL = new Integer[]{97,117};
  static Integer[] AV_CHARS_LL = new Integer[]{97,118};
  static Integer[] AY_CHARS_LL = new Integer[]{97,121};
  static Integer[] B_CHARS_L = new Integer[]{98};
  static Integer[] C_CHARS_L = new Integer[]{99};
  static Integer[] D_CHARS_L = new Integer[]{100};
  static Integer[] DZ_CHARS_LL = new Integer[]{100,122};
  static Integer[] E_CHARS_L = new Integer[]{101};
  static Integer[] F_CHARS_L = new Integer[]{102};
  static Integer[] G_CHARS_L = new Integer[]{103};
  static Integer[] H_CHARS_L = new Integer[]{104};
  static Integer[] HV_CHARS_LL = new Integer[]{104,118};
  static Integer[] I_CHARS_L = new Integer[]{105};
  static Integer[] J_CHARS_L = new Integer[]{106};
  static Integer[] K_CHARS_L = new Integer[]{107};
  static Integer[] L_CHARS_L = new Integer[]{108};
  static Integer[] LJ_CHARS_LL = new Integer[]{108,106};
  static Integer[] M_CHARS_L = new Integer[]{109};
  static Integer[] N_CHARS_L = new Integer[]{110};
  static Integer[] NJ_CHARS_LL = new Integer[]{110,106};
  static Integer[] O_CHARS_L = new Integer[]{111};
  static Integer[] OI_CHARS_LL = new Integer[]{111,105};
  static Integer[] OU_CHARS_LL = new Integer[]{111,117};
  static Integer[] OO_CHARS_LL = new Integer[]{111,111};
  static Integer[] P_CHARS_L = new Integer[]{112};
  static Integer[] Q_CHARS_L = new Integer[]{113};
  static Integer[] R_CHARS_L = new Integer[]{114};
  static Integer[] S_CHARS_L = new Integer[]{115};
  static Integer[] T_CHARS_L = new Integer[]{116};
  static Integer[] TZ_CHARS_LL = new Integer[]{116,122};
  static Integer[] U_CHARS_L = new Integer[]{117};
  static Integer[] V_CHARS_L = new Integer[]{118};
  static Integer[] VY_CHARS_LL = new Integer[]{118,121};
  static Integer[] W_CHARS_L = new Integer[]{119};
  static Integer[] X_CHARS_L = new Integer[]{120};
  static Integer[] Y_CHARS_L = new Integer[]{121};
  static Integer[] Z_CHARS_L = new Integer[]{122};

  static Map<Integer, List<Integer>> DIACRITIC_MAP = new Map<Integer, List<Integer>>{
    65=>A_CHARS_U,9398=>A_CHARS_U,65313=>A_CHARS_U,192=>A_CHARS_U,193=>A_CHARS_U,194=>A_CHARS_U,7846=>A_CHARS_U,7844=>A_CHARS_U,7850=>A_CHARS_U,7848=>A_CHARS_U,195=>A_CHARS_U,256=>A_CHARS_U,258=>A_CHARS_U,7856=>A_CHARS_U,7854=>A_CHARS_U,7860=>A_CHARS_U,7858=>A_CHARS_U,550=>A_CHARS_U,480=>A_CHARS_U,196=>A_CHARS_U,478=>A_CHARS_U,7842=>A_CHARS_U,197=>A_CHARS_U,506=>A_CHARS_U,461=>A_CHARS_U,512=>A_CHARS_U,514=>A_CHARS_U,7840=>A_CHARS_U,7852=>A_CHARS_U,7862=>A_CHARS_U,7680=>A_CHARS_U,260=>A_CHARS_U,570=>A_CHARS_U,11375=>A_CHARS_U,42802=>AA_CHARS_UU,198=>AE_CHARS_UU,508=>AE_CHARS_UU,482=>AE_CHARS_UU,42804=>AO_CHARS_UU,42806=>AU_CHARS_UU,42808=>AV_CHARS_UU,42810=>AV_CHARS_UU,42812=>AY_CHARS_UU,66=>B_CHARS_U,9399=>B_CHARS_U,65314=>B_CHARS_U,7682=>B_CHARS_U,7684=>B_CHARS_U,7686=>B_CHARS_U,579=>B_CHARS_U,386=>B_CHARS_U,385=>B_CHARS_U,67=>C_CHARS_U,9400=>C_CHARS_U,65315=>C_CHARS_U,262=>C_CHARS_U,264=>C_CHARS_U,266=>C_CHARS_U,268=>C_CHARS_U,199=>C_CHARS_U,7688=>C_CHARS_U,391=>C_CHARS_U,571=>C_CHARS_U,42814=>C_CHARS_U,68=>D_CHARS_U,9401=>D_CHARS_U,65316=>D_CHARS_U,7690=>D_CHARS_U,270=>D_CHARS_U,7692=>D_CHARS_U,7696=>D_CHARS_U,7698=>D_CHARS_U,7694=>D_CHARS_U,272=>D_CHARS_U,395=>D_CHARS_U,394=>D_CHARS_U,393=>D_CHARS_U,42873=>D_CHARS_U,497=>DZ_CHARS_UU,452=>DZ_CHARS_UU,498=>DZ_CHARS_UL,453=>DZ_CHARS_UL,69=>E_CHARS_U,9402=>E_CHARS_U,65317=>E_CHARS_U,200=>E_CHARS_U,201=>E_CHARS_U,202=>E_CHARS_U,7872=>E_CHARS_U,7870=>E_CHARS_U,7876=>E_CHARS_U,7874=>E_CHARS_U,7868=>E_CHARS_U,274=>E_CHARS_U,7700=>E_CHARS_U,7702=>E_CHARS_U,276=>E_CHARS_U,278=>E_CHARS_U,203=>E_CHARS_U,7866=>E_CHARS_U,282=>E_CHARS_U,516=>E_CHARS_U,518=>E_CHARS_U,7864=>E_CHARS_U,7878=>E_CHARS_U,552=>E_CHARS_U,7708=>E_CHARS_U,280=>E_CHARS_U,7704=>E_CHARS_U,7706=>E_CHARS_U,400=>E_CHARS_U,398=>E_CHARS_U,70=>F_CHARS_U,9403=>F_CHARS_U,65318=>F_CHARS_U,7710=>F_CHARS_U,401=>F_CHARS_U,42875=>F_CHARS_U,71=>G_CHARS_U,9404=>G_CHARS_U,65319=>G_CHARS_U,500=>G_CHARS_U,284=>G_CHARS_U,7712=>G_CHARS_U,286=>G_CHARS_U,288=>G_CHARS_U,486=>G_CHARS_U,290=>G_CHARS_U,484=>G_CHARS_U,403=>G_CHARS_U,42912=>G_CHARS_U,42877=>G_CHARS_U,42878=>G_CHARS_U,72=>H_CHARS_U,9405=>H_CHARS_U,65320=>H_CHARS_U,292=>H_CHARS_U,7714=>H_CHARS_U,7718=>H_CHARS_U,542=>H_CHARS_U,7716=>H_CHARS_U,7720=>H_CHARS_U,7722=>H_CHARS_U,294=>H_CHARS_U,11367=>H_CHARS_U,11381=>H_CHARS_U,42893=>H_CHARS_U,73=>I_CHARS_U,9406=>I_CHARS_U,65321=>I_CHARS_U,204=>I_CHARS_U,205=>I_CHARS_U,206=>I_CHARS_U,296=>I_CHARS_U,298=>I_CHARS_U,300=>I_CHARS_U,304=>I_CHARS_U,207=>I_CHARS_U,7726=>I_CHARS_U,7880=>I_CHARS_U,463=>I_CHARS_U,520=>I_CHARS_U,522=>I_CHARS_U,7882=>I_CHARS_U,302=>I_CHARS_U,7724=>I_CHARS_U,407=>I_CHARS_U,74=>J_CHARS_U,9407=>J_CHARS_U,65322=>J_CHARS_U,308=>J_CHARS_U,584=>J_CHARS_U,75=>K_CHARS_U,9408=>K_CHARS_U,65323=>K_CHARS_U,7728=>K_CHARS_U,488=>K_CHARS_U,7730=>K_CHARS_U,310=>K_CHARS_U,7732=>K_CHARS_U,408=>K_CHARS_U,11369=>K_CHARS_U,42816=>K_CHARS_U,42818=>K_CHARS_U,42820=>K_CHARS_U,42914=>K_CHARS_U,76=>L_CHARS_U,9409=>L_CHARS_U,65324=>L_CHARS_U,319=>L_CHARS_U,313=>L_CHARS_U,317=>L_CHARS_U,7734=>L_CHARS_U,7736=>L_CHARS_U,315=>L_CHARS_U,7740=>L_CHARS_U,7738=>L_CHARS_U,321=>L_CHARS_U,573=>L_CHARS_U,11362=>L_CHARS_U,11360=>L_CHARS_U,42824=>L_CHARS_U,42822=>L_CHARS_U,42880=>L_CHARS_U,455=>LJ_CHARS_UU,456=>LJ_CHARS_UL,77=>M_CHARS_U,9410=>M_CHARS_U,65325=>M_CHARS_U,7742=>M_CHARS_U,7744=>M_CHARS_U,7746=>M_CHARS_U,11374=>M_CHARS_U,412=>M_CHARS_U,78=>N_CHARS_U,9411=>N_CHARS_U,65326=>N_CHARS_U,504=>N_CHARS_U,323=>N_CHARS_U,209=>N_CHARS_U,7748=>N_CHARS_U,327=>N_CHARS_U,7750=>N_CHARS_U,325=>N_CHARS_U,7754=>N_CHARS_U,7752=>N_CHARS_U,544=>N_CHARS_U,413=>N_CHARS_U,42896=>N_CHARS_U,42916=>N_CHARS_U,458=>NJ_CHARS_UU,459=>NJ_CHARS_UL,79=>O_CHARS_U,9412=>O_CHARS_U,65327=>O_CHARS_U,210=>O_CHARS_U,211=>O_CHARS_U,212=>O_CHARS_U,7890=>O_CHARS_U,7888=>O_CHARS_U,7894=>O_CHARS_U,7892=>O_CHARS_U,213=>O_CHARS_U,7756=>O_CHARS_U,556=>O_CHARS_U,7758=>O_CHARS_U,332=>O_CHARS_U,7760=>O_CHARS_U,7762=>O_CHARS_U,334=>O_CHARS_U,558=>O_CHARS_U,560=>O_CHARS_U,214=>O_CHARS_U,554=>O_CHARS_U,7886=>O_CHARS_U,336=>O_CHARS_U,465=>O_CHARS_U,524=>O_CHARS_U,526=>O_CHARS_U,416=>O_CHARS_U,7900=>O_CHARS_U,7898=>O_CHARS_U,7904=>O_CHARS_U,7902=>O_CHARS_U,7906=>O_CHARS_U,7884=>O_CHARS_U,7896=>O_CHARS_U,490=>O_CHARS_U,492=>O_CHARS_U,216=>O_CHARS_U,510=>O_CHARS_U,390=>O_CHARS_U,415=>O_CHARS_U,42826=>O_CHARS_U,42828=>O_CHARS_U,418=>OI_CHARS_UU,42830=>OO_CHARS_UU,546=>OU_CHARS_UU,80=>P_CHARS_U,9413=>P_CHARS_U,65328=>P_CHARS_U,7764=>P_CHARS_U,7766=>P_CHARS_U,420=>P_CHARS_U,11363=>P_CHARS_U,42832=>P_CHARS_U,42834=>P_CHARS_U,42836=>P_CHARS_U,81=>Q_CHARS_U,9414=>Q_CHARS_U,65329=>Q_CHARS_U,42838=>Q_CHARS_U,42840=>Q_CHARS_U,586=>Q_CHARS_U,82=>R_CHARS_U,9415=>R_CHARS_U,65330=>R_CHARS_U,340=>R_CHARS_U,7768=>R_CHARS_U,344=>R_CHARS_U,528=>R_CHARS_U,530=>R_CHARS_U,7770=>R_CHARS_U,7772=>R_CHARS_U,342=>R_CHARS_U,7774=>R_CHARS_U,588=>R_CHARS_U,11364=>R_CHARS_U,42842=>R_CHARS_U,42918=>R_CHARS_U,42882=>R_CHARS_U,83=>S_CHARS_U,9416=>S_CHARS_U,65331=>S_CHARS_U,7838=>S_CHARS_U,346=>S_CHARS_U,7780=>S_CHARS_U,348=>S_CHARS_U,7776=>S_CHARS_U,352=>S_CHARS_U,7782=>S_CHARS_U,7778=>S_CHARS_U,7784=>S_CHARS_U,536=>S_CHARS_U,350=>S_CHARS_U,11390=>S_CHARS_U,42920=>S_CHARS_U,42884=>S_CHARS_U,84=>T_CHARS_U,9417=>T_CHARS_U,65332=>T_CHARS_U,7786=>T_CHARS_U,356=>T_CHARS_U,7788=>T_CHARS_U,538=>T_CHARS_U,354=>T_CHARS_U,7792=>T_CHARS_U,7790=>T_CHARS_U,358=>T_CHARS_U,428=>T_CHARS_U,430=>T_CHARS_U,574=>T_CHARS_U,42886=>T_CHARS_U,42792=>TZ_CHARS_UU,85=>U_CHARS_U,9418=>U_CHARS_U,65333=>U_CHARS_U,217=>U_CHARS_U,218=>U_CHARS_U,219=>U_CHARS_U,360=>U_CHARS_U,7800=>U_CHARS_U,362=>U_CHARS_U,7802=>U_CHARS_U,364=>U_CHARS_U,220=>U_CHARS_U,475=>U_CHARS_U,471=>U_CHARS_U,469=>U_CHARS_U,473=>U_CHARS_U,7910=>U_CHARS_U,366=>U_CHARS_U,368=>U_CHARS_U,467=>U_CHARS_U,532=>U_CHARS_U,534=>U_CHARS_U,431=>U_CHARS_U,7914=>U_CHARS_U,7912=>U_CHARS_U,7918=>U_CHARS_U,7916=>U_CHARS_U,7920=>U_CHARS_U,7908=>U_CHARS_U,7794=>U_CHARS_U,370=>U_CHARS_U,7798=>U_CHARS_U,7796=>U_CHARS_U,580=>U_CHARS_U,86=>V_CHARS_U,9419=>V_CHARS_U,65334=>V_CHARS_U,7804=>V_CHARS_U,7806=>V_CHARS_U,434=>V_CHARS_U,42846=>V_CHARS_U,581=>V_CHARS_U,42848=>VY_CHARS_UU,87=>W_CHARS_U,9420=>W_CHARS_U,65335=>W_CHARS_U,7808=>W_CHARS_U,7810=>W_CHARS_U,372=>W_CHARS_U,7814=>W_CHARS_U,7812=>W_CHARS_U,7816=>W_CHARS_U,11378=>W_CHARS_U,88=>X_CHARS_U,9421=>X_CHARS_U,65336=>X_CHARS_U,7818=>X_CHARS_U,7820=>X_CHARS_U,89=>Y_CHARS_U,9422=>Y_CHARS_U,65337=>Y_CHARS_U,7922=>Y_CHARS_U,221=>Y_CHARS_U,374=>Y_CHARS_U,7928=>Y_CHARS_U,562=>Y_CHARS_U,7822=>Y_CHARS_U,376=>Y_CHARS_U,7926=>Y_CHARS_U,7924=>Y_CHARS_U,435=>Y_CHARS_U,590=>Y_CHARS_U,7934=>Y_CHARS_U,90=>Z_CHARS_U,9423=>Z_CHARS_U,65338=>Z_CHARS_U,377=>Z_CHARS_U,7824=>Z_CHARS_U,379=>Z_CHARS_U,381=>Z_CHARS_U,7826=>Z_CHARS_U,7828=>Z_CHARS_U,437=>Z_CHARS_U,548=>Z_CHARS_U,11391=>Z_CHARS_U,11371=>Z_CHARS_U,42850=>Z_CHARS_U,97=>A_CHARS_L,9424=>A_CHARS_L,65345=>A_CHARS_L,7834=>A_CHARS_L,224=>A_CHARS_L,225=>A_CHARS_L,226=>A_CHARS_L,7847=>A_CHARS_L,7845=>A_CHARS_L,7851=>A_CHARS_L,7849=>A_CHARS_L,227=>A_CHARS_L,257=>A_CHARS_L,259=>A_CHARS_L,7857=>A_CHARS_L,7855=>A_CHARS_L,7861=>A_CHARS_L,7859=>A_CHARS_L,551=>A_CHARS_L,481=>A_CHARS_L,228=>A_CHARS_L,479=>A_CHARS_L,7843=>A_CHARS_L,229=>A_CHARS_L,507=>A_CHARS_L,462=>A_CHARS_L,513=>A_CHARS_L,515=>A_CHARS_L,7841=>A_CHARS_L,7853=>A_CHARS_L,7863=>A_CHARS_L,7681=>A_CHARS_L,261=>A_CHARS_L,11365=>A_CHARS_L,592=>A_CHARS_L,42803=>AA_CHARS_LL,230=>AE_CHARS_LL,509=>AE_CHARS_LL,483=>AE_CHARS_LL,42805=>AO_CHARS_LL,42807=>AU_CHARS_LL,42809=>AV_CHARS_LL,42811=>AV_CHARS_LL,42813=>AY_CHARS_LL,98=>B_CHARS_L,9425=>B_CHARS_L,65346=>B_CHARS_L,7683=>B_CHARS_L,7685=>B_CHARS_L,7687=>B_CHARS_L,384=>B_CHARS_L,387=>B_CHARS_L,595=>B_CHARS_L,99=>C_CHARS_L,9426=>C_CHARS_L,65347=>C_CHARS_L,263=>C_CHARS_L,265=>C_CHARS_L,267=>C_CHARS_L,269=>C_CHARS_L,231=>C_CHARS_L,7689=>C_CHARS_L,392=>C_CHARS_L,572=>C_CHARS_L,42815=>C_CHARS_L,8580=>C_CHARS_L,100=>D_CHARS_L,9427=>D_CHARS_L,65348=>D_CHARS_L,7691=>D_CHARS_L,271=>D_CHARS_L,7693=>D_CHARS_L,7697=>D_CHARS_L,7699=>D_CHARS_L,7695=>D_CHARS_L,273=>D_CHARS_L,396=>D_CHARS_L,598=>D_CHARS_L,599=>D_CHARS_L,42874=>D_CHARS_L,499=>DZ_CHARS_LL,454=>DZ_CHARS_LL,101=>E_CHARS_L,9428=>E_CHARS_L,65349=>E_CHARS_L,232=>E_CHARS_L,233=>E_CHARS_L,234=>E_CHARS_L,7873=>E_CHARS_L,7871=>E_CHARS_L,7877=>E_CHARS_L,7875=>E_CHARS_L,7869=>E_CHARS_L,275=>E_CHARS_L,7701=>E_CHARS_L,7703=>E_CHARS_L,277=>E_CHARS_L,279=>E_CHARS_L,235=>E_CHARS_L,7867=>E_CHARS_L,283=>E_CHARS_L,517=>E_CHARS_L,519=>E_CHARS_L,7865=>E_CHARS_L,7879=>E_CHARS_L,553=>E_CHARS_L,7709=>E_CHARS_L,281=>E_CHARS_L,7705=>E_CHARS_L,7707=>E_CHARS_L,583=>E_CHARS_L,603=>E_CHARS_L,477=>E_CHARS_L,102=>F_CHARS_L,9429=>F_CHARS_L,65350=>F_CHARS_L,7711=>F_CHARS_L,402=>F_CHARS_L,42876=>F_CHARS_L,103=>G_CHARS_L,9430=>G_CHARS_L,65351=>G_CHARS_L,501=>G_CHARS_L,285=>G_CHARS_L,7713=>G_CHARS_L,287=>G_CHARS_L,289=>G_CHARS_L,487=>G_CHARS_L,291=>G_CHARS_L,485=>G_CHARS_L,608=>G_CHARS_L,42913=>G_CHARS_L,7545=>G_CHARS_L,42879=>G_CHARS_L,104=>H_CHARS_L,9431=>H_CHARS_L,65352=>H_CHARS_L,293=>H_CHARS_L,7715=>H_CHARS_L,7719=>H_CHARS_L,543=>H_CHARS_L,7717=>H_CHARS_L,7721=>H_CHARS_L,7723=>H_CHARS_L,7830=>H_CHARS_L,295=>H_CHARS_L,11368=>H_CHARS_L,11382=>H_CHARS_L,613=>H_CHARS_L,405=>HV_CHARS_LL,105=>I_CHARS_L,9432=>I_CHARS_L,65353=>I_CHARS_L,236=>I_CHARS_L,237=>I_CHARS_L,238=>I_CHARS_L,297=>I_CHARS_L,299=>I_CHARS_L,301=>I_CHARS_L,239=>I_CHARS_L,7727=>I_CHARS_L,7881=>I_CHARS_L,464=>I_CHARS_L,521=>I_CHARS_L,523=>I_CHARS_L,7883=>I_CHARS_L,303=>I_CHARS_L,7725=>I_CHARS_L,616=>I_CHARS_L,305=>I_CHARS_L,106=>J_CHARS_L,9433=>J_CHARS_L,65354=>J_CHARS_L,309=>J_CHARS_L,496=>J_CHARS_L,585=>J_CHARS_L,107=>K_CHARS_L,9434=>K_CHARS_L,65355=>K_CHARS_L,7729=>K_CHARS_L,489=>K_CHARS_L,7731=>K_CHARS_L,311=>K_CHARS_L,7733=>K_CHARS_L,409=>K_CHARS_L,11370=>K_CHARS_L,42817=>K_CHARS_L,42819=>K_CHARS_L,42821=>K_CHARS_L,42915=>K_CHARS_L,108=>L_CHARS_L,9435=>L_CHARS_L,65356=>L_CHARS_L,320=>L_CHARS_L,314=>L_CHARS_L,318=>L_CHARS_L,7735=>L_CHARS_L,7737=>L_CHARS_L,316=>L_CHARS_L,7741=>L_CHARS_L,7739=>L_CHARS_L,383=>L_CHARS_L,322=>L_CHARS_L,410=>L_CHARS_L,619=>L_CHARS_L,11361=>L_CHARS_L,42825=>L_CHARS_L,42881=>L_CHARS_L,42823=>L_CHARS_L,457=>LJ_CHARS_LL,109=>M_CHARS_L,9436=>M_CHARS_L,65357=>M_CHARS_L,7743=>M_CHARS_L,7745=>M_CHARS_L,7747=>M_CHARS_L,625=>M_CHARS_L,623=>M_CHARS_L,110=>N_CHARS_L,9437=>N_CHARS_L,65358=>N_CHARS_L,505=>N_CHARS_L,324=>N_CHARS_L,241=>N_CHARS_L,7749=>N_CHARS_L,328=>N_CHARS_L,7751=>N_CHARS_L,326=>N_CHARS_L,7755=>N_CHARS_L,7753=>N_CHARS_L,414=>N_CHARS_L,626=>N_CHARS_L,329=>N_CHARS_L,42897=>N_CHARS_L,42917=>N_CHARS_L,460=>NJ_CHARS_LL,111=>O_CHARS_L,9438=>O_CHARS_L,65359=>O_CHARS_L,242=>O_CHARS_L,243=>O_CHARS_L,244=>O_CHARS_L,7891=>O_CHARS_L,7889=>O_CHARS_L,7895=>O_CHARS_L,7893=>O_CHARS_L,245=>O_CHARS_L,7757=>O_CHARS_L,557=>O_CHARS_L,7759=>O_CHARS_L,333=>O_CHARS_L,7761=>O_CHARS_L,7763=>O_CHARS_L,335=>O_CHARS_L,559=>O_CHARS_L,561=>O_CHARS_L,246=>O_CHARS_L,555=>O_CHARS_L,7887=>O_CHARS_L,337=>O_CHARS_L,466=>O_CHARS_L,525=>O_CHARS_L,527=>O_CHARS_L,417=>O_CHARS_L,7901=>O_CHARS_L,7899=>O_CHARS_L,7905=>O_CHARS_L,7903=>O_CHARS_L,7907=>O_CHARS_L,7885=>O_CHARS_L,7897=>O_CHARS_L,491=>O_CHARS_L,493=>O_CHARS_L,248=>O_CHARS_L,511=>O_CHARS_L,596=>O_CHARS_L,42827=>O_CHARS_L,42829=>O_CHARS_L,629=>O_CHARS_L,419=>OI_CHARS_LL,547=>OU_CHARS_LL,42831=>OO_CHARS_LL,112=>P_CHARS_L,9439=>P_CHARS_L,65360=>P_CHARS_L,7765=>P_CHARS_L,7767=>P_CHARS_L,421=>P_CHARS_L,7549=>P_CHARS_L,42833=>P_CHARS_L,42835=>P_CHARS_L,42837=>P_CHARS_L,113=>Q_CHARS_L,9440=>Q_CHARS_L,65361=>Q_CHARS_L,587=>Q_CHARS_L,42839=>Q_CHARS_L,42841=>Q_CHARS_L,114=>R_CHARS_L,9441=>R_CHARS_L,65362=>R_CHARS_L,341=>R_CHARS_L,7769=>R_CHARS_L,345=>R_CHARS_L,529=>R_CHARS_L,531=>R_CHARS_L,7771=>R_CHARS_L,7773=>R_CHARS_L,343=>R_CHARS_L,7775=>R_CHARS_L,589=>R_CHARS_L,637=>R_CHARS_L,42843=>R_CHARS_L,42919=>R_CHARS_L,42883=>R_CHARS_L,115=>S_CHARS_L,9442=>S_CHARS_L,65363=>S_CHARS_L,223=>S_CHARS_L,347=>S_CHARS_L,7781=>S_CHARS_L,349=>S_CHARS_L,7777=>S_CHARS_L,353=>S_CHARS_L,7783=>S_CHARS_L,7779=>S_CHARS_L,7785=>S_CHARS_L,537=>S_CHARS_L,351=>S_CHARS_L,575=>S_CHARS_L,42921=>S_CHARS_L,42885=>S_CHARS_L,7835=>S_CHARS_L,116=>T_CHARS_L,9443=>T_CHARS_L,65364=>T_CHARS_L,7787=>T_CHARS_L,7831=>T_CHARS_L,357=>T_CHARS_L,7789=>T_CHARS_L,539=>T_CHARS_L,355=>T_CHARS_L,7793=>T_CHARS_L,7791=>T_CHARS_L,359=>T_CHARS_L,429=>T_CHARS_L,648=>T_CHARS_L,11366=>T_CHARS_L,42887=>T_CHARS_L,42793=>TZ_CHARS_LL,117=>U_CHARS_L,9444=>U_CHARS_L,65365=>U_CHARS_L,249=>U_CHARS_L,250=>U_CHARS_L,251=>U_CHARS_L,361=>U_CHARS_L,7801=>U_CHARS_L,363=>U_CHARS_L,7803=>U_CHARS_L,365=>U_CHARS_L,252=>U_CHARS_L,476=>U_CHARS_L,472=>U_CHARS_L,470=>U_CHARS_L,474=>U_CHARS_L,7911=>U_CHARS_L,367=>U_CHARS_L,369=>U_CHARS_L,468=>U_CHARS_L,533=>U_CHARS_L,535=>U_CHARS_L,432=>U_CHARS_L,7915=>U_CHARS_L,7913=>U_CHARS_L,7919=>U_CHARS_L,7917=>U_CHARS_L,7921=>U_CHARS_L,7909=>U_CHARS_L,7795=>U_CHARS_L,371=>U_CHARS_L,7799=>U_CHARS_L,7797=>U_CHARS_L,649=>U_CHARS_L,118=>V_CHARS_L,9445=>V_CHARS_L,65366=>V_CHARS_L,7805=>V_CHARS_L,7807=>V_CHARS_L,651=>V_CHARS_L,42847=>V_CHARS_L,652=>V_CHARS_L,42849=>VY_CHARS_LL,119=>W_CHARS_L,9446=>W_CHARS_L,65367=>W_CHARS_L,7809=>W_CHARS_L,7811=>W_CHARS_L,373=>W_CHARS_L,7815=>W_CHARS_L,7813=>W_CHARS_L,7832=>W_CHARS_L,7817=>W_CHARS_L,11379=>W_CHARS_L,120=>X_CHARS_L,9447=>X_CHARS_L,65368=>X_CHARS_L,7819=>X_CHARS_L,7821=>X_CHARS_L,121=>Y_CHARS_L,9448=>Y_CHARS_L,65369=>Y_CHARS_L,7923=>Y_CHARS_L,253=>Y_CHARS_L,375=>Y_CHARS_L,7929=>Y_CHARS_L,563=>Y_CHARS_L,7823=>Y_CHARS_L,255=>Y_CHARS_L,7927=>Y_CHARS_L,7833=>Y_CHARS_L,7925=>Y_CHARS_L,436=>Y_CHARS_L,591=>Y_CHARS_L,7935=>Y_CHARS_L,122=>Z_CHARS_L,9449=>Z_CHARS_L,65370=>Z_CHARS_L,378=>Z_CHARS_L,7825=>Z_CHARS_L,380=>Z_CHARS_L,382=>Z_CHARS_L,7827=>Z_CHARS_L,7829=>Z_CHARS_L,438=>Z_CHARS_L,549=>Z_CHARS_L,576=>Z_CHARS_L,11372=>Z_CHARS_L,42851=>Z_CHARS_L
  };

  // Thanks to Adrian Larson at https://salesforce.stackexchange.com/a/155379
  // and TextMechanic.com http://textmechanic.com/wp-content/uploads/source/Remove-Letter-Accents.html
  static String removeDiacritics(String str) {
    if (str == null) {
      return null;
    }
    List<Integer> result = new List<Integer>();
    for (Integer chr : str.getChars()) {
      if (DIACRITIC_MAP.containsKey(chr)) {
        result.addAll(DIACRITIC_MAP.get(chr));
      } else {
        result.add(chr);
      }
    }
    return String.fromCharArray(result);
  }

Attribution
Source : Link , Question Author : Charles Koppelman , Answer Author : Community

Leave a Comment