public static Utf8Span TryCaptureBetween(this Utf8Span str, byte before, byte after) { var start = str.IndexOfRaw(before); if (start == -1) { return(Utf8Span.Empty); } str = str.SubstringRaw(start + 1); var end = str.IndexOfRaw(after); if (end == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(0, end)); }
public static Utf8Span CaptureBetween(this Utf8Span str, byte before, byte after) { var start = str.IndexOfRaw(before); if (start == -1) { throw new InvalidDataException(); } str = str.SubstringRaw(start + 1); var end = str.IndexOfRaw(after); if (end == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(0, end)); }
public static Utf8Span TryCaptureBetween(this Utf8Span str, Utf8Span before, Utf8Span after, StringComparison comparisonType = StringComparison.Ordinal) { var start = str.IndexOfRaw(before, comparisonType); if (start == -1) { return(Utf8Span.Empty); } str = str.SubstringRaw(start + before.Length()); var end = str.IndexOfRaw(after, comparisonType); if (end == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(0, end)); }
public static Utf8Span CaptureBetween(this Utf8Span str, Utf8Span before, Utf8Span after, StringComparison comparisonType = StringComparison.Ordinal) { var start = str.IndexOfRaw(before, comparisonType); if (start == -1) { throw new InvalidDataException(); } str = str.SubstringRaw(start + before.Length()); var end = str.IndexOfRaw(after, comparisonType); if (end == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(0, end)); }
public static Utf8Span TryCaptureBefore(this Utf8Span str, byte suffix) { var end = str.IndexOfRaw(suffix); if (end == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(0, end)); }
public static Utf8Span TryCaptureAfter(this Utf8Span str, byte prefix) { var start = str.IndexOfRaw(prefix); if (start == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(start + 1)); }
public static Utf8Span TryCaptureBefore(this Utf8Span str, Utf8Span suffix, StringComparison comparisonType = StringComparison.Ordinal) { var end = str.IndexOfRaw(suffix, comparisonType); if (end == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(0, end)); }
public static Utf8Span TryCaptureAfter(this Utf8Span str, Utf8Span prefix, StringComparison comparisonType = StringComparison.Ordinal) { var start = str.IndexOfRaw(prefix, comparisonType); if (start == -1) { return(Utf8Span.Empty); } return(str.SubstringRaw(start + prefix.Length())); }
public static Utf8Span CaptureBefore(this Utf8Span str, byte suffix) { var end = str.IndexOfRaw(suffix); if (end == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(0, end)); }
public static Utf8Span CaptureAfter(this Utf8Span str, byte prefix) { var start = str.IndexOfRaw(prefix); if (start == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(start + 1)); }
public static Utf8Span CaptureBefore(this Utf8Span str, Utf8Span suffix, StringComparison comparisonType = StringComparison.Ordinal) { var end = str.IndexOfRaw(suffix, comparisonType); if (end == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(0, end)); }
public static Utf8Span CaptureAfter(this Utf8Span str, Utf8Span prefix, StringComparison comparisonType = StringComparison.Ordinal) { var start = str.IndexOfRaw(prefix, comparisonType); if (start == -1) { throw new InvalidDataException(); } return(str.SubstringRaw(start + prefix.Length())); }
public static Utf8Span ReadTo(ref Utf8Span str, byte end) { var idx = str.IndexOfRaw(end); if (idx == -1) { throw new FormatException(); } var v = str.SubstringRaw(0, idx); str = str.SubstringRaw(idx + 1); return(v); }
/* * internal static bool IsWhiteSpace(Utf8Span str) * { * str.Trim() * if (str.Length == 0) return true; * for (int i = 0; i < str.Length; i++) * { * if (Utf8Span.IsWhiteSpace(str[i])) return false; * } * return true; * } */ private unsafe int FindSeparator(Utf8Span haystack, Utf8String[] separator, out int foundSeparator) { foundSeparator = 0; if (separator.Length == 1) { var sep = separator[0]; if (sep.Length() == 1) { return(haystack.IndexOfRaw(sep.CharAt(0))); } else { return(haystack.IndexOfRaw(sep)); } } else { byte *charMap = stackalloc byte[32]; InitializeProbabilisticMap(charMap, separator); //ref byte pCh = ref haystack.Bytes.DangerousGetPinnableReference(); //var charthere = haystack.Bytes[0]; //var fond = pCh; for (int i = 0; i < haystack.Length(); i++) { //byte thisChar = Unsafe.Add<byte>(ref pCh, i); byte thisChar = haystack.CharAt(i); if (ProbablyContains(charMap, thisChar)) { var substr = new Utf8Span(haystack.Bytes.Slice(i)); for (int j = 0; j < separator.Length; j++) { if (substr.StartsWith(separator[j])) { foundSeparator = j; return(i); } } //if (ArrayContains(thisChar, anyOf) >= 0) //return i; } } /* * var maxlen = 0; * for (int i = 0; i < separator.Length; i++) * { * maxlen = Math.Max(maxlen, separator[i].Length); * } * * * int expected = -1; * for (int i = 0; i < haystack.Length; i++) * { * var substr = new Utf8Span(haystack.Bytes.Slice(i)); * for (int j = 0; j < separator.Length; j++) * { * if (substr.StartsWith(separator[j])) * { * expected = i; * break; * } * } * if (expected != -1) break; * } * * * var min = int.MaxValue; * var minsep = -1; * const int STEP_SIZE = 100; * for (int j = 0; j < haystack.Length; j += STEP_SIZE) * { * * var subhaystack = haystack.Substring(j, Math.Min(STEP_SIZE + maxlen, haystack.Length - j)); * for (int i = 0; i < separator.Length; i++) * { * var pos = subhaystack.IndexOf(separator[i]); * if (pos != -1) * { * if (pos < min) * { * min = pos; * minsep = i; * subhaystack = subhaystack.Substring(0, Math.Min(min + maxlen, subhaystack.Length)); * } * } * } * * //#if DEBUG * // if (minsep != -1) * // { * // foundSeparator = minsep; * // var v = j + min; * // Debug.Assert(expected == v); * // return v; * // } * //#endif * } * */ return(-1); } }