Skip to content

Commit 53faad1

Browse files
committed
Fix is_whitespace guard to include 0x9-0xd
1 parent 48facf6 commit 53faad1

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Changelog for Unicode Guards v0.1.1
2+
3+
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)
4+
5+
### Bug Fixes
6+
7+
* 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.
8+
19
# Changelog for Unicode Guards v0.1.0
210

311
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)

lib/unicode_guards.ex

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,21 @@ defmodule Unicode.Guards do
6464
Guards whether a UTF8 codepoint is a whitespace symbol
6565
character.
6666
67+
This includes the Unicode set `Zs` plus the characters in the range `0x9`-`0xd`
68+
which incudes tab, newline and carriage return.
69+
70+
"""
71+
defguard is_whitespace(codepoint)
72+
when is_integer(codepoint) and match?(codepoint, "[[\u0009-\u000d][:Zs:]]")
73+
74+
@doc """
75+
Guards whether a UTF8 codepoint is a unicode separator symbol
76+
character.
77+
78+
This includes the Unicode set `Zs` plus the characters.
79+
6780
"""
68-
defguard is_whitespace(codepoint) when is_integer(codepoint) and match?(codepoint, "[[:Zs:]]")
81+
defguard is_separator(codepoint)
82+
when is_integer(codepoint) and match?(codepoint, "[[:Zs:]]")
6983

7084
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Unicode.Guards.MixProject do
22
use Mix.Project
33

4-
@version "0.1.0"
4+
@version "0.1.1"
55

66
def project do
77
[

mix.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
44
"earmark": {:hex, :earmark, "1.4.2", "3aa0bd23bc4c61cf2f1e5d752d1bb470560a6f8539974f767a38923bb20e1d7f", [:mix], [], "hexpm"},
55
"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"},
6-
"ex_unicode": {:hex, :ex_unicode, "1.1.0", "95e8ed3fb3a3688a365c85a60e2aa79a20426ed3d2ca1516389324f71efca842", [:mix], [], "hexpm"},
6+
"ex_unicode": {:hex, :ex_unicode, "1.3.1", "df5fc25569b3437fe98452e002b1463c0f98984a19945debe32c5239e73083d0", [:mix], [], "hexpm"},
77
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
88
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
9-
"nimble_parsec": {:hex, :nimble_parsec, "0.5.2", "1d71150d5293d703a9c38d4329da57d3935faed2031d64bc19e77b654ef2d177", [:mix], [], "hexpm"},
10-
"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"},
9+
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm"},
10+
"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"},
1111
}

test/unicode_guards_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ defmodule Unicode.GuardsTest do
1717
assert Guards.lower("a") == :lower
1818
assert Guards.digit("3") == :digit
1919
assert Guards.whitespace(" ") == :whitespace
20+
assert Guards.whitespace("\n") == :whitespace
21+
assert Guards.whitespace("\t") == :whitespace
22+
assert Guards.whitespace("\r") == :whitespace
2023
assert Guards.currency("$") == :currency
2124
end
2225
end

0 commit comments

Comments
 (0)