G
Gyoung-Yoon Noh
Hi,
I am writing a ruby binding for C library implements an automaton
for supporting non-english keyboard input. Following shows an example
usage:
require 'hangul'
hic =3D Hangul::InputContext.new(Hangul::KEYBOARD_2)
input =3D "fnql gksrmf fkdlqmfjfl xptmxm"
buffer =3D ''
input.each_byte do |c|
ret =3D hic.filter(c) # filtering [a-zA-Z] for automaton
commit =3D hic.commit_string # output produced by automaton
buffer << commit if commit
buffer << c.chr unless ret # just append unfiltered chars.
end
hic.flush
buffer << hic.commit_string.to_s
It works as I expected when I paste the code on IRB, or run it with
built-in ruby debugger(-r debug). See the actual session:
$ irb -f
irb(main):001:0> require 'hangul'
=3D> true
irb(main):002:0> hic =3D Hangul::InputContext.new(Hangul::KEYBOARD_2)
=3D> #<Hangul::InputContext:0xb7d50494>
(...)
irb(main):012:0> buffer << hic.commit_string.to_s # bottom line
=3D> "\353\243\250\353\271\204 \355\225\234\352\270\200
\353\235\274\354\235\264\353\270\214\353\237\254\353\246\254
\355\205\214\354\212\244\355\212\270"
FYI, the variable 'buffer' is finally utf-8 encoded string, expected
result.
But it returns strange result when I run the code directly from
command-line. After running the code, the 'buffer' would be filled with
only 3 spaces(0x20). The 'hic.commit_string' always returns nil. I don't
know why the result differs. It doesn't relate with concurrency issues.
My extension codes can be found at:
http://nohmad.sub-port.net/tmp/ruby-hangul/
Any comment will be appreciated.
I am writing a ruby binding for C library implements an automaton
for supporting non-english keyboard input. Following shows an example
usage:
require 'hangul'
hic =3D Hangul::InputContext.new(Hangul::KEYBOARD_2)
input =3D "fnql gksrmf fkdlqmfjfl xptmxm"
buffer =3D ''
input.each_byte do |c|
ret =3D hic.filter(c) # filtering [a-zA-Z] for automaton
commit =3D hic.commit_string # output produced by automaton
buffer << commit if commit
buffer << c.chr unless ret # just append unfiltered chars.
end
hic.flush
buffer << hic.commit_string.to_s
It works as I expected when I paste the code on IRB, or run it with
built-in ruby debugger(-r debug). See the actual session:
$ irb -f
irb(main):001:0> require 'hangul'
=3D> true
irb(main):002:0> hic =3D Hangul::InputContext.new(Hangul::KEYBOARD_2)
=3D> #<Hangul::InputContext:0xb7d50494>
(...)
irb(main):012:0> buffer << hic.commit_string.to_s # bottom line
=3D> "\353\243\250\353\271\204 \355\225\234\352\270\200
\353\235\274\354\235\264\353\270\214\353\237\254\353\246\254
\355\205\214\354\212\244\355\212\270"
FYI, the variable 'buffer' is finally utf-8 encoded string, expected
result.
But it returns strange result when I run the code directly from
command-line. After running the code, the 'buffer' would be filled with
only 3 spaces(0x20). The 'hic.commit_string' always returns nil. I don't
know why the result differs. It doesn't relate with concurrency issues.
My extension codes can be found at:
http://nohmad.sub-port.net/tmp/ruby-hangul/
Any comment will be appreciated.