Re: Unicode native scripting language?

From: Edward Trager (ehtrager@umich.edu)
Date: Wed Jan 18 2006 - 12:19:37 CST

  • Next message: Jeroen Ruigrok/asmodai: "Re: IJ joint in spaced lettering"

    Well actually, in C you can make it even simpler than that:
    Plain old "char *" holds UTF-8 just fine, so you can simply have:

    =========== start test.c ==============
       #include <stdio.h>
       #include <locale.h>
       const char *hello = "你好";
       
       int main(void) {
            setlocale(LC_ALL,"");
            printf("%s\n", hello);
            return 0;
       }
    =========== end test.c ==============

    ... and just compile with:

    gcc -o test test.c

    This works fine modern Linux and Mac OS X and should work fine in any
    other modern Unix or Unix derivative where the locale is set to UTF-8, such as
    Solaris or Nexenta.

     And in fact you can even get rid of the "#include <locale.h>" and
    "setlocale(LC_ALL,"")" lines and it still works just the same (as long as the
    locale is UTF-8, which is increasingly the default). Here's the equivalently
    trivial CPP version:

    =========== start test.cpp ==============
    #include <iostream>
    #include <string>

    using namespace std;

    int main(void){
            string hello="你好";
            cout << hello << endl;
            return 0;
    }
    =========== end test.cpp ==============

    ... and compile with:

    g++ -o testcc test.cpp

    SQL integration should also not be a problem : Just store UTF-8 strings
    directly in your database tables.

    Best Wishes--

    -- Ed Trager

    On Wednesday 18 January 2006 04:06, Samuel Thibault wrote:
    > Hi,
    >
    > Mike Ayers, le Tue 17 Jan 2006 21:07:44 -0800, a écrit :
    > > It's now commonplace for scripting languages to "support" Unicode,
    > > but is there one that is truly fluent in Unicode? I want to be able to:
    > >
    > > String hello = '你好';
    > >
    > > ...and go from there. The key here is to be able to use Unicode in
    > > the source code. SQL integration would be a plus. Any pointers would
    > > be appreciated.
    >
    > C can do this: put yourself in a utf-8 locale, run an editor, type:
    >
    > #include <stdio.h>
    > #include <wchar.h>
    > #include <locale.h>
    > wchar_t *hello = L"你好";
    >
    > int main(void) {
    > setlocale(LC_ALL,"");
    > wprintf(L"%ls\n", hello);
    > return 0;
    > }
    >
    > Compile with gcc -std=c99 test.c -o test
    > run it, you're done!
    >
    > Regards,
    > Samuel



    This archive was generated by hypermail 2.1.5 : Wed Jan 18 2006 - 12:32:29 CST