-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Code cleanup, diffable-cs improvements
- Loading branch information
1 parent
c720a52
commit a227bef
Showing
12 changed files
with
111 additions
and
98 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
Cpp2IL.Core.Tests/AccessibilityUtilsTests.cs → ...ore.Tests/AccessibilityExtensionsTests.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
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
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,69 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Cpp2IL.Core.Extensions; | ||
|
||
internal static class EnumerableExtensions | ||
{ | ||
public static IEnumerable<T> MaybeAppend<T>(this IEnumerable<T> enumerable, T? item) where T : struct | ||
{ | ||
if (item is not null) | ||
{ | ||
return enumerable.Append(item.Value); | ||
} | ||
|
||
return enumerable; | ||
} | ||
|
||
public static MemoryEnumerable<T> AsEnumerable<T>(this Memory<T> memory) => new(memory); | ||
|
||
public static MemoryEnumerator<T> GetEnumerator<T>(this Memory<T> memory) => new(memory); | ||
|
||
public class MemoryEnumerable<T> : IEnumerable<T> | ||
{ | ||
private readonly Memory<T> _memory; | ||
|
||
public MemoryEnumerable(Memory<T> memory) | ||
{ | ||
_memory = memory; | ||
} | ||
|
||
public IEnumerator<T> GetEnumerator() => new MemoryEnumerator<T>(_memory); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
public class MemoryEnumerator<T> : IEnumerator<T> | ||
{ | ||
private readonly Memory<T> _memory; | ||
|
||
private int _index = -1; | ||
|
||
public MemoryEnumerator(Memory<T> memory) | ||
{ | ||
_memory = memory; | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
_index++; | ||
return _index < _memory.Length; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
_index = -1; | ||
} | ||
|
||
public T Current => _memory.Span[_index]; | ||
|
||
object? IEnumerator.Current => Current; | ||
|
||
public void Dispose() | ||
{ | ||
// Nothing to dispose | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Cpp2IL.Core.Extensions; | ||
|
||
public static class StringExtensions | ||
{ | ||
public static string EscapeString(this string str) | ||
=> str | ||
.Replace("\\", @"\\") | ||
.Replace("\"", "\\\"") | ||
.Replace("\n", "\\n") | ||
.Replace("\r", "\\r") | ||
.Replace("\t", "\\t") | ||
.Replace("\0", "\\0"); | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
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