public static Utf8String?ValidateAndFixupUtf8String(Utf8String?value) { if (Utf8String.IsNullOrEmpty(value)) { return(value); } ReadOnlySpan <byte> valueAsBytes = value.AsBytes(); int idxOfFirstInvalidData = GetIndexOfFirstInvalidUtf8Sequence(valueAsBytes, out _); if (idxOfFirstInvalidData < 0) { return(value); } // TODO_UTF8STRING: Replace this with the faster implementation once it's available. // (The faster implementation is in the dev/utf8string_bak branch currently.) MemoryStream memStream = new MemoryStream(); memStream.Write(valueAsBytes.Slice(0, idxOfFirstInvalidData)); valueAsBytes = valueAsBytes.Slice(idxOfFirstInvalidData); do { if (Rune.DecodeFromUtf8(valueAsBytes, out _, out int bytesConsumed) == OperationStatus.Done) { // Valid scalar value - copy data as-is to MemoryStream memStream.Write(valueAsBytes.Slice(0, bytesConsumed)); } else { // Invalid scalar value - copy U+FFFD to MemoryStream memStream.Write(ReplacementCharSequence); } valueAsBytes = valueAsBytes.Slice(bytesConsumed); } while (!valueAsBytes.IsEmpty); bool success = memStream.TryGetBuffer(out ArraySegment <byte> memStreamBuffer); Debug.Assert(success, "Couldn't get underlying MemoryStream buffer."); return(Utf8String.DangerousCreateWithoutValidation(memStreamBuffer, assumeWellFormed: true)); }
public int CompareToCi(Utf8String?other) { if (ReferenceEquals(null, other)) { return(0); } if (ReferenceEquals(this, other)) { return(1); } if ((IsAsciiLowerInternal ?? false) && (other.IsAsciiLowerInternal ?? false)) { return(ByteStringFunctions.Compare(_path, Length, other._path, other.Length)); } return(ByteStringFunctions.AsciiCaselessCompare(_path, Length, other._path, other.Length)); }
public bool EqualsCi(Utf8String?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if ((IsAsciiLowerInternal ?? false) && (other.IsAsciiLowerInternal ?? false)) { return(_crc32 == other._crc32 && ByteStringFunctions.Equals(_path, Length, other._path, other.Length)); } return(ByteStringFunctions.AsciiCaselessEquals(_path, Length, other._path, other.Length)); }
public override int Compare(Utf8String?x, Utf8String?y) { // TODO_UTF8STRING: Avoid the allocations below. return(_compareInfo.Compare(x?.ToString(), y?.ToString(), _options)); }
public override bool Equals(Utf8String?x, Utf8String?y) { // TODO_UTF8STRING: Avoid the allocations below. return(StringComparer.OrdinalIgnoreCase.Equals(x?.ToString(), y?.ToString())); }
public override bool Equals(Utf8String?x, Utf8String?y) => Utf8String.Equals(x, y);
public override int Compare(Utf8String?x, Utf8String?y) { // TODO_UTF8STRING: Avoid the allocations below. return(string.CompareOrdinal(x?.ToString(), y?.ToString())); }
public Utf8Span(Utf8String?value) { Bytes = Utf8Extensions.AsBytes(value); }
public static ReadOnlySpan <byte> AsBytes(this Utf8String?text) { if (text is null) { return(default);
public Utf8Span(Utf8String?value) { throw new PlatformNotSupportedException(); }
public static bool IsNullOrEmpty([NotNullWhen(false)] Utf8String?value) { return(value == null || value.Length == 0); }
/// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target <see cref="Utf8String"/>.</summary> /// <param name="text">The target <see cref="Utf8String"/>.</param> /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> public static ReadOnlyMemory <Char8> AsMemory(this Utf8String?text) { if (text is null) { return(default);
public Chat(Utf8String?value) { Value = value; }
public NbtString(Utf8String?value) { Value = value; }
public override bool Equals(Utf8String?x, Utf8String?y) => Compare(x, y) == 0;
public Utf8Splitter EnumerateSplit( Utf8String?separator, StringSplitOptions splitOptions = StringSplitOptions.None) { return(EnumerateSplit(separator.AsSpan(), splitOptions)); }
public override int GetHashCode(Utf8String?obj) { // TODO_UTF8STRING: Avoid the allocations below. return((obj is null) ? 0 : _compareInfo.GetHashCode(obj.ToString(), _options)); }
public static ReadOnlySpan <byte> AsSpan(this Utf8String?value) { if (value == null) { return(default);