/// <summary> /// Determine whether this string ends with the provided string. /// </summary> public bool EndsWith(string other) { var it = new ReverseUtf8Enumerator(this); for (int i = other.Length - 1; i >= 0; i--) { if (!it.MoveNext()) { return(false); } var c = other[i]; uint codepoint; if (char.IsLowSurrogate(c)) { i--; codepoint = (uint)char.ConvertToUtf32(other[i], c); } else { codepoint = (uint)c; } if (codepoint != it.Current.Value) { return(false); } } return(true); }
/// <summary> /// Create a string consisting of this one, minus any trailing whitespace. /// </summary> /// <remarks> /// This method does not allocate. /// </remarks> public Utf8String TrimEnd() { var it = new ReverseUtf8Enumerator(this); while (it.MoveNext()) { if (!char.IsWhiteSpace((char)it.Current.Value)) { Console.WriteLine("idx: {0} len: {1}", it.Current.Index, it.Current.EncodedLength); return(Substring(0, it.Current.Index + it.Current.EncodedLength)); } } return(Utf8String.Empty); }