summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/elixir/lib/string.ex13
-rw-r--r--lib/elixir/pages/Typespecs.md6
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/elixir/lib/string.ex b/lib/elixir/lib/string.ex
index b1831f293..2ed17991c 100644
--- a/lib/elixir/lib/string.ex
+++ b/lib/elixir/lib/string.ex
@@ -203,9 +203,22 @@ defmodule String do
is generated at runtime and does not survive compile term.
"""
+ @typedoc """
+ A UTF-8 encoded binary.
+
+ Note `String.t()` and `binary()` are equivalent to analysis tools.
+ Although, for those reading the documentation, `String.t()` implies
+ it is a UTF-8 encoded binary.
+ """
@type t :: binary
+
+ @typedoc "A UTF-8 codepoint. It may be one or more bytes."
@type codepoint :: t
+
+ @typedoc "Multiple codepoints that may be perceived as a single character by readers"
@type grapheme :: t
+
+ @typedoc "Pattern used in functions like `replace/3` and `split/2`"
@type pattern :: t | [t] | :binary.cp()
@conditional_mappings [:greek]
diff --git a/lib/elixir/pages/Typespecs.md b/lib/elixir/pages/Typespecs.md
index 26813fe87..43c379756 100644
--- a/lib/elixir/pages/Typespecs.md
+++ b/lib/elixir/pages/Typespecs.md
@@ -238,8 +238,8 @@ If a callback module that implements a given behaviour doesn't export all the fu
Elixir's standard library contains a few frequently used behaviours such as `GenServer`, `Supervisor`, and `Application`.
-## Notes
+## The `string()` type
-Elixir discourages the use of type `t:string/0` as it might be confused with binaries which are referred to as "strings" in Elixir (as opposed to character lists). In order to use the type that is called `t:string/0` in Erlang, one has to use the `t:charlist/0` type which is a synonym for `string`. If you use `string`, you'll get a warning from the compiler.
+Elixir discourages the use of the `string()` type. The `string()` type refers to Erlang strings, which are known as "charlists" in Elixir. They do not refer to Elixir strings, which are UTF-8 encoded binaries. To avoid confusion, if you attempt to use the type `string()`, Elixir will emit a warning. You should use `charlist()`, `binary()` or `String.t()` accordingly.
-If you want to refer to the "string" type (the one operated on by functions in the `String` module), use `t:String.t/0` type instead.
+Note `String.t()` and `binary()` are equivalent to analysis tools. Although, for those reading the documentation, `String.t()` implies it is a UTF-8 encoded binary.