-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add async implementations to the HtmlFormatter. #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
40a43b9
298dc15
db731be
5a4766f
1cd8889
5e7c77a
b30e88e
e267276
c61a2c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,21 @@ | |
| Write(value.ToCharArray(), 0, value.Length); | ||
| } | ||
|
|
||
| public override async Task WriteAsync(string value) | ||
| { | ||
| await WriteAsync(value.ToCharArray(), 0, value.Length); | ||
| } | ||
|
|
||
| public override void Write(char[] value) | ||
| { | ||
| Write(value, 0, value.GetLength(0)); | ||
| } | ||
|
|
||
| public async Task WriteAsync(char[] value) | ||
|
||
| { | ||
| await WriteAsync(value, 0, value.GetLength(0)); | ||
| } | ||
|
|
||
| public override void Write(char[] source, int offset, int length) | ||
| { | ||
| if (offset + length > source.GetLength(0)) | ||
|
|
@@ -62,6 +72,38 @@ | |
| } | ||
| } | ||
|
|
||
| public override async Task WriteAsync(char[] source, int offset, int length) | ||
| { | ||
| if (offset + length > source.GetLength(0)) | ||
| throw new ArgumentException("Cannot read past the end of the input source char array."); | ||
|
|
||
| char[] destination = PrepareBuffer(); | ||
| int flushAt = BUFFER_SIZE - 2; | ||
| int written = 0; | ||
| for (int i = offset; i < offset + length; i++) | ||
| { | ||
| char c = source[i]; | ||
|
|
||
| // Flush buffer if (nearly) full | ||
| if (written >= flushAt) | ||
| { | ||
| await Writer.WriteAsync(destination, 0, written); | ||
| written = 0; | ||
| } | ||
|
|
||
| // Write with escapes | ||
| if (c == '/') | ||
| { | ||
| destination[written++] = '\\'; | ||
| } | ||
| destination[written++] = c; | ||
| } | ||
| // Flush any remaining | ||
| if (written > 0) | ||
| { | ||
| await Writer.WriteAsync(destination, 0, written); | ||
| } | ||
| } | ||
| private char[] PrepareBuffer() | ||
| { | ||
| // Reuse the same buffer, avoids repeated array allocation | ||
|
|
@@ -74,6 +116,11 @@ | |
| Writer.Flush(); | ||
| } | ||
|
|
||
| public override async Task FlushAsync() | ||
| { | ||
| await Writer.FlushAsync(); | ||
| } | ||
|
|
||
| public override void Close() | ||
| { | ||
| Writer.Close(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.