예제 #1
0
파일: Regex.cs 프로젝트: AirKuma/AirProject
        //------------------------------------------------------------
        // ???
        //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
파일: Regex.cs 프로젝트: AirKuma/AirProject
        //============================================================
        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
파일: Regex.cs 프로젝트: AirKuma/AirProject
 public static StringView WithoutOutermostSpaces(this StringView str)
 {
     return(str.GetSubView(str.GetFirstSpaceBoundary(), str.GetLastSpaceBoundary()));
 }