Skip to content

Commit 905380e

Browse files
committed
Regexes now has the unicode flag set
1 parent 8833d40 commit 905380e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/Gren/Kernel/Regex.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _Regex_fromStringWith = F2(function (options, string) {
1313
return __Maybe_Nothing;
1414
}
1515

16-
var flags = "g";
16+
var flags = "gu";
1717
if (options.__$multiline) {
1818
flags += "m";
1919
}
@@ -86,5 +86,3 @@ var _Regex_replaceAtMost = F4(function (n, re, replacer, string) {
8686
var _Regex_splitAtMost = F3(function (n, re, str) {
8787
return str.split(re, n);
8888
});
89-
90-
var _Regex_infinity = Number.MAX_SAFE_INTEGER;

src/String/Regex.gren

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Array exposing (Array)
3535
import Basics exposing (..)
3636
import Maybe exposing (Maybe(..))
3737
import String exposing (String)
38+
import Math
3839
import Gren.Kernel.Regex
3940

4041

@@ -143,7 +144,7 @@ If you want some really fancy splits, a library like
143144
-}
144145
split : Regex -> String -> Array String
145146
split =
146-
Gren.Kernel.Regex.splitAtMost Gren.Kernel.Regex.infinity
147+
Gren.Kernel.Regex.splitAtMost Math.maxSafeInteger
147148

148149

149150
{-| Find matches in a string:
@@ -169,7 +170,7 @@ If you need `submatches` for some reason, a library like
169170
-}
170171
find : Regex -> String -> Array Match
171172
find =
172-
Gren.Kernel.Regex.findAtMost Gren.Kernel.Regex.infinity
173+
Gren.Kernel.Regex.findAtMost Math.maxSafeInteger
173174

174175

175176
{-| The details about a particular match:
@@ -226,7 +227,7 @@ you use the details of a specific match when making replacements.
226227
-}
227228
replace : Regex -> (Match -> String) -> String -> String
228229
replace =
229-
Gren.Kernel.Regex.replaceAtMost Gren.Kernel.Regex.infinity
230+
Gren.Kernel.Regex.replaceAtMost Math.maxSafeInteger
230231

231232

232233

tests/src/Test/Regex.gren

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ tests =
1414
[ test "Regex.replace" <| \{} ->
1515
Regex.replace vowels (\_ -> "_") "abc"
1616
|> Expect.equal "_bc"
17+
, test "Regex has unicode enabled" <| \{} ->
18+
Regex.replace smily (\_ -> "_") "you are all 🙂 aren't you?"
19+
|> Expect.equal "you are all _ aren't you?"
1720
, test "Regex.split with never and empty string returns empty string" <| \{} ->
1821
Regex.split Regex.never ""
1922
|> Expect.equal [""]
@@ -33,3 +36,9 @@ vowels : Regex
3336
vowels =
3437
Regex.fromString "[aeiou]"
3538
|> Maybe.withDefault Regex.never
39+
40+
41+
smily : Regex
42+
smily =
43+
Regex.fromString "[🙂]"
44+
|> Maybe.withDefault Regex.never

0 commit comments

Comments
 (0)