3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サロゲートペアの取り扱い(rubyとmacrubyの違い)

Last updated at Posted at 2013-03-09

サロゲートペアを含む文字列に対して、バックシュラッシュ記法で特定のサロゲートペアを検出しようとしたときの挙動が、rubyとmacrubyで異なる。

macrubyの場合

$ macirb
irb(main):001:0> "\xF4\x8F\xB5\x88-hydroxy alkylthiols".include?("\xF4")
=> true
irb(main):002:0> i = "\xF4\x8F\xB5\x88-hy".ord
=> 56319
irb(main):003:0> i.chr("UTF-8")
RangeError: 56319 out of char range

rubyの場合

$ irb
1.9.3-p327 :001 > "\xF4\x8F\xB5\x88-hydroxy alkylthiols".include?("\xF4")
=> false
1.9.3-p327 :001 > i = "\xF4\x8F\xB5\x88-hy".ord
=> 1113416
1.9.3-p327 :002 > i.chr("UTF-8")
=> "

サロゲートペアを含む文字列をHTMLに埋め込んでWebViewに表示しようとしても、なにも表示されないので注意が必要。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?