Skip to content

Commit 46e6014

Browse files
committed
Bump gleam_stdlib and replace list.range with int.range
Upgrade gleam_stdlib to 0.70.0 and replace deprecated list.range usages with gleam/int.range across the project to comply with the latest stdlib API.
1 parent b9e8a9c commit 46e6014

11 files changed

Lines changed: 28 additions & 21 deletions

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ All notable changes to this project are documented in this file.
1111

1212
### Changed
1313

14+
- Updated `gleam_stdlib` usage to comply with latest versions:
15+
- Replaced deprecated `list.range` with `int.range` for improved performance and zero-warning compilation.
16+
- Optimized string building in `repeat_str` by replacing basic concatenation with `gleam/string_tree`.
1417
- Enhanced `words` to handle additional Unicode whitespace characters (non-breaking space, en-space, em-space, thin space, zero-width space, ideographic space).
15-
- Optimized string concatenation in `repeat_str` by replacing basic concatenation with `gleam/string_tree` for better performance on large string repetitions.
1618

1719
---
1820

manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
5+
{ name = "gleam_stdlib", version = "0.70.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86949BF5D1F0E4AC0AB5B06F235D8A5CC11A2DFC33BF22F752156ED61CA7D0FF" },
66
{ name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" },
77
{ name = "houdini", version = "1.2.0", build_tools = ["gleam"], requirements = [], otp_app = "houdini", source = "hex", outer_checksum = "5DB1053F1AF828049C2B206D4403C18970ABEF5C18671CA3C2D2ED0DD64F6385" },
88
{ name = "odysseus", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "odysseus", source = "hex", outer_checksum = "6A97DA1075BDDEA8B60F47B1DFFAD49309FA27E73843F13A0AF32EA7087BA11C" },

src/str/internal/core.gleam

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ pub fn distance(a: String, b: String) -> Int {
13401340
/// Uses a single row for space efficiency.
13411341
fn levenshtein(a: List(String), b: List(String), _a_len: Int, b_len: Int) -> Int {
13421342
// Initialize first row: [0, 1, 2, ..., b_len]
1343-
let initial_row = list.range(0, b_len)
1343+
let initial_row = int.range(from: 0, to: b_len + 1, with: [], run: list.prepend) |> list.reverse
13441344

13451345
// Process each character of a
13461346
let final_row =
@@ -1799,12 +1799,16 @@ pub fn is_hex(text: String) -> Bool {
17991799
/// escape_html("Tom & Jerry") -> "Tom & Jerry"
18001800
/// escape_html("Say \"hello\"") -> "Say "hello""
18011801
///
1802+
/// Escapes a string to be safely used inside an HTML document.
1803+
///
1804+
/// escape_html("<div>") -> "&lt;div&gt;"
1805+
/// escape_html("Tom & Jerry") -> "Tom &amp; Jerry"
1806+
///
18021807
pub fn escape_html(text: String) -> String {
18031808
houdini.escape(text)
18041809
}
18051810

18061811
/// Unescapes HTML entities to their character equivalents.
1807-
/// Handles: &amp; &lt; &gt; &quot; &#39;
18081812
///
18091813
/// unescape_html("&lt;div&gt;") -> "<div>"
18101814
/// unescape_html("Tom &amp; Jerry") -> "Tom & Jerry"

test/str_config_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gleam/list
1+
import gleam/int
22
import str
33

44
// removed unused import
@@ -8,7 +8,7 @@ pub fn smart_search_default_test() {
88
}
99

1010
fn make_repeat(s: String, n: Int) -> String {
11-
list.fold(list.range(1, n), "", fn(acc, _) { acc <> s })
11+
int.range(from: 1, to: n + 1, with: "", run: fn(acc, _) { acc <> s })
1212
}
1313

1414
pub fn choose_strategy_min_pattern_test() {

test/str_core_test.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gleam/int
12
import gleam/list
23
import gleam/string
34
import str
@@ -406,7 +407,7 @@ pub fn grapple_len_behavior_test() {
406407
assert str.length("👨‍👩‍👧‍👦") == 1
407408

408409
// Stress: long ASCII string should return its length
409-
let long = list.fold(list.range(1, 1000), "", fn(acc, _) { acc <> "x" })
410+
let long = int.range(from: 1, to: 1001, with: "", run: fn(acc, _) { acc <> "x" })
410411
assert str.length(long) == 1000
411412
}
412413

test/str_html_escape_fuzz_test.gleam

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gleam/int
12
import gleam/list
23
import gleam/string
34
import gleeunit
@@ -68,16 +69,14 @@ fn idx_for(seed: Int, i: Int, len: Int) -> Int {
6869

6970
fn gen_string(seed: Int, tokens: List(String), n: Int) -> String {
7071
let len = list.length(tokens)
71-
let seq = list.range(0, n - 1)
72-
seq
73-
|> list.map(fn(i) {
72+
int.range(from: 0, to: n, with: "", run: fn(acc, i) {
7473
let j = idx_for(seed, i, len)
75-
case list.drop(tokens, j) {
74+
let token = case list.drop(tokens, j) {
7675
[first, ..] -> first
7776
[] -> ""
7877
}
78+
acc <> token
7979
})
80-
|> list.fold("", fn(acc, s) { acc <> s })
8180
}
8281

8382
fn run_cfg(seed: Int, n: Int, tokens: List(String)) -> Bool {

test/str_kmp_cache_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gleam/list
1+
import gleam/int
22
import str
33

44
pub fn kmp_maps_reuse_index_test() {
@@ -28,5 +28,5 @@ pub fn kmp_maps_reuse_search_all_test() {
2828
}
2929

3030
fn repeat(s: String, n: Int) -> String {
31-
list.fold(list.range(1, n), "", fn(acc, _) { acc <> s })
31+
int.range(from: 1, to: n + 1, with: "", run: fn(acc, _) { acc <> s })
3232
}

test/str_length_edge_cases_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gleam/list
1+
import gleam/int
22
import str
33

44
pub fn length_edge_cases_test() {
@@ -14,6 +14,6 @@ pub fn length_edge_cases_test() {
1414
assert str.length("👩‍❤️‍👨") == 1
1515

1616
// Long string sanity: 500 'x' characters
17-
let long = list.fold(list.range(1, 500), "", fn(acc, _) { acc <> "x" })
17+
let long = int.range(from: 1, to: 501, with: "", run: fn(acc, _) { acc <> "x" })
1818
assert str.length(long) == 500
1919
}

test/str_length_more_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gleam/list
1+
import gleam/int
22
import str
33

44
pub fn length_more_test() {
@@ -30,6 +30,6 @@ pub fn length_more_test() {
3030
assert str.length("𐐷") == 1
3131

3232
// Long ASCII string
33-
let long = list.fold(list.range(1, 100), "", fn(acc, _) { acc <> "x" })
33+
let long = int.range(from: 1, to: 101, with: "", run: fn(acc, _) { acc <> "x" })
3434
assert str.length(long) == 100
3535
}

test/str_strategy_explicit_test.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gleam/int
12
import gleam/list
23
import str
34
import str/internal/core
@@ -31,5 +32,5 @@ pub fn count_strategy_kmp_test() {
3132
}
3233

3334
fn repeat(s: String, n: Int) -> String {
34-
list.fold(list.range(1, n), "", fn(acc, _) { acc <> s })
35+
int.range(from: 1, to: n + 1, with: "", run: fn(acc, _) { acc <> s })
3536
}

0 commit comments

Comments
 (0)