Ask a Question related to Ruby, Design and Development.
-
Yukihiro Matsumoto #1
Re: [ruby-talk] Re: newbie locale/ascii sort question
Hi,
In message "[ruby-talk] Re: newbie locale/ascii sort question"
on 03/07/01, Bengt Dahlqvist <bengt.dahlqvist@ling.uu.se> writes:
|Does such utilities exist in the Ruby context?
Not yet. But a small extension like this seems to work.
require "locale"
Locale::setlocale(Locale::LC_ALL, "ja_JP.eucJP")
my_array.sort{|a,b| Locale::strcoll(a,b)}
Just for information. Does anybody want to work further?
matz.
---- locale.c
#include "ruby.h"
#include <locale.h>
static VALUE
locale_setlocale(self, category, locale)
VALUE self, category, locale;
{
char *l;
if (NIL_P(locale)) l = NULL;
else l = StringValuePtr(locale);
l = setlocale(NUM2INT(category), l);
if (!l) return Qnil;
return rb_str_new2(l);
}
static VALUE
locale_strcoll(self, s1, s2)
VALUE self, s1, s2;
{
int n = strcoll(StringValuePtr(s1), StringValuePtr(s2));
return INT2NUM(n);
}
void
Init_locale()
{
VALUE mLocale = rb_define_module("Locale");
rb_define_module_function(mLocale, "setlocale", locale_setlocale, 2);
rb_define_module_function(mLocale, "strcoll", locale_strcoll, 2);
rb_define_const(mLocale, "LC_ALL", INT2NUM(LC_ALL));
rb_define_const(mLocale, "LC_COLLATE", INT2NUM(LC_COLLATE));
rb_define_const(mLocale, "LC_CTYPE", INT2NUM(LC_CTYPE));
rb_define_const(mLocale, "LC_MESSAGES", INT2NUM(LC_MESSAGES));
rb_define_const(mLocale, "LC_MONETARY", INT2NUM(LC_MONETARY));
rb_define_const(mLocale, "LC_NUMERIC", INT2NUM(LC_NUMERIC));
rb_define_const(mLocale, "LC_TIME", INT2NUM(LC_TIME));
}
Yukihiro Matsumoto Guest
-
newbie question for Ruby and/or PHP
Hi, with some of your help, I manage to extract a delimited record into mysql database using ruby. I have the following structure in my MySQL... -
Newbie question : Extending Ruby
I'm making my first extension to Ruby. The C file declarations look like: __declspec(dllexport) VALUE cImage8 = Qnil; __declspec(dllexport)... -
ruby-talk: 80813 (Rite/Ruby2.0 & Ruby vs OCaml)
Hope nobody finds this annoying. Somehow I missed this message when it was originally sent, but I thought my reply might be useful to sombody. ... -
Bопpоc от ruby-talk@ruby-lang.org
ua g ap p g lw c 3 38 12 9 4 uag a p pg lw c Распродажа мониторов б/у из Японии! 21" от 200$ до 270$ 17" от 70$ до 100$ Ноутбуки от 260$.... -
Ruby OO-newbie design-question
Hi! I'm not at all new to programming, I know OO-concepts but I don't have any hands-on experience with designing/programming OO except for small...



Reply With Quote

