-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
6 changed files
with
92 additions
and
5 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
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
50 changes: 50 additions & 0 deletions
50
Backports/Features/Span/System/SpanHelper.StringHandler.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,50 @@ | ||
// This file is part of Hawkynt's .NET Framework extensions. | ||
// | ||
// Hawkynt's .NET Framework extensions are free software: | ||
// you can redistribute and/or modify it under the terms | ||
// given in the LICENSE file. | ||
// | ||
// Hawkynt's .NET Framework extensions is distributed in the hope that | ||
// it will be useful, but WITHOUT ANY WARRANTY without even the implied | ||
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the LICENSE file for more details. | ||
// | ||
// You should have received a copy of the License along with Hawkynt's | ||
// .NET Framework extensions. If not, see | ||
// <https://github.com/Hawkynt/C--FrameworkExtensions/blob/master/LICENSE>. | ||
|
||
#if !SUPPORTS_SPAN | ||
|
||
namespace System; | ||
|
||
internal static partial class SpanHelper { | ||
public class StringHandler(string source, int start) : IMemoryHandler<char> { | ||
#region Implementation of IMemoryHandler<char> | ||
|
||
/// <inheritdoc /> | ||
public ref char this[int index] => ref new[] { source[start + index] }[0]; | ||
|
||
/// <inheritdoc /> | ||
public IMemoryHandler<char> SliceFrom(int offset) => new StringHandler(source, start + offset); | ||
|
||
/// <inheritdoc /> | ||
public void CopyTo(IMemoryHandler<char> other, int length) { | ||
for (int i = 0, offset = start; i < length; ++offset, ++i) | ||
other[i] = source[offset]; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void CopyTo(char[] target, int count) => source.CopyTo(start, target, 0, count); | ||
|
||
#endregion | ||
|
||
#region Overrides of Object | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() => start == 0 ? source : source[start..]; | ||
|
||
#endregion | ||
} | ||
} | ||
|
||
#endif |
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