Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Created Aug 11, 2022
Embed
What would you like to do?
Elixir 漢字判定モジュール
defmodule Kanji do
@moduledoc """
漢字かどうかを判定する
## Usage
iex(1)> Kanji.kanji?(?漢)
true
iex(2)> Kanji.kanji?(?A)
false
### Reference
https://tama-san.com/kanji-regex/
"""
@doc """
漢字かどうかを判定する
"""
@spec kanji?(char()) :: boolean()
def kanji?(char)
when is_integer(char) and
(char in 0x2E80..0x2FDF or
char in [?々, ?〇, ?〻] or
char in 0x3400..0x4DBF or
char in 0x4E00..0x9FFF or
char in 0xF900..0xFAFF or
char in 0x20000..0x2FFFF),
do: true
def kanji?(_any), do: false
end
@nukosuke
Copy link
Author

nukosuke commented Aug 11, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment