From 03477e5f04dfc52d44dc02658d70cc94c66b8574 Mon Sep 17 00:00:00 2001 From: Kero van Gelder Date: Thu, 8 Dec 2022 22:42:33 +0100 Subject: JS/Firefox: also match newlines in string.length and string.pop_grapheme (#385) --- CHANGELOG.md | 2 ++ src/gleam_stdlib.mjs | 4 ++-- 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)]); -- cgit v1.2.3