public bool Equals(Substring theOther)
 {
     return
         (length == theOther.length
              ? string.Compare(source, start, theOther.source, theOther.start, length) == 0
              : false);
 }
Example #2
0
 string FromPosition(Substring start) {
     var from = start.Truncate(current).ToString();
     var result = new StringBuilder();
     for (var index = 0; index < from.Length; index++) {
         if (index < from.Length - 1 && from[index] == '\\') index++;
         result.Append(from[index]);
     }
     return result.ToString();
 }
Example #3
0
 static string GetTag(Substring theInput)
 {
     var tag = new StringBuilder();
     int i = 0;
     if (theInput[0] == '/') tag.Append(theInput[i++]);
     while (i < theInput.Length && char.IsLetter(theInput[i])) {
         tag.Append(theInput[i++]);
     }
     return tag.ToString().ToLower();
 }
Example #4
0
 static string GetTag(Substring theInput) {
     var current = theInput;
     var tag = new StringBuilder();
     if (theInput[0] == '/') {
         tag.Append('/');
         current = current.Skip(1);
     }
     while (!current.IsEmpty && char.IsLetter(current[0])) {
         tag.Append(current[0]);
         current = current.Skip(1);
     }
     return tag.ToString().ToLower();
 }
Example #5
0
 public void MoveNext() {
     current = current.After;
     if (current.AtEnd) {
         return;
     }
     if (current.StartsWith("\\")) {
         Type = CharacterType.Letter;
         current = current.Skip(1).Truncate(1);
     }
     else if (current.StartsWith("[\n")) {
         Type = CharacterType.BeginCell;
         current = current.Truncate(2);
     }
     else if (current.StartsWith("\n]")) {
         Type = CharacterType.EndCell;
         current = current.Truncate(2);
     }
     else if (current.StartsWith("\n")) {
         Type = CharacterType.Newline;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("\"") || current.StartsWith("'")) {
         Type = CharacterType.Quote;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("|")) {
         Type = CharacterType.Separator;
         current = current.Truncate(1);
     }
     else if (current.StartsWith(TextStoryTestBegin, StringComparison.OrdinalIgnoreCase)) {
         Type = CharacterType.BeginTest;
         current = current.Truncate(5);
     }
     else if (current.StartsWith("@test", StringComparison.OrdinalIgnoreCase)) {
         Type = CharacterType.EndTest;
         current = current.Truncate(5);
     }
     else if (char.IsWhiteSpace(current[0])) {
         Type = CharacterType.WhiteSpace;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("<br", StringComparison.OrdinalIgnoreCase)
         && current.Contains(">")) {
         Type = CharacterType.Newline;
         current = current.TruncateAfter(">");
     }
     else {
         Type = CharacterType.Letter;
         current = current.Truncate(1);
     }
 }
            public void Append(Substring theInput)
            {
                var current = theInput;

                while (!current.IsEmpty)
                {
                    var input = current[0];
                    if (isStandard && input != '\u00a0' && char.IsWhiteSpace(input))
                    {
                        if (!myWhitespace)
                        {
                            myText.Append(' ');
                            myLastTag = myLastTag + " ";
                        }
                        myWhitespace = true;
                    }
                    else
                    {
                        switch (input)
                        {
                        case '\u201c':
                            input = '"'; break;

                        case '\u201d':
                            input = '"'; break;

                        case '\u2018':
                            input = '\''; break;

                        case '\u2019':
                            input = '\''; break;

                        case '\u00a0':
                            input = ' '; break;

                        case '&':
                            if (current.ContainsAt(1, "nbsp;"))
                            {
                                input   = ' ';
                                current = current.Skip(5);
                            }
                            break;
                        }
                        myText.Append(input);
                        myWhitespace = false;
                        myLastTag    = string.Empty;
                    }
                    current = current.Skip(1);
                }
            }
        string FromPosition(Substring start)
        {
            var from   = start.Truncate(current).ToString();
            var result = new StringBuilder();

            for (var index = 0; index < from.Length; index++)
            {
                if (index < from.Length - 1 && from[index] == '\\')
                {
                    index++;
                }
                result.Append(from[index]);
            }
            return(result.ToString());
        }
