{
string s = m_value ? TrueLiteral : FalseLiteral;
- if (s.AsReadOnlySpan().TryCopyTo(destination))
+ if (s.AsSpan().TryCopyTo(destination))
{
charsWritten = s.Length;
return true;
public static Boolean Parse(String value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
- return Parse(value.AsReadOnlySpan());
+ return Parse(value.AsSpan());
}
public static bool Parse(ReadOnlySpan<char> value) =>
return false;
}
- return TryParse(value.AsReadOnlySpan(), out result);
+ return TryParse(value.AsSpan(), out result);
}
public static bool TryParse(ReadOnlySpan<char> value, out bool result)
{
- ReadOnlySpan<char> trueSpan = TrueLiteral.AsReadOnlySpan();
+ ReadOnlySpan<char> trueSpan = TrueLiteral.AsSpan();
if (StringSpanHelpers.Equals(trueSpan, value, StringComparison.OrdinalIgnoreCase))
{
result = true;
return true;
}
- ReadOnlySpan<char> falseSpan = FalseLiteral.AsReadOnlySpan();
+ ReadOnlySpan<char> falseSpan = FalseLiteral.AsSpan();
if (StringSpanHelpers.Equals(falseSpan, value, StringComparison.OrdinalIgnoreCase))
{
result = false;
_pos = pos + 1;
}
- public ReadOnlySpan<T> AsReadOnlySpan()
+ public ReadOnlySpan<T> AsSpan()
{
return _span.Slice(0, _pos);
}
return 0;
}
- int r = ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
+ int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
if (r < Byte.MinValue || r > Byte.MaxValue)
ThrowByteOverflowException();
return (byte)r;
return 0;
}
- int r = ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI1);
+ int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI1);
if (fromBase != 10 && r <= Byte.MaxValue)
return (sbyte)r;
return 0;
}
- int r = ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI2);
+ int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI2);
if (fromBase != 10 && r <= UInt16.MaxValue)
return (short)r;
return 0;
}
- int r = ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
+ int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
if (r < UInt16.MinValue || r > UInt16.MaxValue)
ThrowUInt16OverflowException();
return (ushort)r;
throw new ArgumentException(SR.Arg_InvalidBase);
}
return value != null ?
- ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight) :
+ ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
0;
}
throw new ArgumentException(SR.Arg_InvalidBase);
}
return value != null ?
- (uint)ParseNumbers.StringToInt(value.AsReadOnlySpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
+ (uint)ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
0;
}
throw new ArgumentException(SR.Arg_InvalidBase);
}
return value != null ?
- ParseNumbers.StringToLong(value.AsReadOnlySpan(), fromBase, ParseNumbers.IsTight) :
+ ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
0;
}
throw new ArgumentException(SR.Arg_InvalidBase);
}
return value != null ?
- (ulong)ParseNumbers.StringToLong(value.AsReadOnlySpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
+ (ulong)ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
0;
}
throw new ArgumentNullException(nameof(s));
}
- return TryFromBase64Chars(s.AsReadOnlySpan(), bytes, out bytesWritten);
+ return TryFromBase64Chars(s.AsSpan(), bytes, out bytesWritten);
}
public static unsafe bool TryFromBase64Chars(ReadOnlySpan<char> chars, Span<byte> bytes, out int bytesWritten)
return String.CompareOrdinal(string1, string2);
}
- return CompareString(string1.AsReadOnlySpan(), string2.AsReadOnlySpan(), options);
+ return CompareString(string1.AsSpan(), string2.AsSpan(), options);
}
// TODO https://github.com/dotnet/coreclr/issues/13827:
{
if (options == CompareOptions.OrdinalIgnoreCase)
{
- return CompareOrdinalIgnoreCase(string1, string2.AsReadOnlySpan());
+ return CompareOrdinalIgnoreCase(string1, string2.AsSpan());
}
// Verify the options before we do any real comparison.
throw new ArgumentException(SR.Argument_CompareOptionOrdinal, nameof(options));
}
- return string.CompareOrdinal(string1, string2.AsReadOnlySpan());
+ return string.CompareOrdinal(string1, string2.AsSpan());
}
if ((options & ValidCompareMaskOffFlags) != 0)
if (_invariantMode)
{
return (options & CompareOptions.IgnoreCase) != 0 ?
- CompareOrdinalIgnoreCase(string1, string2.AsReadOnlySpan()) :
- string.CompareOrdinal(string1, string2.AsReadOnlySpan());
+ CompareOrdinalIgnoreCase(string1, string2.AsSpan()) :
+ string.CompareOrdinal(string1, string2.AsSpan());
}
return CompareString(string1, string2, options);
}
return CompareString(
- string1.AsReadOnlySpan().Slice(offset1, length1),
- string2.AsReadOnlySpan().Slice(offset2, length2),
+ string1.AsSpan().Slice(offset1, length1),
+ string2.AsSpan().Slice(offset2, length2),
options);
}
{
Debug.Assert(indexA + lengthA <= strA.Length);
Debug.Assert(indexB + lengthB <= strB.Length);
- return CompareOrdinalIgnoreCase(strA.AsReadOnlySpan().Slice(indexA, lengthA), strB.AsReadOnlySpan().Slice(indexB, lengthB));
+ return CompareOrdinalIgnoreCase(strA.AsSpan().Slice(indexA, lengthA), strB.AsSpan().Slice(indexB, lengthB));
}
internal static unsafe int CompareOrdinalIgnoreCase(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)
{
return false;
}
- if (m_info.Compare(Value.Slice(thisPosition, segmentLength), target.AsReadOnlySpan().Slice(targetPosition, segmentLength), CompareOptions.IgnoreCase) != 0)
+ if (m_info.Compare(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength), CompareOptions.IgnoreCase) != 0)
{
return false;
}
{
return false;
}
- if (m_info.Compare(Value.Slice(thisPosition, segmentLength), target.AsReadOnlySpan().Slice(targetPosition, segmentLength), CompareOptions.IgnoreCase) != 0)
+ if (m_info.Compare(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength), CompareOptions.IgnoreCase) != 0)
{
return false;
}
{
try
{
- int advance = Int32.Parse(str.AsReadOnlySpan().Slice(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
+ int advance = Int32.Parse(str.AsSpan().Slice(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
if ((advance >= MinAdvancedHijri) && (advance <= MaxAdvancedHijri))
{
hijriAdvance = advance;
int month;
int day;
- ReadOnlySpan<char> valueSpan = value.AsReadOnlySpan();
+ ReadOnlySpan<char> valueSpan = value.AsSpan();
if (!Int32.TryParse(valueSpan.Slice(0, 4), NumberStyles.None, NumberFormatInfo.InvariantInfo, out year) ||
!Int32.TryParse(valueSpan.Slice(5, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out month) ||
!Int32.TryParse(valueSpan.Slice(8, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out day))
if (path == null)
return false;
- return IsPathRooted(path.AsReadOnlySpan());
+ return IsPathRooted(path.AsSpan());
}
public static bool IsPathRooted(ReadOnlySpan<char> path)
public static ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
{
- return PathInternal.IsEffectivelyEmpty(path) && IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString.AsReadOnlySpan() : ReadOnlySpan<char>.Empty;
+ return PathInternal.IsEffectivelyEmpty(path) && IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString.AsSpan() : ReadOnlySpan<char>.Empty;
}
/// <summary>Gets whether the system is case-sensitive.</summary>
// Path is current drive rooted i.e. starts with \:
// "\Foo" and "C:\Bar" => "C:\Foo"
// "\Foo" and "\\?\C:\Bar" => "\\?\C:\Foo"
- combinedPath = CombineNoChecks(GetPathRoot(basePath), path.AsReadOnlySpan().Slice(1));
+ combinedPath = CombineNoChecks(GetPathRoot(basePath), path.AsSpan().Slice(1));
}
else if (length >= 2 && PathInternal.IsValidDriveChar(path[0]) && path[1] == PathInternal.VolumeSeparatorChar)
{
// Drive relative paths
Debug.Assert(length == 2 || !PathInternal.IsDirectorySeparator(path[2]));
- if (StringSpanHelpers.Equals(GetVolumeName(path.AsReadOnlySpan()), GetVolumeName(basePath.AsReadOnlySpan())))
+ if (StringSpanHelpers.Equals(GetVolumeName(path.AsSpan()), GetVolumeName(basePath.AsSpan())))
{
// Matching root
// "C:Foo" and "C:\Bar" => "C:\Bar\Foo"
// "C:Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo"
- combinedPath = CombineNoChecks(basePath, path.AsReadOnlySpan().Slice(2));
+ combinedPath = CombineNoChecks(basePath, path.AsSpan().Slice(2));
}
else
{
// if it starts with a backslash ("\") or a valid drive letter and a colon (":").
public static bool IsPathRooted(string path)
{
- return path != null && IsPathRooted(path.AsReadOnlySpan());
+ return path != null && IsPathRooted(path.AsSpan());
}
public static bool IsPathRooted(ReadOnlySpan<char> path)
if (PathInternal.IsEffectivelyEmpty(path))
return null;
- ReadOnlySpan<char> result = GetPathRoot(path.AsReadOnlySpan());
+ ReadOnlySpan<char> result = GetPathRoot(path.AsSpan());
if (path.Length == result.Length)
return PathInternal.NormalizeDirectorySeparators(path);
if (path == null)
return null;
- return new string(GetExtension(path.AsReadOnlySpan()));
+ return new string(GetExtension(path.AsSpan()));
}
/// <summary>
if (path == null)
return null;
- ReadOnlySpan<char> result = GetFileName(path.AsReadOnlySpan());
+ ReadOnlySpan<char> result = GetFileName(path.AsSpan());
if (path.Length == result.Length)
return path;
if (path == null)
return null;
- ReadOnlySpan<char> result = GetFileNameWithoutExtension(path.AsReadOnlySpan());
+ ReadOnlySpan<char> result = GetFileNameWithoutExtension(path.AsSpan());
if (path.Length == result.Length)
return path;
if (path == null)
throw new ArgumentNullException(nameof(path));
- return IsPathFullyQualified(path.AsReadOnlySpan());
+ return IsPathFullyQualified(path.AsSpan());
}
public static bool IsPathFullyQualified(ReadOnlySpan<char> path)
{
if (path != null)
{
- return HasExtension(path.AsReadOnlySpan());
+ return HasExtension(path.AsSpan());
}
return false;
}
if (string.IsNullOrEmpty(second))
return first;
- if (IsPathRooted(second.AsReadOnlySpan()))
+ if (IsPathRooted(second.AsSpan()))
return second;
return CombineNoChecksInternal(first, second);
if (string.IsNullOrEmpty(third))
return CombineNoChecks(first, second);
- if (IsPathRooted(third.AsReadOnlySpan()))
+ if (IsPathRooted(third.AsSpan()))
return third;
- if (IsPathRooted(second.AsReadOnlySpan()))
+ if (IsPathRooted(second.AsSpan()))
return CombineNoChecks(second, third);
return CombineNoChecksInternal(first, second, third);
if (string.IsNullOrEmpty(fourth))
return CombineNoChecks(first, second, third);
- if (IsPathRooted(fourth.AsReadOnlySpan()))
+ if (IsPathRooted(fourth.AsSpan()))
return fourth;
- if (IsPathRooted(third.AsReadOnlySpan()))
+ if (IsPathRooted(third.AsSpan()))
return CombineNoChecks(third, fourth);
- if (IsPathRooted(second.AsReadOnlySpan()))
+ if (IsPathRooted(second.AsSpan()))
return CombineNoChecks(second, third, fourth);
return CombineNoChecksInternal(first, second, third, fourth);
{
if (value != null)
{
- WriteCore(value.AsReadOnlySpan(), _autoFlush);
+ WriteCore(value.AsSpan(), _autoFlush);
}
}
CheckAsyncTaskInProgress();
if (value != null)
{
- WriteCore(value.AsReadOnlySpan(), autoFlush: false);
+ WriteCore(value.AsSpan(), autoFlush: false);
}
WriteCore(new ReadOnlySpan<char>(CoreNewLine), autoFlush: true);
}
{
Debug.Assert(source != null);
- if (source.AsReadOnlySpan().TryCopyTo(destination))
+ if (source.AsSpan().TryCopyTo(destination))
{
charsWritten = source.Length;
return true;
/// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
/// reference (Nothing in Visual Basic).</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsReadOnlySpan(this string text)
+ public static ReadOnlySpan<char> AsSpan(this string text)
{
if (text == null)
return default;
/// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >text.Length).
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start)
+ public static ReadOnlySpan<char> AsSpan(this string text, int start)
{
if (text == null)
{
/// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start, int length)
+ public static ReadOnlySpan<char> AsSpan(this string text, int start, int length)
{
if (text == null)
{
return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetRawStringData(), start), length);
}
+ // TODO: Delete once the AsReadOnlySpan -> AsSpan rename propages through the system
+ public static ReadOnlySpan<char> AsReadOnlySpan(this string text) => AsSpan(text);
+ public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start) => AsSpan(text, start);
+ public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start, int length) => AsSpan(text, start, length);
+
internal static unsafe void ClearWithoutReferences(ref byte b, nuint byteLength)
{
if (byteLength == 0)
// String allocation and copying is in separate method to make this method faster for the case where
// nothing needs replacing.
- string dst = ReplaceHelper(oldValue.Length, newValue, replacementIndices.AsReadOnlySpan());
+ string dst = ReplaceHelper(oldValue.Length, newValue, replacementIndices.AsSpan());
replacementIndices.Dispose();
int count = replacementIdx - thisIdx;
if (count != 0)
{
- this.AsReadOnlySpan().Slice(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
+ this.AsSpan().Slice(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
dstIdx += count;
}
thisIdx = replacementIdx + oldValueLength;
// Copy over newValue to replace the oldValue.
- newValue.AsReadOnlySpan().CopyTo(dstSpan.Slice(dstIdx));
+ newValue.AsSpan().CopyTo(dstSpan.Slice(dstIdx));
dstIdx += newValue.Length;
}
// Copy over the final non-matching portion at the end of the string.
Debug.Assert(this.Length - thisIdx == dstSpan.Length - dstIdx);
- this.AsReadOnlySpan().Slice(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
+ this.AsSpan().Slice(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
return dst;
}
var sepListBuilder = new ValueListBuilder<int>(initialSpan);
MakeSeparatorList(separators, ref sepListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsReadOnlySpan();
+ ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
// Handle the special case of no replaces.
if (sepList.Length == 0)
var lengthListBuilder = new ValueListBuilder<int>(lengthListInitialSpan);
MakeSeparatorList(separators, ref sepListBuilder, ref lengthListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsReadOnlySpan();
- ReadOnlySpan<int> lengthList = lengthListBuilder.AsReadOnlySpan();
+ ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
+ ReadOnlySpan<int> lengthList = lengthListBuilder.AsSpan();
// Handle the special case of no replaces.
if (sepList.Length == 0)
var sepListBuilder = new ValueListBuilder<int>(sepListInitialSpan);
MakeSeparatorList(separator, ref sepListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsReadOnlySpan();
+ ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
if (sepList.Length == 0)
{
// there are no separators so sepListBuilder did not rent an array from pool and there is no need to dispose it
throw new ArgumentOutOfRangeException(nameof(comparisonType));
public static bool Equals(this ReadOnlySpan<char> left, string right) =>
- Equals(left, right.AsReadOnlySpan());
+ Equals(left, right.AsSpan());
public static bool Equals(this ReadOnlySpan<char> left, ReadOnlySpan<char> right)
{
if (startPos != pos)
{
// There was no brace escaping, extract the item format as a single string
- itemFormatSpan = format.AsReadOnlySpan().Slice(startPos, pos - startPos);
+ itemFormatSpan = format.AsSpan().Slice(startPos, pos - startPos);
}
}
else
int secondDotIndex = dateRule.IndexOf('.', firstDotIndex + 1);
if (secondDotIndex > 0)
{
- if (int.TryParse(dateRule.AsReadOnlySpan().Slice(1, firstDotIndex - 1), out month) &&
- int.TryParse(dateRule.AsReadOnlySpan().Slice(firstDotIndex + 1, secondDotIndex - firstDotIndex - 1), out week) &&
- int.TryParse(dateRule.AsReadOnlySpan().Slice(secondDotIndex + 1), out int day))
+ if (int.TryParse(dateRule.AsSpan().Slice(1, firstDotIndex - 1), out month) &&
+ int.TryParse(dateRule.AsSpan().Slice(firstDotIndex + 1, secondDotIndex - firstDotIndex - 1), out week) &&
+ int.TryParse(dateRule.AsSpan().Slice(secondDotIndex + 1), out int day))
{
dayOfWeek = (DayOfWeek)day;
return true;
throw new ArgumentNullException(nameof(input));
}
- return ParseVersion(input.AsReadOnlySpan(), throwOnFailure: true);
+ return ParseVersion(input.AsSpan(), throwOnFailure: true);
}
public static Version Parse(ReadOnlySpan<char> input) =>
return false;
}
- return (result = ParseVersion(input.AsReadOnlySpan(), throwOnFailure: false)) != null;
+ return (result = ParseVersion(input.AsSpan(), throwOnFailure: false)) != null;
}
public static bool TryParse(ReadOnlySpan<char> input, out Version result) =>