public int LastIndexOf(IStringView other, StringComparison sc = StringComparison.Ordinal) { if (Length < other.Length) { return(-1); } int otherIndex = other.Length - 1; for (var i = Length - 1; i >= 0 && otherIndex >= 0; --i) { if (!Compare(this[i], other[otherIndex], sc)) { otherIndex = other.Length - 1; } else { if (otherIndex == 0) { return(i); } otherIndex--; } } return(-1); }
public static bool IsNullOrEmpty(this IStringView sv) { if (sv == null || !sv.valid) { return(true); } return(sv.length == 0); }
// True if 'src' starts with 'pattern' private static bool Match(IStringView src, int start, string pattern) { int i = 0, iend = pattern.Length; if (start + pattern.Length > src.Length) { return(false); } for (; i != iend && src[start + i] == pattern[i]; ++i) { } return(i == iend); }
public static bool IsNullOrWhiteSpace(this IStringView sv) { if (sv.IsNullOrEmpty()) { return(true); } for (var i = 0; i < sv.length; ++i) { if (!char.IsWhiteSpace(sv[i])) { return(false); } } return(true); }
public bool StartsWith(IStringView v, StringComparison sc = StringComparison.Ordinal) { if (v.length > length) { return(false); } for (var i = 0; i < v.length; ++i) { if (!StringView.Compare(this[i], v[i], sc)) { return(false); } } return(true); }
public bool EndsWith(IStringView v, StringComparison sc = StringComparison.Ordinal) { if (v.Length > Length) { return(false); } for (var i = 0; i < v.Length; ++i) { if (!Compare(this[Length - v.Length + i], v[i], sc)) { return(false); } } return(true); }
public int IndexOf(IStringView other, StringComparison sc = StringComparison.Ordinal) { if (!valid || !other.valid) { return(-1); } if (Length < other.Length) { return(-1); } int foundStartIndex = -1; int otherIndex = 0; for (var i = 0; i < Length && otherIndex < other.Length; ++i) { if (!Compare(this[i], other[otherIndex], sc)) { if (foundStartIndex > -1) { foundStartIndex = -1; otherIndex = 0; } } else { if (foundStartIndex == -1) { foundStartIndex = i; } otherIndex++; } } if (otherIndex != other.Length) { return(-1); } return(foundStartIndex); }
public bool Equals(IStringView other, StringComparison comparisonOptions = StringComparison.OrdinalIgnoreCase) { if (other is StringView sv) { return(Equals(sv, comparisonOptions)); } if (other?.Length != Length) { return(false); } for (var i = 0; i < Length; ++i) { if (!Compare(this[i], other[i], comparisonOptions)) { return(false); } } return(true); }
bool IStringView.Equals(IStringView other, StringComparison comparisonOptions) { return(Equals(other, comparisonOptions)); }
bool IStringView.StartsWith(IStringView v, StringComparison sc) { return(StartsWith(v, sc)); }
public bool WithinComment(IStringView src, int i) { // This function requires 'src' because we need to look ahead // to say whether we're in a comment. switch (m_comment) { case EType.None: { if (m_lit.WithinLiteral(src[i])) { } else if (m_emit == 0 && m_pat.m_line_comment.Length != 0 && Match(src, i, m_pat.m_line_comment)) { m_comment = EType.Line; m_emit = m_pat.m_line_comment.Length; m_escape = false; } else if (m_emit == 0 && m_pat.m_block_beg.Length != 0 && Match(src, i, m_pat.m_block_beg)) { m_comment = EType.Block; m_emit = m_pat.m_block_beg.Length; } break; } case EType.Line: { if (src[i] == '\0') { m_comment = EType.None; m_emit = 0; } else if (m_emit == 0 && !m_escape && Match(src, i, m_pat.m_line_end)) { m_comment = EType.None; m_emit = 0; // line comments don't include the line end } m_escape = src[i] == LineContinuation; break; } case EType.Block: { if (src[i] == '\0') { m_comment = EType.Block; m_emit = 0; } else if (m_emit == 0 && Match(src, i, m_pat.m_block_end)) { m_comment = EType.None; m_emit = m_pat.m_block_end.Length; } break; } default: { throw new Exception("Unknown comment state"); } } IsWithinComment = m_comment != EType.None || m_emit != 0; m_emit -= m_emit != 0 ? 1 : 0; return(IsWithinComment); }
bool IStringView.EndsWith(IStringView v, StringComparison sc) { return(EndsWith(v, sc)); }
public CopyToClipboardPopupMenuIcon(Context context, IStringView stringView) { _context = context; _stringView = stringView; }
public bool Contains(IStringView s, StringComparison ordinal = StringComparison.Ordinal) { return(IndexOf(s) != -1); }
int IStringView.LastIndexOf(IStringView other, StringComparison sc) { return(LastIndexOf(other, sc)); }
bool IStringView.Contains(IStringView s, StringComparison ordinal) { return(Contains(s, ordinal)); }