public static string Escape(string text, Encoder encoder, EscapeMode escapeMode) { if (encoder == null) { throw new ArgumentNullException("encoder"); } // TODO Might use Encoding instead of encoder for parameter because of the // needed API : Encoding.Clone StringBuilder accum = new StringBuilder(text.Length * 2); IDictionary <int, string> map = escapeMode.GetMap(); for (int pos = 0; pos < text.Length; pos++) { // TODO: char doesnt cover all UTF32 codepoints // Need StringInfo.GetTextElementEnumerator(text) char c = text[pos]; if (map.ContainsKey(c)) { accum.Append('&').Append(map.GetValueOrDefault(c)).Append(';'); } else if (true) // UNDONE encoder.canEncode(c)) { accum.Append(c); } else { accum.Append("&#").Append((int)c).Append(';'); } } return(accum.ToString()); }
private void HandleButton(Button button) { if (isOn) { if (IsTurningOff(button)) { TurnOff(); } else { RestartTimerIfStateNotWaiting(); state = state.HandleButton(button, escapeMode); } } else { if (button == Buttons.Clear) { TurnOn(); } } escapeMode = new NoEscapeMode(); UpdateDisplay(); }
internal static string Escape(string @string, EscapeMode escapeMode, Encoding charset) { StringBuilder accum = new StringBuilder(@string.Length * 2); Escape(accum, @string, escapeMode, charset, false, false, false); return(accum.ToString()); }
public override State HandleButton(Button button, EscapeMode escapeMode) { if (button.Letter != null) { BottomStatus = ""; Display = $"STO * {button.Letter}"; var storedValue = calculator.Recall(button.Letter); calculator.Store(button.Letter, storedValue * output.ToDouble()); return(new WaitForDefault()); } else if (button == Buttons.Clear) { Display = output.ToString(); return(new DefaultState()); } else if (button == Buttons.Back) { return(new StoreState()); } else if (button == Buttons.Solve) { Display = $"STO * (i)"; return(new WaitForInvalidI()); } else { return(this); } }
public static string Escape(string s, Encoding encoding, EscapeMode escapeMode) { StringBuilder accum = new StringBuilder(s.Length * 2); Dictionary<char, string> map = escapeMode.GetMap(); for (int pos = 0; pos < s.Length; pos++) { char c = s[pos]; // To replicate this line from the original code: encoder.canEncode(c), we perform the following steps: byte[] unicodeBytes = Encoding.Unicode.GetBytes(c.ToString()); // Get the bytes by unicode. byte[] encodingBytes = Encoding.Convert(Encoding.Unicode, encoding, unicodeBytes); // Convert bytes into target encoding's bytes. char[] encodingChars = new char[encoding.GetCharCount(encodingBytes)]; encoding.GetChars(encodingBytes, 0, encodingBytes.Length, encodingChars, 0); // Convert target encoding bytes into chars. if (map.ContainsKey(c)) { accum.AppendFormat("&{0};", map[c]); } else if (encodingChars[0] == c) { // If the char resulting from the conversion matches the original one, we can understand that the encoding can encode this char. accum.Append(c); // If so, add it to the accumulator. } else { accum.AppendFormat("&#{0};", (int)c); } } return accum.ToString(); }
public static string Escape(string s, Encoding encoding, EscapeMode escapeMode) { StringBuilder accum = new StringBuilder(s.Length * 2); Dictionary <char, string> map = escapeMode.GetMap(); for (int pos = 0; pos < s.Length; pos++) { char c = s[pos]; // To replicate this line from the original code: encoder.canEncode(c), we perform the following steps: byte[] unicodeBytes = Encoding.Unicode.GetBytes(c.ToString()); // Get the bytes by unicode. byte[] encodingBytes = Encoding.Convert(Encoding.Unicode, encoding, unicodeBytes); // Convert bytes into target encoding's bytes. char[] encodingChars = new char[encoding.GetCharCount(encodingBytes)]; encoding.GetChars(encodingBytes, 0, encodingBytes.Length, encodingChars, 0); // Convert target encoding bytes into chars. if (map.ContainsKey(c)) { accum.AppendFormat("&{0};", map[c]); } else if (encodingChars[0] == c) { // If the char resulting from the conversion matches the original one, we can understand that the encoding can encode this char. accum.Append(c); // If so, add it to the accumulator. } else { accum.AppendFormat("&#{0};", (int)c); } } return(accum.ToString()); }
public override State HandleButton(Button button, EscapeMode escapeMode) { if (button == Buttons.Clear) { Display = output.ToString(); return(new DefaultState()); } else { return(new DefaultState().HandleButton(button, escapeMode)); } }
private static IDictionary <int, string> GetMap(this EscapeMode mode) { switch (mode) { case EscapeMode.Xhtml: return(xhtmlByVal); case EscapeMode.Base: return(baseByVal); case EscapeMode.Extended: default: return(fullByVal); } }
private static IDictionary<Utf32, string> GetMap(EscapeMode escapeMode) { switch (escapeMode) { case EscapeMode.Base: return baseByVal; case EscapeMode.Extended: return fullByVal; case EscapeMode.Xhtml: return xhtmlByVal; } throw new ArgumentException(); }
private static IDictionary <Utf32, string> GetMap(EscapeMode escapeMode) { switch (escapeMode) { case EscapeMode.Base: return(baseByVal); case EscapeMode.Extended: return(fullByVal); case EscapeMode.Xhtml: return(xhtmlByVal); } throw new ArgumentException(); }
public MainPageViewModel() { LeftArrowCommand = new Command(HandleLeftArrow, () => isOn); RightArrowCommand = new Command(HandleRightArrow, () => isOn); ButtonCommand = new Command <Button>(HandleButton, IsButtonEnabled); timer = new Timer(TimerElapsed); State.Timer = timer; State.Buttons = Buttons; DefaultState.AssignButtonOperations(); escapeMode = new NoEscapeMode(); state = new DefaultState(); UpdateDisplay(); }
public override State HandleButton(Button button, EscapeMode escapeMode) { switch (escapeMode) { case NoEscapeMode mode: return(button.DefaultOperation()); case LeftEscapeMode mode: return(button.LeftOperation()); case RightEscapeMode mode: return(button.RightOperation()); default: throw new InvalidOperationException("Unexpected escape mode"); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Semmle.Autobuild.CommandBuilder"/> class. /// </summary> /// <param name="workingDirectory">The working directory (<code>null</code> for current directory).</param> /// <param name="environment">Additional environment variables.</param> public CommandBuilder(IBuildActions actions, string workingDirectory = null, IDictionary <string, string> environment = null) { arguments = new StringBuilder(); if (actions.IsWindows()) { executable = "cmd.exe"; arguments.Append("/C"); escapingMode = EscapeMode.Cmd; } else { escapingMode = EscapeMode.Process; } firstCommand = true; this.workingDirectory = workingDirectory; this.environment = environment; }
public static string UnEscape(EscapeMode mode, string text) { switch (mode) { case EscapeMode.None: return(text); case EscapeMode.CSharp: return(FromCSharpFormat(text)); case EscapeMode.CSharpVerbatim: return(FromCSharpVerbatimFormat(text)); case EscapeMode.Xml: return(FromXml(text)); default: throw new Exception("Unknown string escaping mode '" + mode.ToString() + "'"); } }
public static string Escape(string s, EscapeMode mode) { if (mode == EscapeMode.noEsc) { return(s); } if (mode == EscapeMode.blankEsc) { return(Os.escapeBlank(s)); } if (mode == EscapeMode.paramEsc) { return(Os.escapeParam(s)); } if (mode == EscapeMode.backslashed) { return(Os.winInternal(s)); } return(s); }
public override State HandleButton(Button button, EscapeMode escapeMode) { if (button.Letter != null) { BottomStatus = ""; Display = $"RCL {button.Letter}"; var storedValue = calculator.Recall(button.Letter); output.FromDouble(storedValue); return(new WaitForDefault()); } else if (button == Buttons.Divide) { return(new RecallDivide()); } else if (button == Buttons.Multiply) { return(new RecallMultiply()); } else if (button == Buttons.Subtract) { return(new RecallSubtract()); } else if (button == Buttons.Add) { return(new RecallAdd()); } else if (button == Buttons.Clear || button == Buttons.Back) { Display = output.ToString(); return(new DefaultState()); } else if (button == Buttons.Solve) { Display = $"RCL (i)"; return(new WaitForInvalidI()); } else { return(this); } }
public override State HandleButton(Button button, EscapeMode escapeMode) { if (button.Letter != null) { BottomStatus = ""; Display = $"STO {button.Letter}"; calculator.Store(button.Letter, output.ToDouble()); return(new WaitForDefault()); } else if (button == Buttons.Divide) { return(new StoreDivide()); } else if (button == Buttons.Multiply) { return(new StoreMultiply()); } else if (button == Buttons.Subtract) { return(new StoreSubtract()); } else if (button == Buttons.Add) { return(new StoreAdd()); } else if (button == Buttons.Clear || button == Buttons.Back) { Display = output.ToString(); return(new DefaultState()); } else if (button == Buttons.Solve) { Display = $"STO (i)"; return(new WaitForInvalidI()); } else { return(this); } }
/// <summary> /// This function returns the string escaped according to the supplied mode. /// </summary> /// <param name="value">The string to escape.</param> /// <param name="mode">The escape mode.</param> /// <returns>An escaped string.</returns> public static string Escape(string value, EscapeMode mode) { if (value == null) throw new ArgumentNullException("value", "The string must be supplied."); if (mode < EscapeMode.None || mode > EscapeMode.Url) throw new ArgumentOutOfRangeException("mode", "The supplied mode is not a recognized escape mode."); switch (mode) { case EscapeMode.Html: return HttpUtility.HtmlEncode(value); //Note - use of the JavaScript mode would prevent the use of embedded //carraige returns in the text to be alerted. Alerts require the //term "\\n" for carriage return, which would be converted to "\\\\n" //by this function. case EscapeMode.JavaScript: return value.Replace("\\", "\\\\").Replace("'", "\\'"); case EscapeMode.Url: return HttpUtility.UrlEncode(value); default: return value; } /* switch */ }
public override State HandleButton(Button button, EscapeMode escapeMode) { if (button.Letter != null) { BottomStatus = ""; Display = $"RCL / {button.Letter}"; var storedValue = calculator.Recall(button.Letter); if (storedValue == 0.0) { return(new DivideByZero()); } else { output.FromDouble(output.ToDouble() / storedValue); return(new WaitForDefault()); } } else if (button == Buttons.Clear) { Display = output.ToString(); return(new DefaultState()); } else if (button == Buttons.Back) { return(new RecallState()); } else if (button == Buttons.Solve) { Display = $"RCL - (i)"; return(new WaitForInvalidI()); } else { return(this); } }
/// <summary> /// Gets the words. /// </summary> /// <param name="input">The input.</param> /// <param name="groups">The groups.</param> /// <param name="escapeCharacter">The escape character.</param> /// <param name="mode">The mode.</param> /// <param name="wordSeparators">The word separators.</param> /// <returns></returns> public static IList <string> GetWords(string input, string[] groups, char escapeCharacter, EscapeMode mode, char[] wordSeparators) { if (input == null) { throw new ArgumentNullException("input"); } Dictionary <char, char> _groups = new Dictionary <char, char>(); if (groups != null) { foreach (string g in groups) { if (g.Length != 2) { throw new ArgumentException("Groups must be list of strings with 2 characters"); } else { _groups.Add(g[0], g[1]); } } } if (wordSeparators != null && wordSeparators.Length == 0) { wordSeparators = null; } List <string> words = new List <string>(); char groupEnd = '\0'; bool inGroup = false; int start = -1; for (int i = 0; i < input.Length; i++) { char c = input[i]; bool hasNext = i + 1 < input.Length; bool isSeparator = IsSeparator(c, wordSeparators); if (isSeparator && !inGroup) { if (hasNext && (mode == EscapeMode.DoubleItem) && input[i + 1] == c) { if (start < 0) { start = i; } i++; continue; } if (start >= 0) { words.Add(UnEscape(input.Substring(start, i - start), _groups, groups, escapeCharacter, mode, wordSeparators)); start = -1; continue; } } if (start < 0) { start = i; } if (!inGroup && _groups.TryGetValue(input[i], out groupEnd)) { inGroup = true; } else if (inGroup && input[i] == groupEnd) { if ((mode == EscapeMode.DoubleItem) && hasNext && input[i + 1] == groupEnd) { // Escaped end of group; will be removed in UnEscape i++; continue; } else { inGroup = false; } } if ((c == escapeCharacter) && hasNext) { switch (mode) { case EscapeMode.EscapeCharacter: i++; // Escaped character; will be removed in UnEscape continue; case EscapeMode.EscapeGroupOnly: char cn = input[i + 1]; if (inGroup ? (cn == groupEnd) : _groups.ContainsKey(cn)) { i++; // Escaped character; will be removed in UnEscape } // else: Just ignore the escape break; } } } if (start >= 0) { words.Add(UnEscape(input.Substring(start), _groups, groups, escapeCharacter, mode, wordSeparators)); } return(words); }
// this method is ugly, and does a lot. but other breakups cause rescanning and stringbuilder generations internal static void Escape(StringBuilder accum, string @string, EscapeMode escapeMode, Encoding charset, bool inAttribute, bool normaliseWhite, bool stripLeadingWhite) { bool lastWasWhite = false; bool reachedNonWhite = false; CharsetEncoder encoder = new CharsetEncoder(charset); IDictionary <Utf32, string> map = GetMap(escapeMode); int length = @string.Length; char c = default(char); for (int offset = 0; offset < length; offset += (char.IsSurrogate(c) ? 2 : 1)) { c = @string[offset]; if (normaliseWhite) { if (StringUtil.IsWhitespace(c)) { if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite) { continue; } accum.Append(' '); lastWasWhite = true; continue; } else { lastWasWhite = false; reachedNonWhite = true; } } if (!char.IsSurrogate(c)) { // split implementation for efficiency on single char common case (saves creating strings, char[]): switch (c) { case '&': // html specific and required escapes: accum.Append("&"); continue; case '\u00A0': if (escapeMode != EscapeMode.Xhtml) { accum.Append(" "); } else { accum.Append(c); } continue; case '<': if (!inAttribute) { accum.Append("<"); } else { accum.Append(c); } continue; case '>': if (!inAttribute) { accum.Append(">"); } else { accum.Append(c); } continue; case '"': if (inAttribute) { accum.Append("""); } else { accum.Append(c); } continue; default: break; } } var chars = char.IsSurrogate(c) ? new[] { c, @string[offset + 1] } : new[] { c }; if (encoder.CanEncode(chars)) { accum.Append(chars); continue; } Utf32 codePoint = char.ConvertToUtf32(@string, offset); if (map.ContainsKey(codePoint)) { accum.Append('&').Append(map[codePoint]).Append(';'); } else { accum.Append("&#x").AppendFormat("{0:x}", codePoint).Append(';'); } } }
public override State HandleButton(Button button, EscapeMode escapeMode) { return(this); }
internal static string Escape(string @string, EscapeMode escapeMode, Encoding charset) { StringBuilder accum = new StringBuilder(@string.Length * 2); Escape(accum, @string, escapeMode, charset, false, false, false); return accum.ToString(); }
// this method is ugly, and does a lot. but other breakups cause rescanning and stringbuilder generations internal static void Escape(StringBuilder accum, string @string, EscapeMode escapeMode, Encoding charset, bool inAttribute, bool normaliseWhite, bool stripLeadingWhite) { bool lastWasWhite = false; bool reachedNonWhite = false; CharsetEncoder encoder = new CharsetEncoder(charset); IDictionary<Utf32, string> map = GetMap(escapeMode); int length = @string.Length; char c = default(char); for (int offset = 0; offset < length; offset += (char.IsSurrogate(c) ? 2 : 1)) { c = @string[offset]; if (normaliseWhite) { if (StringUtil.IsWhitespace(c)) { if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite) { continue; } accum.Append(' '); lastWasWhite = true; continue; } else { lastWasWhite = false; reachedNonWhite = true; } } if (!char.IsSurrogate(c)) { // split implementation for efficiency on single char common case (saves creating strings, char[]): switch (c) { case '&': // html specific and required escapes: accum.Append("&"); continue; case '\u00A0': if (escapeMode != EscapeMode.Xhtml) { accum.Append(" "); } else { accum.Append(c); } continue; case '<': if (!inAttribute) { accum.Append("<"); } else { accum.Append(c); } continue; case '>': if (!inAttribute) { accum.Append(">"); } else { accum.Append(c); } continue; case '"': if (inAttribute) { accum.Append("""); } else { accum.Append(c); } continue; default: break; } } var chars = char.IsSurrogate(c) ? new[] { c, @string[offset + 1] } : new[] { c }; if (encoder.CanEncode(chars)) { accum.Append(chars); continue; } Utf32 codePoint = char.ConvertToUtf32(@string, offset); if (map.ContainsKey(codePoint)) { accum.Append('&').Append(map[codePoint]).Append(';'); } else { accum.Append("&#x").AppendFormat("{0:x}", codePoint).Append(';'); } } }
/// <summary> /// Replace escape sequences strings by sequences. /// I.e. "\\n" -> "\n", "\\"" -> "\"" etc. /// </summary> /// <returns> /// Unescaped string /// </returns> /// <param name='mode'> /// Unescaping mode /// </param> /// <param name='text'> /// Text to process. /// </param> /// <exception cref='Exception'> /// Throw an error if escaping mode is not supported. /// </exception> public static string UnEscape(EscapeMode mode, string text) { switch (mode) { case EscapeMode.None: return text; case EscapeMode.CSharp: return FromCSharpFormat (text); case EscapeMode.CSharpVerbatim: return FromCSharpVerbatimFormat (text); case EscapeMode.Xml: return FromXml (text); default: throw new Exception ("Unknown string escaping mode '" + mode.ToString () + "'"); } }
public ObjectList ParseGeniObjectList(string objectListString) { ObjectList rootObject = new ObjectList(); ObjectList currentObject = AddChild(rootObject); //int cnt = 0; string tTag = ""; string tValue = ""; //bool skipNextQuotation = false; EscapeMode escapeMode = EscapeMode.Null; string escapeString = ""; if (printDecode) { trace.TraceInformation("ParseGeniObjectList({0})", objectListString.Length); trace.TraceInformation("**********************************************************-start"); trace.TraceInformation(objectListString); trace.TraceInformation("**********************************************************-end"); } for (int cnt = 0; cnt < objectListString.Length; cnt++) { char ch = objectListString[cnt]; //trace.TraceInformation("{0}, char:{1} ", currentObject, ch); switch (currentObject.parserState) { case ObjectParserState.Null: if (ch == '{') { //ObjectList child = new ObjectList(); //child.SetParent(currentObject); currentObject = AddChild(currentObject); //currentObject = child; //currentObject.parserState = ObjectParserState.TagStart; } else if (ch == ',') { //ObjectList sibling = new ObjectList(); //sibling.SetParent(currentObject.parent); if (currentObject.parent != null) { currentObject = AddChild(currentObject.parent); } else { trace.TraceInformation("No Parent! curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } //currentObject = sibling; //currentObject.parserState = ObjectParserState.TagStart; } else if (ch == '"') { currentObject.parserState = ObjectParserState.Tag; } else if ((ch == '}') || (ch == ']')) { if (currentObject.parent != null) { //trace.TraceInformation("<==ToParent:" + currentObject.level + "char:" + cnt + "/" + objectListString.Length); currentObject = currentObject.parent; } else { trace.TraceInformation("No Parent! curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } } else { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; case ObjectParserState.TagStart: if (ch == '"') { currentObject.parserState = ObjectParserState.Tag; } else { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; case ObjectParserState.Tag: if (ch == '"') { currentObject.parserState = ObjectParserState.TagEnd; } else { tTag += ch; } break; case ObjectParserState.TagEnd: if (ch == ':') { currentObject.SetTag(tTag); tTag = ""; currentObject.parserState = ObjectParserState.Assign; } else { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; case ObjectParserState.Assign: if (ch == '"') { currentObject.parserState = ObjectParserState.ValueQuoted; } else if (ch == '{') { //ObjectList child = new ObjectList(); //child.SetParent(currentObject); currentObject.parserState = ObjectParserState.Null; currentObject = AddChild(currentObject); //currentObject = child; // } else if (ch == '[') { //ObjectList child = new ObjectList(); currentObject.parserState = ObjectParserState.Null; //child.SetParent(currentObject); currentObject = AddChild(currentObject); //currentObject = child; currentObject.parserState = ObjectParserState.Assign; currentObject.valueList = true; } else { currentObject.parserState = ObjectParserState.Value; tValue += ch; } break; case ObjectParserState.ValueQuotedStart: if (ch == '"') { currentObject.parserState = ObjectParserState.ValueQuoted; } else { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; case ObjectParserState.ValueQuoted: if (escapeMode != EscapeMode.Null) { if (escapeMode == EscapeMode.UnknownYet) { switch (ch) { case '"': escapeMode = EscapeMode.Null; tValue += ch; break; case 'u': escapeMode = EscapeMode.HexNumerical; escapeString = ""; break; } } else if (escapeMode == EscapeMode.HexNumerical) { if (escapeString.Length < 4) { escapeString += ch; } if (escapeString.Length == 4) { int charValue = 0; for (int i = 0; i < 4; i++) { charValue = (charValue << 4) + CharToHex(escapeString[i]); } tValue += (char)charValue; escapeMode = EscapeMode.Null; } } } else if (ch == '"') { currentObject.SetValue(tValue); tValue = ""; currentObject.parserState = ObjectParserState.ValueQuotedEnd; } else if (ch == '\\') { escapeMode = EscapeMode.UnknownYet; } else { tValue += ch; } break; case ObjectParserState.ValueQuotedEnd: if (ch == ',') { bool listMode = currentObject.valueList; //ObjectList sibling = new ObjectList(); //sibling.SetParent(currentObject.parent); currentObject.parserState = ObjectParserState.Null; currentObject = AddChild(currentObject.parent); //currentObject.parserState = ObjectParserState.Null; //currentObject = sibling; if (listMode) { currentObject.valueList = true; currentObject.parserState = ObjectParserState.Assign; } } else if ((ch == '}') || (ch == ']')) { if (currentObject.parent != null) { currentObject.parserState = ObjectParserState.Null; //trace.TraceInformation("<==ToParent:" + currentObject.level); currentObject = currentObject.parent; } else { trace.TraceInformation("No Parent! curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } } else { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; case ObjectParserState.Value: if (ch == ',') { currentObject.SetValue(tValue); tValue = ""; //ObjectList sibling = new ObjectList(); //sibling.SetParent(currentObject.parent); currentObject.parserState = ObjectParserState.Null; currentObject = AddChild(currentObject.parent); //currentObject.parserState = ObjectParserState.Null; //currentObject = sibling; } else if (ch == '}') { currentObject.SetValue(tValue); tValue = ""; currentObject.parserState = ObjectParserState.Null; //ObjectList sibling = new ObjectList(); //sibling.SetParent(currentObject.parent); //trace.TraceInformation("<==ToParent:" + currentObject.level + "char:" + cnt + "/" + objectListString.Length); currentObject = currentObject.parent; //currentObject.parserState = ObjectParserState.Null; //currentObject = sibling; } else { tValue += ch; } break; default: { trace.TraceInformation("Unhandled character curr:{0}, state:{1}, char:{2} ", currentObject, currentObject.parserState, ch); } break; } } if (printDecode) { trace.TraceInformation("currentObj:" + currentObject); trace.TraceInformation("rootObj:" + rootObject); rootObject.PrintFull(); } return(rootObject); }
static string UnEscape(string p, Dictionary <char, char> _groups, string[] groups, char escapeCharacter, EscapeMode mode, char[] wordSeparators) { switch (mode) { case EscapeMode.DoubleItem: { if (wordSeparators != null) { foreach (char c in wordSeparators) { string cs = c.ToString(); p = p.Replace(cs + cs, cs); } } else { for (int i = 0; i < p.Length; i++) { if (char.IsWhiteSpace(p, i)) { int j = i + 1; while (j < p.Length && char.IsWhiteSpace(p, j)) { j++; } p = p.Remove(i + 1, j - i - 1); } } } } break; case EscapeMode.EscapeCharacter: { for (int i = 0; i < p.Length; i++) { if (p[i] == escapeCharacter) { p = p.Remove(i, 0); // We automatically skip the next character } } } break; case EscapeMode.EscapeGroupOnly: { GC.KeepAlive(_groups); for (int i = 0; i < p.Length; i++) { if (p[i] == escapeCharacter && i + 1 < p.Length) { bool found = false; char c = p[i + 1]; foreach (string s in groups) { if (s[1] == c) { found = true; break; } } if (found) { p = p.Remove(i, 0); } // otherwise we just leave the escape and continue } } } break; case EscapeMode.None: break; default: throw new InvalidOperationException(); } return(p); }
private void HandleRightArrow() { RestartTimerIfStateNotWaiting(); escapeMode = escapeMode.HandleRightArrow(); TopStatus = EscapeMode.TopStatus; }