Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
文字数はおいくら?(Ruby版)
Search
tsuda.a
April 05, 2014
Programming
17
0
Share
文字数はおいくら?(Ruby版)
サロゲート文字とか合字とか異体字とかの文字数を取得してみました。
tsuda.a
April 05, 2014
More Decks by tsuda.a
See All by tsuda.a
マジカルインクリメントと指数表記
tsudaahr
0
240
バックアップしていますか?
tsudaahr
0
140
RDB以前のファイル設計の話でもしようか(ぇ
tsudaahr
0
150
NPUわからん
tsudaahr
0
200
計算量オーダーの話
tsudaahr
1
440
クラウド初学者が抱える不安について
tsudaahr
0
320
キューとは何か
tsudaahr
0
270
等幅は死んだ(ぇ
tsudaahr
0
130
いくら眺めてもエラーの理由がわからないコードについて
tsudaahr
0
210
Other Decks in Programming
See All in Programming
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
340
NakouPAY説明用
annouim0
0
240
事業会社でのセキュリティ長期インターンについて
masachikaura
0
250
Back to the roots of date
jinroq
0
260
[RubyKaigi 2026] Require Hooks
palkan
1
210
おれのAgentic Coding 2026/03
tsukasagr
1
150
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
2
210
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
280
AIエージェントで業務改善してみた
taku271
0
530
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
140
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
490
Coding as Prompting Since 2025
ragingwind
0
840
Featured
See All Featured
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
54k
Agile that works and the tools we love
rasmusluckow
331
21k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
770
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
720
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
How to train your dragon (web standard)
notwaldorf
97
6.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
Transcript
文字数はおいくら? (Ruby版) @tsuda_ahr 2014/4/5 LTDD広島 #2
1.サロゲート文字の場合 puts "𩹉".length ※サロゲート文字とは、文字コードが U+10000 以上の文字をいいます。(かなり嘘かも)
1.サロゲート文字の場合 こたえ 1
1.サロゲート文字の場合 サロゲート文字でも、 正しく文字数を答える模様。
2.合字の場合 puts "を ゙".length puts "が".length puts "が".length
2.合字の場合 こたえ 2 2 1
2.合字の場合 合字の構成要素数が文字数として戻る。
3.異体字の場合 puts "辻".length puts "辻󠄀".length
3.異体字の場合 こたえ 1 2
4.C#だとこんな感じ Ruby C# サロゲート 𩹉 (U+29E49) 1 2 合字 を
゙ (U+3092 U+3099) 2 2 が (U+304B U+3099) 2 2 が (U+304C) 1 1 異体字 辻 (U+8FBB) 1 1 辻󠄀 (U+8FBB U+E0100) 2 3 内部がUTF-16なので、 サロゲート領域(U+10000以上) の文字は 2 でカウントされる。
5.結論 Ruby 結構優秀! (割と素直) (というか内部が多分UTF-8)
蛇足) 気にしてほしいこと String.Length は処理系によって値が異なることがある。 内部はどういうデータで保持しているかを想像してほしい。 入力するユーザー(一般の人)は無慈悲だ。 #
システムの都合は察してくれない
おわり ありがとうございました