Created
June 26, 2012 13:20
-
-
Save hsbt/2995750 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
should "not drop utf-8 bytes" do | |
assert_equal "あいえお", "あ\000い\343う\201え\202お".printable! | |
end |
"う" は UTF-8 だと "\343\201\206" で表現できるのですが、その直前に "\343" が来ると "\343\343\201" と結合してしまうため、うを判定するのは不可能ではないかという判断です。
"あいうえお" にすることが可能であればそのようにしたいです。
なるほど。
かなり効率の悪い方法ですが、 https://gist.github.com/3000522 ではいかがでしょう?
一応「う」の判定もできているようです。
#文字コード関連には弱いので他のテストケースでは試せてません。
ありがとうございます! 1.9 以降ですと提示して頂いたコードで動きますね。
ただ、上記のコードは ruby-1.8.7 で動かす必要があるという情報が抜けていました...。申し訳ないです。
こちらこそすみません。1.8.7という情報を見落としていました。
同じアプローチでNKF.guessを使う方法を試したのですが、これだとどうでしょうか?
https://gist.github.com/3000522
丁寧にありがとうございます。1.8.7 で NKF を使うとできました。
この方法でやってみようと思います。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"あいうえお"ではなく"あいえお"にしたいのはどうしてでしょうか?