description.cr updated

Co-authored-by: Fijxu <fijxu@nadeko.net>
This commit is contained in:
shiny-comic 2026-02-17 12:04:58 +09:00 committed by GitHub
parent 0e5809c536
commit 51aab0681b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,10 +29,16 @@ private def copy_string(str : String::Builder, iter : Iterator, count : Int) : I
return copied return copied
end end
# size < bytesize, so we need to count the number of characters that are
# two UInt16 wide.
# Taken from: https://github.com/crystal-lang/crystal/blob/8fa7f90c091aa3757821c04ee243c7ab5f67ac20/src/string/utf16.cr#L18-L20
private def utf16_length(content : String) : Int32 private def utf16_length(content : String) : Int32
content.each_char.sum { |ch| ch.ord >= 0x10000 ? 2 : 1 } u16_size = 0
content.each_char do |char|
u16_size += char.ord < 0x1_0000 ? 1 : 2
end
u16_size
end 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?