Unicode.LinkTerm (Unicode v2.1.0)

Copy Markdown View Source

Functions to introspect the Link_Term property for binaries (Strings) and codepoints.

Link_Term drives the link termination algorithm of UTS #58, which decides where a URL or email address appearing in flowing text ends. The values are:

  • :include — the character belongs inside the link.

  • :hard — the character terminates the link immediately. This is the default, so any codepoint not listed in the data terminates a link.

  • :soft — the character terminates the link only when what follows is a run of soft characters and then a hard character or the end of the text. This is what lets See example.com. drop the sentence-final full stop while example.com/a.b keeps its inner one.

  • :open and :close — bracket characters, paired through Unicode.LinkBracket. A closing bracket is included when it matches the innermost open bracket and terminates the link otherwise.

The primary API is link_term/1 which returns the value for a codepoint, or the list of values for a string.

Summary

Functions

Returns a map of aliases for Link_Term values.

Returns the count of codepoints with a given Link_Term value.

Returns the Unicode codepoint ranges for a given Link_Term value.

Returns the Unicode codepoint ranges for a given Link_Term value.

Returns a list of known Link_Term values.

Returns the Link_Term value of the given binary or codepoint.

Returns the map of Link_Term values.

Functions

aliases()

Returns a map of aliases for Link_Term values.

Link_Term is defined by UTS #58 rather than the UCD, so it has no entry in PropertyValueAliases.txt and the only aliases are the value names themselves.

Returns

  • A map where the alias string is the key and the value name is the value.

Examples

iex> Unicode.LinkTerm.aliases() |> Map.get("soft")
:soft

count(link_term)

Returns the count of codepoints with a given Link_Term value.

Arguments

  • link_term is any Link_Term value name, as an atom or string.

Returns

  • A non-negative integer count of the codepoints with that value.

  • :error if the value is not known.

Examples

iex> Unicode.LinkTerm.count(:open)
65

fetch(link_term)

Returns the Unicode codepoint ranges for a given Link_Term value.

Arguments

  • link_term is any Link_Term value name, as an atom or string.

Returns

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

  • :error if the value is not known.

Examples

iex> Unicode.LinkTerm.fetch(:open) |> elem(0)
:ok

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

get(link_term)

Returns the Unicode codepoint ranges for a given Link_Term value.

Arguments

  • link_term is any Link_Term value name, as an atom or string.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if the value is not known.

Examples

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