[#11357] [PATCH] an analogue of `long long' — "Nobuyoshi.Nakada" <nobu.nakada@...>
なかだです。
まつもと ゆきひろです
えぐち@エスアンドイー です。
まつもと ゆきひろです
えぐち@エスアンドイー です。
まつもと ゆきひろです
>From: matz@zetabits.com (Yukihiro Matsumoto)
まつもと ゆきひろです
[#11440] class Character (was: Ruby I18N) — Yasushi Shoji <yashi@...>
[ruby-dev:11428] からの続きですが、threadは切りました。
高橋征義です。用語について。
At Wed, 8 Nov 2000 20:44:55 +0900,
高橋征義です。
At Thu, 9 Nov 2000 13:30:34 +0900,
まつもと ゆきひろです
[#11447] gets は secure? — Kazuhiro NISHIYAMA <zn@...>
出力がInsecureなのに入力はsecureなのでしょうか?
[#11467] debug write in regex.c? — "Nobuyoshi.Nakada" <nobu.nakada@...>
なかだです。
[#11500] rb_to_integer/rb_to_int — "Nobuyoshi.Nakada" <nobu.nakada@...>
なかだです。
[#11520] A problem of Socket methods on Windows — OKA Toshiyuki <oka@...>
岡と申します。
なかだです。
まつもと ゆきひろです
なかだです。
岡です。
なかだです。
なかだです。
岡です。
なかだです。
[#11569] blocking on socket? — Shugo Maeda <shugo@...>
前田です。
[#11591] object.c パッチ — Kazuhiro NISHIYAMA <zn@...>
使われてなかったnil_plusの削除とOBJ_INFECTへの変更です。
[#11611] return value of waitpid2 — Koji Arai <JCA02266@...>
新井です。
まつもと ゆきひろです
荒井です。いや、新井です。(よくあることさ)
まつもと ゆきひろです
新井です。
新井です。
[#11618] Re: class variable — "Koji Arai" <jca02266@...>
新井です
なかだです。
まつもと ゆきひろです
> まつもと ゆきひろです
まつもと ゆきひろです
まつもと ゆきひろです
新井です。
[#11641] eval too slow — Wakou Aoyama <wakou@...>
青山です。
[#11650] conflict of NODE_DREGX_ONCE — "Nobuyoshi.Nakada" <nobu.nakada@...>
なかだです。
まつもと ゆきひろです
[#11662] IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org>
In article <E140cR3-0002ls-00@ev.netlab.zetabits.co.jp>,
まつもと ゆきひろです
In article <E140fxW-0002u9-00@ev.netlab.zetabits.co.jp>,
In article <hvor93w5wb8.fsf@coulee.m17n.org>,
In article <hvoofz05uwz.fsf@coulee.m17n.org>,
まつもと ゆきひろです
新井です。
まつもと ゆきひろです
In article <E141eaC-0003w0-00@ev.netlab.zetabits.co.jp>,
まつもと ゆきひろです
In article <E142ZqF-0004rX-00@ev.netlab.zetabits.co.jp>,
まつもと ゆきひろです
In article <E143Zem-000271-00@ev.netlab.zetabits.co.jp>,
まつもと ゆきひろです
In article <E143amj-00028V-00@ev.netlab.zetabits.co.jp>,
[ruby-dev:11445] Re: Ruby I18N
とみたです。
[matz@zetabits.com (Yukihiro Matsumoto)さんが]
["[ruby-dev:11420] Re: Ruby I18N" で曰く]
> が、それは「String の下位クラスを作る」ことと矛盾しそうで、
> 「String の下位クラスを作る」ならば「string.cのほとんどコピー
> が各文字コード系毎に発生することになりそう」という意図だった
> のですが。
ええと、String の下位クラスを作っても、string.c のコピーは不要じゃ
ないかというのが私の意図です。
MySQL と似たようなやり方で、ちょいとサンプルモジュールを作って
みましたんで、添付します。
require 'ctype-euc-jp'
s = EucJpString::new("あaいbうcえdおe")
puts s[2,3] # => "いbう"
puts s.index(EucJpString::new "え") # => 6
例えば、こういうのと同じような動きをするモジュールを C で作成したと
すると、文字コード系毎には ctype-***.c を作ればいいだけで、mbstring.c
は一つでいいんではないかと…。
# 何か勘違いしてるかな…?
---
とみたまさひろ <tommy@tmtm.org> http://www.tmtm.org
日本MySQLユーザ会 http://www.mysql.gr.jp
Attachments (3)
class MBString < String
C = {}
def initialize(str, ctype=nil)
@ctype = ctype
super str
end
attr_reader :ctype
attr_writer :ctype
def clone()
MBString::new(self, ctype)
end
def dup()
MBString::new(self, ctype)
end
alias :byte_eql? :eql?
def ==(s)
s.ctype == ctype and super(self)
end
def ===(s)
self.==(s)
end
def eql?(s)
self.==(s)
end
def +(s)
raise 'different ctype' if s.ctype != ctype
MBString::new super(s), ctype
end
def *(s)
MBString::new super(s), ctype
end
alias :byte_length :length
alias :byte_at :[]
def pos(n)
i = 0
c = 0
while c < n and i < byte_length
i += C[ctype].mblength(byte_at i)
c += 1
end
if i < byte_length then i else nil end
end
def length()
i = 0
c = 0
while i < byte_length
i += C[ctype].mblength(byte_at i)
c += 1
end
c
end
alias :size :length
def [](*arg)
if arg.length == 1 and arg[0].type == Fixnum then
i = pos arg[0]
if i then
l = C[ctype].mblength(super i)
r = 0
l.times do
r = r * 256 + super(i)
i += 1
end
r
else
nil
end
elsif arg.length == 2 then
i = pos arg[0]
j = pos arg[1]
MBString::new super(i, j), ctype
elsif arg.length == 1 and arg[0].type == Range then
i = pos arg[0].first
j = pos arg[0].end
MBString::new super(i, j), ctype
else
raise 'invalid argument'
end
end
def index(s, p=nil)
raise 'different ctype' if s.ctype != ctype
i = p ? pos(p) : 0
p ||= 0
while i < byte_length
if s.byte_eql? byte_at(i, s.byte_length) then return p end
i += C[ctype].mblength(byte_at i)
p += 1
end
nil
end
end
require 'mbstring'
module EucJpCType
def mblength(c)
n = c < 0x80 ? 1 : 0xa1 <= c && c <= 0xfe ? 2 : c == 0x8e ? 2 : c == 0x8f ? 3 : 1
end
module_function :mblength
end
MBString::C['euc-jp'] = EucJpCType
class EucJpString < MBString
def initialize(str)
super(str, 'euc-jp')
end
end
require 'mbstring'
module ShiftJisCType
def mblength(c)
n = 0x81 < c && c < 0x9f ? 2 : 1
end
module_function :mblength
end
MBString::C['shift_jis'] = ShiftJisCType
class ShiftJisString < MBString
def initialize(str)
super(str, 'shift_jis')
end
end