Skip to content

Commit

Permalink
v2.0.0-RC.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Sep 13, 2023
1 parent 85e9e40 commit aa5a899
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions LC6464.Base16384.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Authors>LC</Authors>
<Version>2.0.0-Preview.2</Version>
<PackageReleaseNotes>修复一些高级 API 逻辑错误以及 Span 访问越界等致命问题。</PackageReleaseNotes>
<Version>2.0.0-RC.1</Version>
<PackageReleaseNotes>完成了 ToUtf8BOMBytes 方法。</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Runtime.InteropServices" />
Expand Down
5 changes: 5 additions & 0 deletions Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ private static void EncodeLengthInternal(long dataLength, out long outLength, ou
/// </summary>
public static ReadOnlySpan<byte> Utf16LEPreamble => new byte[] { 0xFF, 0xFE };

/// <summary>
/// UTF-8 with BOM 编码的 BOM,应在文件头部出现。
/// </summary>
public static ReadOnlySpan<byte> Utf8Preamble => new byte[] { 0xEF, 0xBB, 0xBF };


/// <summary>
/// 计算编码指针需要的长度。
Expand Down
11 changes: 7 additions & 4 deletions Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ public static partial class Base16384 {
public static ReadOnlySpan<byte> ConvertFromUtf16BEBytesToUtf8Bytes(this ReadOnlySpan<byte> data) =>
Encoding.Convert(Encoding.BigEndianUnicode, Encoding.UTF8, data.ToArray());

#if DEBUG // 此处仍有问题,暂时不使用
/// <summary>
/// 将 UTF-16 BE 编码的数据转换为 UTF-8 with BOM 编码的数据。
/// </summary>
/// <param name="data">UTF-16 BE 编码的数据</param>
/// <returns>UTF-8 with BOM 编码的数据</returns>
public static ReadOnlySpan<byte> ConvertFromUtf16BEBytesToUtf8BOMBytes(this ReadOnlySpan<byte> data) =>
Encoding.Convert(Encoding.BigEndianUnicode, new UTF8Encoding(true), data.ToArray());
#endif
public static ReadOnlySpan<byte> ConvertFromUtf16BEBytesToUtf8BOMBytes(this ReadOnlySpan<byte> data) {
Span<byte> buffer = new byte[data.Length + 3];
Utf8Preamble.CopyTo(buffer);
data.ConvertFromUtf16BEBytesToUtf8Bytes().CopyTo(buffer[3..]);
return buffer;
}


/// <summary>
/// 将 UTF-16 BE 编码的数据转换为字符串。
Expand Down

0 comments on commit aa5a899

Please sign in to comment.