public CaretSeparatedText(string Path) { int ID = 1; string UnfinishedString = ""; bool SplitString = false; foreach (string CaretString in File.ReadLines(Path)) { if (!CaretString.Contains("^")) //Comments { continue; } if (CaretString.EndsWith("^", StringComparison.CurrentCultureIgnoreCase)) { m_Strings.Add(ID, SanitizeString(CaretString)); ID++; } else { UnfinishedString = SanitizeString(CaretString); SplitString = true; } if (SplitString) { if (CaretString.EndsWith("^")) { m_Strings.Add(ID, SanitizeString(UnfinishedString + CaretString)); ID++; SplitString = false; } else { UnfinishedString += CaretString; } continue; } } }
public CaretStringIterator(CaretString caretString) { _caretString = caretString; _currentIndex = 0; }
public Result Apply(CaretString text, bool autocomplete = false) { var interator = new CaretStringIterator(text); var affinity = 0; var extractedValue = string.Empty; var modifiedString = string.Empty; var modifiedCaretPosition = text.CaretPosition; var state = initialState; var beforeCaret = interator.BeforeCaret(); var character = interator.Next(); while (character.HasValue) { var next = state.Accept(character.Value); if (next != null) { state = next.State; modifiedString += next.Insert != null ? new String(next.Insert.Value, 1) : string.Empty; extractedValue += next.Value != null ? new String(next.Value.Value, 1) : string.Empty; if (next.Pass) { beforeCaret = interator.BeforeCaret(); character = interator.Next(); affinity += 1; } else { if (beforeCaret && next.Insert != null) { modifiedCaretPosition += 1; } affinity -= 1; } } else { if (interator.BeforeCaret()) { modifiedCaretPosition -= 1; } beforeCaret = interator.BeforeCaret(); character = interator.Next(); affinity -= 1; } } Next nextAC; while (autocomplete && beforeCaret && (nextAC = state.Autocomplete()) != null) { state = nextAC.State; modifiedString += nextAC.Insert.HasValue ? new string(nextAC.Insert.Value, 1) : string.Empty; extractedValue += nextAC.Value.HasValue ? new string(nextAC.Value.Value, 1) : string.Empty; if (nextAC.Insert.HasValue) { modifiedCaretPosition += 1; } } return(new Result { FormattedText = new CaretString(modifiedString, modifiedCaretPosition), ExtractedValue = extractedValue, Affinity = affinity, Complete = NoMandatoryCharactersLeftAfterState(state) }); }