Skip to content

Commit

Permalink
Fix is_whitespace guard to include 0x9-0xd
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Feb 25, 2020
1 parent 48facf6 commit 53faad1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog for Unicode Guards v0.1.1

This is the changelog for Unicode Guards v0.1.1 released on February 25th, 2020. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-unicode/unicode_guards/tags)

### Bug Fixes

* Corrects `is_whitespace/1` to include the expected characters in the range `0x9-0xd`. These comprise carriage return, newline, vertical tab and tab which are commonly considered by regex engines to be whitespace.

# Changelog for Unicode Guards v0.1.0

This is the changelog for Unicode Guards v0.1.0 released on November 23rd, 2019. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-unicode/unicode_guards/tags)
Expand Down
16 changes: 15 additions & 1 deletion lib/unicode_guards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,21 @@ defmodule Unicode.Guards do
Guards whether a UTF8 codepoint is a whitespace symbol
character.
This includes the Unicode set `Zs` plus the characters in the range `0x9`-`0xd`
which incudes tab, newline and carriage return.
"""
defguard is_whitespace(codepoint)
when is_integer(codepoint) and match?(codepoint, "[[\u0009-\u000d][:Zs:]]")

@doc """
Guards whether a UTF8 codepoint is a unicode separator symbol
character.
This includes the Unicode set `Zs` plus the characters.
"""
defguard is_whitespace(codepoint) when is_integer(codepoint) and match?(codepoint, "[[:Zs:]]")
defguard is_separator(codepoint)
when is_integer(codepoint) and match?(codepoint, "[[:Zs:]]")

end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Unicode.Guards.MixProject do
use Mix.Project

@version "0.1.0"
@version "0.1.1"

def project do
[
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.4.2", "3aa0bd23bc4c61cf2f1e5d752d1bb470560a6f8539974f767a38923bb20e1d7f", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_unicode": {:hex, :ex_unicode, "1.1.0", "95e8ed3fb3a3688a365c85a60e2aa79a20426ed3d2ca1516389324f71efca842", [:mix], [], "hexpm"},
"ex_unicode": {:hex, :ex_unicode, "1.3.1", "df5fc25569b3437fe98452e002b1463c0f98984a19945debe32c5239e73083d0", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.2", "1d71150d5293d703a9c38d4329da57d3935faed2031d64bc19e77b654ef2d177", [:mix], [], "hexpm"},
"unicode_set": {:hex, :unicode_set, "0.1.0", "d32d23953702baeb89da0486cad22eeb8817bb8050571250248da443ba73983a", [:mix], [{:ex_unicode, "~> 1.1", [hex: :ex_unicode, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm"},
"unicode_set": {:hex, :unicode_set, "0.4.2", "627e5ffce656dbd652b23115bf91beee7f2348d2a30dda3c66001367144f2d9a", [:mix], [{:ex_unicode, "~> 1.3", [hex: :ex_unicode, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
}
3 changes: 3 additions & 0 deletions test/unicode_guards_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ defmodule Unicode.GuardsTest do
assert Guards.lower("a") == :lower
assert Guards.digit("3") == :digit
assert Guards.whitespace(" ") == :whitespace
assert Guards.whitespace("\n") == :whitespace
assert Guards.whitespace("\t") == :whitespace
assert Guards.whitespace("\r") == :whitespace
assert Guards.currency("$") == :currency
end
end

0 comments on commit 53faad1

Please sign in to comment.