Hello friends,
I am looking for some advice on JS performance.
I wrote a function in PHP that converts characters for large strings. Here is the entire array:
$table = array(
'CH'=>'Ċ', 'GH'=>'Ġ', 'BH'=>'Ḃ', 'DH'=>'Ḋ', 'FH'=>'Ḟ', 'MH'=>'Ṁ', 'PH'=>'Ṗ', 'SH'=>'Ṡ', 'TH'=>'Ṫ',
'Ch'=>'Ċ', 'Gh'=>'Ġ', 'Bh'=>'Ḃ', 'Dh'=>'Ḋ', 'Fh'=>'Ḟ', 'Mh'=>'Ṁ', 'Ph'=>'Ṗ', 'Sh'=>'Ṡ', 'Th'=>'Ṫ',
'ch'=>'ċ', 'gh'=>'ġ', 'bh'=>'ḃ', 'dh'=>'ḋ', 'fh'=>'ḟ', 'mh'=>'ṁ', 'ph'=>'ṗ', 'sh'=>'ṡ', 'th'=>'ṫ' )
It removes the ‘h’ suffix and places a diacritic (dot) above the consonant for Irish words.
eg. ‘lough’ becomes ‘louġ’; ‘leprechaun’ becomes ‘lepreċaun’; 'Siobhán ’ becomes ‘Sioḃán’; and ‘shamrock’ becomes ‘ṡamrock’.
This was the way Irish words were written before the arrival of the typewriter to Ireland, and as the typewriter did not have a facility to place a dot above consonants, a ‘h’ suffix was used instead and has remained to this day. My PHP function above converts modern Irish words back to the traditional sort.
Anyway, I now want to do this with Javascript. As the average page contains about 15,000 characters, I was wondering what would be the most efficient way of doing this.
I tested the following jQuery functions, which seem to work, but I´m not sure how to add the entire array, and I´m not sure if it´s the most efficient way for 15,000 characters of text…
$(this).html(this.html().replace('ch','ċ'));
jQuery('html').each(function(i){ jQuery(this).text(jQuery(this).text().replace('ch','ċ')) })
Any tips would be great.