Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Apr 28, 2019
1 parent 1163976 commit 1b15c44
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions EhTagClient/MarkdigExt/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace EhTagClient.MarkdigExt
{
internal static class Extension
{
static readonly byte[] _HexChars = "0123456789ABCDEF".Select(c => (byte)c).ToArray();
private static readonly byte[] _HexChars = "0123456789ABCDEF".Select(c => (byte)c).ToArray();
private const int UTF8_MAX_LEN = 6;

public static string NormalizeUri(string url)
{
Expand All @@ -25,7 +26,7 @@ public static string NormalizeUri(string url)
var ch = uri[i];
if ("()".IndexOf(ch) >= 0 || char.IsWhiteSpace(ch) || char.IsControl(ch))
{
var b = (Span<byte>)stackalloc byte[12];
var b = (Span<byte>)stackalloc byte[3 * UTF8_MAX_LEN];
var l = encodeChar(uri.Slice(i, 1), b);
buf.Write(b.Slice(0, l));
}
Expand All @@ -37,7 +38,7 @@ public static string NormalizeUri(string url)
|| char.IsControl((char)bc)
|| char.IsWhiteSpace((char)bc)))
{
var b = (Span<byte>)stackalloc byte[4 * 3];
var b = (Span<byte>)stackalloc byte[3 * UTF8_MAX_LEN];
var l = enc.GetBytes(uri.Slice(i, 3), b);
buf.Write(b.Slice(0, l));
}
Expand All @@ -49,7 +50,7 @@ public static string NormalizeUri(string url)
}
else
{
var b = (Span<byte>)stackalloc byte[4];
var b = (Span<byte>)stackalloc byte[UTF8_MAX_LEN];
var l = enc.GetBytes(uri.Slice(i, 1), b);
buf.Write(b.Slice(0, l));
}
Expand All @@ -66,7 +67,7 @@ bool isHexChar(char ch)

int encodeChar(ReadOnlySpan<char> chars, Span<byte> bytes)
{
var chbytes = (Span<byte>)stackalloc byte[4];
var chbytes = (Span<byte>)stackalloc byte[UTF8_MAX_LEN];
var chlen = enc.GetBytes(chars, chbytes);
for (var i = 0; i < chlen; i++)
{
Expand Down

0 comments on commit 1b15c44

Please sign in to comment.