Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Created August 11, 2022 04:25
Show Gist options
  • Save nukosuke/3d4737324bef3e8e58d95ef6fc311a04 to your computer and use it in GitHub Desktop.
Save nukosuke/3d4737324bef3e8e58d95ef6fc311a04 to your computer and use it in GitHub Desktop.
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

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