Пример #1
0
        //------------------------------------------------------------
        // ???
        //public static int Balance(this StringView str, int indexOfOpeningBracketOrQuote) {
        //  var literalStatus = new LiteralStatus();
        //  for (int i = indexOfOpeningBracketOrQuote; i != str.Length; ++i) {
        //    if (str[i].IsBracket()) {
        //      literalStatus.PushBracket(str[i].GetBracketType());
        //      if (literalStatus.Effective) {
        //        return i + 1;
        //      }
        //    }
        //    else if (str[i].IsQuote()) {
        //      literalStatus.PushQuote(str[i].GetQuoteType());
        //      if (literalStatus.Effective) {
        //        return i + 1;
        //      }
        //    }
        //  }
        //  return str.Length;
        //}
        //============================================================

        public static StringView StripBoundaryWhitespaces(this StringView str)
        {
            int p = str.GetFirstSpaceBoundary();
            int n = str.GetLastSpaceBoundary();

            return(str.GetSubView(p, n));
        }
Пример #2
0
        //============================================================
        public static IEnumerable <StringView> GetWords(this StringView str, Predicate <char> whitespacePred)
        {
            int p = str.GetFirstSpaceBoundary();
            int n = str.GetLastSpaceBoundary();

            // if all are whitespaces
            if (p > n)
            {
                yield break;
            }

            for (int i = p; i != n; ++i)
            {
                if (str[i] == ' ')
                {
                    yield return(str.GetSubView(p, i));

                    p = i = str.FindFirst((char c) => c != ' ', i);
                }
            }
            yield return(str.GetSubView(p, n));
        }
Пример #3
0
 public static StringView WithoutOutermostSpaces(this StringView str)
 {
     return(str.GetSubView(str.GetFirstSpaceBoundary(), str.GetLastSpaceBoundary()));
 }