Example #8
0
        static string GetTag(Substring theInput)
        {
            var tag = new StringBuilder();
            int i   = 0;

            if (theInput[0] == '/')
            {
                tag.Append(theInput[i++]);
            }
            while (i < theInput.Length && char.IsLetter(theInput[i]))
            {
                tag.Append(theInput[i++]);
            }
            return(tag.ToString().ToLower());
        }
Example #9
0
            public void Append(Substring theInput)
            {
                for (int i = 0; i < theInput.Length; i++)
                {
                    char input = theInput[i];
                    if (isStandard && input != '\u00a0' && char.IsWhiteSpace(input))
                    {
                        if (!myWhitespace)
                        {
                            myText.Append(' ');
                            myLastTag = myLastTag + " ";
                        }
                        myWhitespace = true;
                    }
                    else
                    {
                        switch (input)
                        {
                        case '\u201c':
                            input = '"'; break;

                        case '\u201d':
                            input = '"'; break;

                        case '\u2018':
                            input = '\''; break;

                        case '\u2019':
                            input = '\''; break;

                        case '\u00a0':
                            input = ' '; break;

                        case '&':
                            if (theInput.Contains(i + 1, "nbsp;"))
                            {
                                input = ' ';
                                i    += 5;
                            }
                            break;
                        }
                        myText.Append(input);
                        myWhitespace = false;
                        myLastTag    = string.Empty;
                    }
                }
            }
        static string GetTag(Substring theInput)
        {
            var current = theInput;
            var tag     = new StringBuilder();

            if (theInput[0] == '/')
            {
                tag.Append('/');
                current = current.Skip(1);
            }
            while (!current.IsEmpty && char.IsLetter(current[0]))
            {
                tag.Append(current[0]);
                current = current.Skip(1);
            }
            return(tag.ToString().ToLower());
        }
Example #11
0
        public void FindTokenPair(string theFirstToken, string theSecondToken, TokenBodyFilter theFilter)
        {
            Leader  = Substring.Empty;
            Body    = Substring.Empty;
            Element = Substring.Empty;
            if (myPrevious >= myInput.Length)
            {
                return;
            }
            int first, second = 0;

            for (first = myPrevious; first < myInput.Length; first = second + theSecondToken.Length)
            {
                first  = Find(myInput, theFirstToken, first);
                second = Find(myInput, theSecondToken, first + theFirstToken.Length + 1);
                if (second == myInput.Length)
                {
                    first = second;
                    break;
                }
                int body = first + theFirstToken.Length;
                if (second <= body)
                {
                    continue;
                }
                Body    = new Substring(myInput, body, second - body);
                Element = new Substring(myInput, first, second - first + theSecondToken.Length);
                if (theFilter(Body))
                {
                    break;
                }
            }
            if (first > myPrevious)
            {
                Leader = new Substring(myInput, myPrevious, first - myPrevious);
            }
            myPrevious = second + theSecondToken.Length;
        }
 public Substring Truncate(Substring next)
 {
     return(new Substring(source, start, next.start - start));
 }
Example #13
0
 public Substring Truncate(Substring next) { return new Substring(source, start, next.start - start); }
Example #14
0
 static bool FilterString(Substring theTokenBody) {
     return !ourFilterString.Equals(theTokenBody);
 }
Example #15
0
 public void FindTokenPairFilter(string theFirstToken, string theSecondToken, string theFilterString) {
     ourFilterString = new Substring(theFilterString);
     myScanner.FindTokenPair(theFirstToken, theSecondToken, ourFilter);
 }
