aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKero van Gelder <keroami@users.noreply.github.com>2022-12-08 22:42:33 +0100
committerGitHub <noreply@github.com>2022-12-08 21:42:33 +0000
commit03477e5f04dfc52d44dc02658d70cc94c66b8574 (patch)
treececef02b849334e2db0b8658790d25ea00a69bde
parent39d5b221f7c28e76262fc7e8b0746152a46c97c5 (diff)
downloadgleam_stdlib-03477e5f04dfc52d44dc02658d70cc94c66b8574.tar.gz
gleam_stdlib-03477e5f04dfc52d44dc02658d70cc94c66b8574.zip
JS/Firefox: also match newlines in string.length and string.pop_grapheme (#385)
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/gleam_stdlib.mjs4
2 files changed, 4 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83b76ed..0a87f32 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@
when running as JavaScript in a browser)
- The `list.at` function now returns `Error(Nil)` if given index is smaller than
zero, instead of returning the first element.
+- The `string` module takes into account newlines for `length` and
+ various other functions in Firefox
## v0.25.0 - 2022-11-19
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs
index a3e6c13..cde1052 100644
--- a/src/gleam_stdlib.mjs
+++ b/src/gleam_stdlib.mjs
@@ -89,7 +89,7 @@ export function string_length(string) {
}
return i;
} else {
- return string.match(/./gu).length;
+ return string.match(/./gus).length;
}
}
@@ -111,7 +111,7 @@ export function pop_grapheme(string) {
if (iterator) {
first = iterator.next().value?.segment;
} else {
- first = string.match(/./u)?.[0];
+ first = string.match(/./us)?.[0];
}
if (first) {
return new Ok([first, string.slice(first.length)]);