-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
473d2be
commit bc439e1
Showing
4 changed files
with
167 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/language_server/test/misc/mock_elixir_src/lib/elixir/lib/string.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Kernel, except: [length: 1] | ||
|
||
defmodule String do | ||
@typedoc """ | ||
A UTF-8 encoded binary. | ||
The types `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 | ||
|
||
@doc """ | ||
Returns the number of Unicode graphemes in a UTF-8 string. | ||
## Examples | ||
iex> String.length("elixir") | ||
6 | ||
iex> String.length("եոգլի") | ||
5 | ||
""" | ||
@spec length(t) :: non_neg_integer | ||
def length(string) when is_binary(string), do: length(string, 0) | ||
|
||
defp length(gcs, acc) do | ||
case :unicode_util.gc(gcs) do | ||
[_ | rest] -> length(rest, acc + 1) | ||
[] -> acc | ||
{:error, <<_, rest::bits>>} -> length(rest, acc + 1) | ||
end | ||
end | ||
end |
Oops, something went wrong.