Fix stupid TCO fail
This commit is contained in:
parent
1330319e80
commit
7c1f67a46f
4 changed files with 52 additions and 16 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
4.0.1
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Fixed a call stack error on the JavaScript target
|
||||||
|
|
||||||
4.0.0
|
4.0.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name = "glentities"
|
name = "glentities"
|
||||||
version = "4.0.0"
|
version = "4.0.1"
|
||||||
description = "HTML entity encoder/decoder for Gleam"
|
description = "HTML entity encoder/decoder for Gleam"
|
||||||
|
|
||||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||||
|
|
|
@ -2332,7 +2332,14 @@ pub fn encode_html_body(text: String, acc: StringBuilder) -> String {
|
||||||
">" <> rest -> encode_html_body(rest, string_builder.append(acc, ">"))
|
">" <> rest -> encode_html_body(rest, string_builder.append(acc, ">"))
|
||||||
"\"" <> rest -> encode_html_body(rest, string_builder.append(acc, """))
|
"\"" <> rest -> encode_html_body(rest, string_builder.append(acc, """))
|
||||||
"'" <> rest -> encode_html_body(rest, string_builder.append(acc, "'"))
|
"'" <> rest -> encode_html_body(rest, string_builder.append(acc, "'"))
|
||||||
other -> encode_other_case(other, acc, encode_html_body)
|
other -> {
|
||||||
|
let maybe_grapheme = string.pop_grapheme(other)
|
||||||
|
case maybe_grapheme {
|
||||||
|
Ok(#(grapheme, rest)) ->
|
||||||
|
encode_html_body(rest, string_builder.append(acc, grapheme))
|
||||||
|
Error(Nil) -> string_builder.to_string(acc)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4074,19 +4081,13 @@ pub fn encode_named(text: String, acc: StringBuilder) -> String {
|
||||||
"𝓏" <> rest -> encode_named(rest, string_builder.append(acc, "𝓏"))
|
"𝓏" <> rest -> encode_named(rest, string_builder.append(acc, "𝓏"))
|
||||||
"" <> rest -> encode_named(rest, string_builder.append(acc, "‍"))
|
"" <> rest -> encode_named(rest, string_builder.append(acc, "‍"))
|
||||||
"" <> rest -> encode_named(rest, string_builder.append(acc, "‌"))
|
"" <> rest -> encode_named(rest, string_builder.append(acc, "‌"))
|
||||||
other -> encode_other_case(other, acc, encode_named)
|
other -> {
|
||||||
}
|
let maybe_grapheme = string.pop_grapheme(other)
|
||||||
}
|
case maybe_grapheme {
|
||||||
|
Ok(#(grapheme, rest)) ->
|
||||||
fn encode_other_case(
|
encode_named(rest, string_builder.append(acc, grapheme))
|
||||||
text: String,
|
Error(Nil) -> string_builder.to_string(acc)
|
||||||
acc: StringBuilder,
|
}
|
||||||
continue_callback: fn(String, StringBuilder) -> String,
|
}
|
||||||
) -> String {
|
|
||||||
let maybe_grapheme = string.pop_grapheme(text)
|
|
||||||
case maybe_grapheme {
|
|
||||||
Ok(#(grapheme, rest)) ->
|
|
||||||
continue_callback(rest, string_builder.append(acc, grapheme))
|
|
||||||
Error(Nil) -> string_builder.to_string(acc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import gleam/string
|
||||||
import gleeunit
|
import gleeunit
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
import glentities
|
import glentities
|
||||||
|
@ -74,3 +75,32 @@ pub fn roundtrip_hex_test() {
|
||||||
input,
|
input,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tco_test() {
|
||||||
|
let input =
|
||||||
|
string.repeat(
|
||||||
|
"I will never try to be clever in tail call recursive languages again",
|
||||||
|
100,
|
||||||
|
)
|
||||||
|
|
||||||
|
should.equal(
|
||||||
|
input
|
||||||
|
|> glentities.encode(glentities.Hex)
|
||||||
|
|> glentities.decode(),
|
||||||
|
input,
|
||||||
|
)
|
||||||
|
|
||||||
|
should.equal(
|
||||||
|
input
|
||||||
|
|> glentities.encode(glentities.Named)
|
||||||
|
|> glentities.decode(),
|
||||||
|
input,
|
||||||
|
)
|
||||||
|
|
||||||
|
should.equal(
|
||||||
|
input
|
||||||
|
|> glentities.encode(glentities.HTMLBody)
|
||||||
|
|> glentities.decode(),
|
||||||
|
input,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue