Merge 50fa843eb563dd231cae46693de628d54f5b1f0f into d51a7a44ad91d2fa7d1330970a15a0d8f365f250

This commit is contained in:
shiny-comic 2026-01-27 00:24:13 -06:00 committed by GitHub
commit be1e060150
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,6 +29,10 @@ private def copy_string(str : String::Builder, iter : Iterator, count : Int) : I
return copied
end
private def utf16_length(content : String) : Int32
content.each_char.sum { |ch| ch.ord >= 0x10000 ? 2 : 1 }
end
def parse_description(desc, video_id : String) : String?
return "" if desc.nil?
@ -40,7 +44,7 @@ def parse_description(desc, video_id : String) : String?
# Slightly faster than HTML.escape, as we're only doing one pass on
# the string instead of five for the standard library
return String.build do |str|
copy_string(str, content.each_codepoint, content.size)
copy_string(str, content.each_codepoint, utf16_length(content))
end
end
@ -76,7 +80,7 @@ def parse_description(desc, video_id : String) : String?
end
# Copy the end of the string (past the last command).
remaining_length = content.size - index
remaining_length = utf16_length(content) - index
copy_string(str, iter, remaining_length) if remaining_length > 0
end
end