Пример #1
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();
 }
Пример #2
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();
 }
Пример #3
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();
 }
Пример #4
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);
     }
 }
Пример #5
0
 static bool IsValidTag(Substring theBody)
 {
     return theBody[0] == '/' || char.IsLetter(theBody[0]);
 }
Пример #6
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;
         }
     }
 }
Пример #7
0
 static bool FilterString(Substring theTokenBody) {
     return !ourFilterString.Equals(theTokenBody);
 }
Пример #8
0
 public void FindTokenPairFilter(string theFirstToken, string theSecondToken, string theFilterString) {
     ourFilterString = new Substring(theFilterString);
     myScanner.FindTokenPair(theFirstToken, theSecondToken, ourFilter);
 }
Пример #9
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);
     }
 }
Пример #10
0
 public bool Equals(Substring theOther) {
     return
         (length == theOther.length
              ? string.Compare(source, start, theOther.source, theOther.start, length) == 0
              : false);
 }
Пример #11
0
 public Substring Truncate(Substring next) { return new Substring(source, start, next.start - start); }
Пример #12
0
 public Characters(string input) {
     current = new Substring(input.Replace("\r", string.Empty), 0, 0);
     MoveNext();
 }