mirror of
https://github.com/iv-org/invidious.git
synced 2026-01-28 07:48:31 -06:00
Merge 50fa843eb563dd231cae46693de628d54f5b1f0f into d51a7a44ad91d2fa7d1330970a15a0d8f365f250
This commit is contained in:
commit
be1e060150
@ -29,6 +29,10 @@ private def copy_string(str : String::Builder, iter : Iterator, count : Int) : I
|
|||||||
return copied
|
return copied
|
||||||
end
|
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?
|
def parse_description(desc, video_id : String) : String?
|
||||||
return "" if desc.nil?
|
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
|
# Slightly faster than HTML.escape, as we're only doing one pass on
|
||||||
# the string instead of five for the standard library
|
# the string instead of five for the standard library
|
||||||
return String.build do |str|
|
return String.build do |str|
|
||||||
copy_string(str, content.each_codepoint, content.size)
|
copy_string(str, content.each_codepoint, utf16_length(content))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,7 +80,7 @@ def parse_description(desc, video_id : String) : String?
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Copy the end of the string (past the last command).
|
# 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
|
copy_string(str, iter, remaining_length) if remaining_length > 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user