-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/wpiutil/Serialization/Struct/Parsing/Utf8CodePointEnumerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Buffers; | ||
using System.Text; | ||
|
||
namespace WPIUtil.Serialization.Struct.Parsing; | ||
|
||
public ref struct Utf8CodePointEnumerator(ReadOnlySpan<byte> str) { | ||
private readonly ReadOnlySpan<byte> m_str = str; | ||
private int m_index; | ||
public Rune Current {readonly get; private set;} | ||
|
||
public int CurrentMark {readonly get; private set;} | ||
|
||
public readonly ReadOnlySpan<byte> MarkedSpan => m_str[CurrentMark..m_index]; | ||
|
||
public void Mark() { | ||
CurrentMark = m_index; | ||
} | ||
|
||
public bool MoveNext() { | ||
var status = Rune.DecodeFromUtf8(m_str[m_index..], out var result, out var bytesConsumed); | ||
m_index += bytesConsumed; | ||
Current = result; | ||
|
||
return status != OperationStatus.NeedMoreData; | ||
} | ||
|
||
public bool MovePrevious() { | ||
var status = Rune.DecodeLastFromUtf8(m_str[..^m_index], out var result, out var bytesConsumed); | ||
m_index -= bytesConsumed; | ||
Current = result; | ||
|
||
return status != OperationStatus.NeedMoreData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.