Unicode.SentenceBreak (Unicode v2.0.0)

Copy Markdown View Source

Functions to introspect the Unicode sentence break property for binaries (Strings) and codepoints.

The primary API is sentence_break/1 which returns the sentence break property for a codepoint or the list of sentence break properties for a string.

The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges associated with a given sentence break property. sentence_breaks/0, known_sentence_breaks/0 and aliases/0 return the underlying property data.

Summary

Functions

Returns a map of aliases for Unicode sentence breaks.

Returns the count of the number of characters for a given sentence break.

Returns the Unicode codepoint ranges for a given sentence break.

Returns the Unicode codepoint ranges for a given sentence break.

Returns a list of known Unicode sentence break names.

Returns the sentence break name(s) for the given binary or codepoint.

Returns the map of Unicode sentence breaks.

Functions

aliases()

Returns a map of aliases for Unicode sentence breaks.

An alias is an alternative name for referring to a sentence break. Aliases are resolved by the fetch/1 and get/1 functions.

Returns

  • A map with the alias as a string key and the sentence break name as an atom value.

Examples

iex> Unicode.SentenceBreak.aliases() |> Map.get("up")
:upper

count(sentence_break)

Returns the count of the number of characters for a given sentence break.

Arguments

  • sentence_break is any sentence break name as an atom, or a string alias for a sentence break.

Returns

  • The number of codepoints that have the given sentence break.

  • :error if the sentence break name is not known.

Examples

iex> Unicode.SentenceBreak.count(:extend)
2643

fetch(sentence_break)

Returns the Unicode codepoint ranges for a given sentence break.

Aliases are resolved by this function.

Arguments

  • sentence_break is any sentence break name as an atom, or a string alias for a sentence break.

Returns

  • {:ok, range_list} where range_list is a list of codepoint ranges as 2-tuples.

  • :error if the sentence break name is not known.

Examples

iex> Unicode.SentenceBreak.fetch(:cr)
{:ok, [{13, 13}]}

iex> Unicode.SentenceBreak.fetch(:invalid)
:error

get(sentence_break)

Returns the Unicode codepoint ranges for a given sentence break.

Aliases are resolved by this function.

Arguments

  • sentence_break is any sentence break name as an atom, or a string alias for a sentence break.

Returns

  • range_list which is a list of codepoint ranges as 2-tuples.

  • nil if the sentence break name is not known.

Examples

iex> Unicode.SentenceBreak.get(:cr)
[{13, 13}]

iex> Unicode.SentenceBreak.get(:invalid)
nil

known_sentence_breaks()

Returns a list of known Unicode sentence break names.

This function does not return the names of any sentence break aliases.

Returns

  • A list of sentence break names as atoms.

Examples

iex> Unicode.SentenceBreak.known_sentence_breaks() |> Enum.sort() |> Enum.take(3)
[:aterm, :close, :cr]

sentence_break(string)

Returns the sentence break name(s) for the given binary or codepoint.

Arguments

  • codepoint_or_string is either an integer codepoint or a string.

Returns

  • In the case of a codepoint, a single sentence break name as an atom. Codepoints with no explicit sentence break property default to :other.

  • In the case of a string, a list of the distinct sentence break names represented by the codepoints in the string.

Examples

iex> Unicode.SentenceBreak.sentence_break(?A)
:upper

iex> Unicode.SentenceBreak.sentence_break("Aa")
[:upper, :lower]

sentence_breaks()

Returns the map of Unicode sentence breaks.

Returns

  • A map with the sentence break name as the key and a list of codepoint ranges as 2-tuples as the value.

Examples

iex> Unicode.SentenceBreak.sentence_breaks() |> Map.get(:cr)
[{13, 13}]