Example #16
0
 public void Append(Substring theInput) {
     var current = theInput;
     while (!current.IsEmpty) {
         var input = current[0];
         if (isStandard && input != '\u00a0' && char.IsWhiteSpace(input)) {
             if (!myWhitespace) {
                 myText.Append(' ');
                 myLastTag = myLastTag + " ";
             }
             myWhitespace = true;
         }
         else {
             switch (input) {
                 case '\u201c':
                     input = '"'; break;
                 case '\u201d':
                     input = '"'; break;
                 case '\u2018':
                     input = '\''; break;
                 case '\u2019':
                     input = '\''; break;
                 case '\u00a0':
                     input = ' '; break;
                 case '&':
                     if (current.ContainsAt(1, "nbsp;")) {
                         input = ' ';
                         current = current.Skip(5);
                     }
                     break;
             }
             myText.Append(input);
             myWhitespace = false;
             myLastTag = string.Empty;
         }
         current = current.Skip(1);
     }
 }
Example #17
0
 public bool Equals(Substring theOther) {
     return
         (length == theOther.length
              ? string.Compare(source, start, theOther.source, theOther.start, length) == 0
              : false);
 }
Example #18
0
 static bool NullTokenBodyFilter(Substring theTokenBody)
 {
     return(true);
 }
Example #19
0
 static bool IsValidTag(Substring theBody)
 {
     return(theBody[0] == '/' || char.IsLetter(theBody[0]));
 }
 public Characters(string input)
 {
     current = new Substring(input.Replace("\r", string.Empty), 0, 0);
     MoveNext();
 }
Example #21
0
 public void Append(Substring theInput)
 {
     for (int i = 0; i < theInput.Length; i++) {
         char input = theInput[i];
         if (isStandard && input != '\u00a0' && char.IsWhiteSpace(input)) {
             if (!myWhitespace) {
                 myText.Append(' ');
                 myLastTag = myLastTag + " ";
             }
             myWhitespace = true;
         }
         else {
             switch (input) {
                 case '\u201c':
                     input = '"'; break;
                 case '\u201d':
                     input = '"'; break;
                 case '\u2018':
                     input = '\''; break;
                 case '\u2019':
                     input = '\''; break;
                 case '\u00a0':
                     input = ' '; break;
                 case '&':
                     if (theInput.Contains(i + 1, "nbsp;")) {
                         input = ' ';
                         i += 5;
                     }
                     break;
             }
             myText.Append(input);
             myWhitespace = false;
             myLastTag = string.Empty;
         }
     }
 }
 public void MoveNext()
 {
     current = current.After;
     if (current.AtEnd)
     {
         return;
     }
     if (current.StartsWith("\\"))
     {
         Type    = CharacterType.Letter;
         current = current.Skip(1).Truncate(1);
     }
     else if (current.StartsWith("[\n"))
     {
         Type    = CharacterType.BeginCell;
         current = current.Truncate(2);
     }
     else if (current.StartsWith("\n]"))
     {
         Type    = CharacterType.EndCell;
         current = current.Truncate(2);
     }
     else if (current.StartsWith("\n"))
     {
         Type    = CharacterType.Newline;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("\"") || current.StartsWith("'"))
     {
         Type    = CharacterType.Quote;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("|"))
     {
         Type    = CharacterType.Separator;
         current = current.Truncate(1);
     }
     else if (current.StartsWith(TextStoryTestBegin, StringComparison.OrdinalIgnoreCase))
     {
         Type    = CharacterType.BeginTest;
         current = current.Truncate(5);
     }
     else if (current.StartsWith("@test", StringComparison.OrdinalIgnoreCase))
     {
         Type    = CharacterType.EndTest;
         current = current.Truncate(5);
     }
     else if (char.IsWhiteSpace(current[0]))
     {
         Type    = CharacterType.WhiteSpace;
         current = current.Truncate(1);
     }
     else if (current.StartsWith("<br", StringComparison.OrdinalIgnoreCase) &&
              current.Contains(">"))
     {
         Type    = CharacterType.Newline;
         current = current.TruncateAfter(">");
     }
     else
     {
         Type    = CharacterType.Letter;
         current = current.Truncate(1);
     }
 }
Example #23
0
 static bool IsValidTag(Substring theBody)
 {
     return theBody[0] == '/' || char.IsLetter(theBody[0]);
 }
Example #24
0
 public Characters(string input) {
     current = new Substring(input.Replace("\r", string.Empty), 0, 0);
     MoveNext();
 }