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.

Revisions

  1. mohanmca revised this gist Oct 12, 2017. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions TamilFunctions.md
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,23 @@ for(var i=0;i<128;i++) {
    var newCharInHex = newChar.toString(16)
    console.log(convertHexToString(newCharInHex))
    }
    ```

    Generate Tamil char using unicode
    ```Javascript
    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))
    }
    ```
  2. mohanmca revised this gist Oct 11, 2017. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion TamilFunctions.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,12 @@
    பி - 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

    ```Javascript

    function convertHexToString(input) {
    @@ -20,7 +29,6 @@ function convertHexToString(input) {
    console.log("'" + convertHexToString('c385') + "'"); // => 'Å'
    console.log("'" + convertHexToString('E0AEAA') + "'");

    >> 128 tamil utf-8 characters

    for(var i=0;i<128;i++) {
    var tamilChar = parseInt("E0AEAA", 16)
  3. mohanmca created this gist Oct 11, 2017.
    31 changes: 31 additions & 0 deletions TamilFunctions.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    ```Javascript

    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') + "'");

    >> 128 tamil utf-8 characters

    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))
    }
    ```