diff --git a/Text.cs b/Text.cs index 22c5f99..923a353 100644 --- a/Text.cs +++ b/Text.cs @@ -20,9 +20,10 @@ public static ReadOnlySpan ConvertFromUtf16BEBytesToUtf8Bytes(this ReadOnl /// UTF-16 BE 编码的数据 /// UTF-8 with BOM 编码的数据 public static ReadOnlySpan ConvertFromUtf16BEBytesToUtf8BOMBytes(this ReadOnlySpan data) { - Span buffer = new byte[data.Length + 3]; + var utf8Bytes = data.ConvertFromUtf16BEBytesToUtf8Bytes(); + Span buffer = new byte[utf8Bytes.Length + 3]; Utf8Preamble.CopyTo(buffer); - data.ConvertFromUtf16BEBytesToUtf8Bytes().CopyTo(buffer[3..]); + utf8Bytes.CopyTo(buffer[3..]); return buffer; }