Skip to content

Instantly share code, notes, and snippets.

@mohanmca
Last active October 12, 2017 19:37
Show Gist options
  • Save mohanmca/f18eae05b87b1bc43df7fcd9d490f6ec to your computer and use it in GitHub Desktop.
Save mohanmca/f18eae05b87b1bc43df7fcd9d490f6ec to your computer and use it in GitHub Desktop.

பி - TAMIL LETTER PA - Hex UTF-8 bytes - E0 AE AA டி - TAMIL LETTER TTA - Hex UTF-8 bytes - E0 AE 9F

http://www.utf8-chartable.de/unicode-utf8-table.pl?start=2944&number=128&utf8=0x starts from - U+0B80 - 0xe0 0xae 0x80 ends until - U+0BFF - 0xe0 0xaf 0xbf

128 tamil utf-8 characters

function convertHexToString(input) {

    // split input into groups of two
    var hex = input.match(/[\s\S]{2}/g) || [];
    var output = '';

    // build a hex-encoded representation of your string
    for (var i = 0, j = hex.length; i < j; i++) {
        output += '%' + ('0' + hex[i]).slice(-2);
    }

    // decode it using this trick
    output = decodeURIComponent(output);

    return output;
}

console.log("'" + convertHexToString('c385') + "'");   // => 'Å'
console.log("'" + convertHexToString('E0AEAA') + "'");


for(var i=0;i<128;i++) {
    var tamilChar = parseInt("E0AEAA", 16)
    var newChar = tamilChar + i
    var newCharInHex = newChar.toString(16)
    console.log(convertHexToString(newCharInHex))
}

Generate Tamil char using unicode

function convertToUtf8(s) {
  function parse(a, c) {
    return String.fromCharCode(parseInt(c, 16));
  }
  return encodeURIComponent(s.replace(/%u([0-f]{4})/gi, parse));
}

var tamilBaseChar = parseInt("B80", 16)
for(var i=0;i<128;i++) {
    var newChar = tamilBaseChar + i
    var newCharInHex = (newChar).toString(16)
    var tamilUnicodeHex = "0x0" + newCharInHex
    var tamilChar = String.fromCodePoint("0x0" + newCharInHex)
    console.log(tamilUnicodeHex + " ~~ " + tamilChar + " ~~ UTF8 ~~> " + convertToUtf8(tamilChar))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment