tomasslavicek

Replace special characters (diacritics), Garmin Connect IQ

Oct 28th, 2018
173
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function replaceDiaText(sourceText) { //0.9 kB, .mc file must be saved in the UTF-8 encoding
  2.     if (sourceText == null) { return null; }
  3.     var outputText = "";
  4.     var in =  "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĴĵĶķĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžƀƁƂƃƇƈƊƋƌƑƒƓƗƘƙƚƝƞƟƠơƤƥƫƬƭƮƯưƲƳƴƵƶDžLjNjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǞǟǠǡǤǥǦǧǨǩǪǫǬǭǰDzǴǵǸǹǺǻǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȞȟȠȡȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳ";
  5.     var out = "AAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiJjKkLlLlLlLlLlNnNnNnnOoOoOoRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzbBBbCcDDdFfGIKklNnOOoPptTtTUuVYyZzDLNAaIiOoUuUuUuUuUuAaAaGgGgKkOoOojDGgNnAaOoAaAaEeEeIiIiOoOoRrRrUuUuSsTtHhNdZzAaEeOoOoOoOoYy";
  6.    
  7.     var s1 = 'a'.toNumber(); var s2 = 'z'.toNumber();        
  8.     var l1 = 'A'.toNumber(); var l2 = 'Z'.toNumber();
  9.     var n1 = '0'.toNumber(); var n2 = '9'.toNumber();
  10.    
  11.     for (var i = 0; i < sourceText.length(); i++) {
  12.         var str = sourceText.substring(i, i + 1);
  13.         var char = str.toCharArray()[0];
  14.         var num = char.toNumber();
  15.        
  16.         if (num >= s1 && num <= s2 || num >= l1 && num <= l2 || num >= n1 && num <= n2 || char == ' ' || char == '-') {
  17.             outputText += char.toString();
  18.             continue;
  19.         }
  20.        
  21.         for (var j = 0; j < in.length(); j++) {
  22.             var inStr = in.substring(j, j + 1);
  23.             if (str.equals(inStr)) {
  24.                 outputText += out.substring(j, j + 1);
  25.                 break;
  26.             }
  27.         }
  28.     }
  29.     return outputText;
  30. }
RAW Paste Data