Esempio n. 1
0
 public static SubString ToSubString(this SubString value, int begin = 0, int count = int.MaxValue / 2)
 {
     return(new SubString(value, begin, count));
 }
Esempio n. 2
0
        public static IEnumerable <SubString> ReadLines(this SubString subString)
        {
            var baseString = subString.BaseString;
            var begin      = subString.Begin;
            var end        = subString.End;

            var beginLine = begin;
            var count     = 0;

            var state = ParseLineState.NewLine;

            for (var iter = begin; iter < end; ++iter)
            {
                var ch = baseString[iter];

                switch (state)
                {
                case ParseLineState.ConsumedCR:
                    yield return(new SubString(baseString, beginLine, count));

                    switch (ch)
                    {
                    case '\r':
                        beginLine = iter;
                        count     = 0;
                        state     = ParseLineState.ConsumedCR;
                        break;

                    case '\n':
                        state = ParseLineState.NewLine;
                        break;

                    default:
                        beginLine = iter;
                        count     = 1;
                        state     = ParseLineState.Inline;
                        break;
                    }

                    break;

                case ParseLineState.NewLine:
                    beginLine = iter;
                    count     = 0;
                    switch (ch)
                    {
                    case '\r':
                        state = ParseLineState.ConsumedCR;
                        break;

                    case '\n':
                        yield return(new SubString(baseString, beginLine, count));

                        state = ParseLineState.NewLine;
                        break;

                    default:
                        state = ParseLineState.Inline;
                        ++count;
                        break;
                    }
                    break;

                case ParseLineState.Inline:
                default:
                    switch (ch)
                    {
                    case '\r':
                        state = ParseLineState.ConsumedCR;
                        break;

                    case '\n':
                        yield return(new SubString(baseString, beginLine, count));

                        state = ParseLineState.NewLine;
                        break;

                    default:
                        ++count;
                        break;
                    }
                    break;
                }
            }

            switch (state)
            {
            case ParseLineState.NewLine:
                yield return(new SubString(baseString, 0, 0));

                break;

            case ParseLineState.ConsumedCR:
                yield return(new SubString(baseString, beginLine, count));

                yield return(new SubString(baseString, 0, 0));

                break;

            case ParseLineState.Inline:
            default:
                yield return(new SubString(baseString, beginLine, count));

                break;
            }
        }
Esempio n. 3
0
 public static void AppendSubString(this StringBuilder sb, SubString ss)
 {
     sb.Append(ss.BaseString, ss.Begin, ss.Length);
 }