char.IsWhiteSpace(char)

Here are the examples of the csharp api char.IsWhiteSpace(char) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1211 Examples 7

19 Source : CelesteNetUtils.cs
with MIT License
from 0x0ade

public static unsafe string Sanitize(this string? value, HashSet<char>? illegal = null, bool space = false) {
            const int buffer = 64;

            if (value.IsNullOrEmpty())
                return "";

            char[] sanitizedArray = sanitizedShared ?? new char[value.Length + buffer];
            if (sanitizedArray.Length < value.Length)
                sanitizedArray = new char[value.Length + buffer];
            sanitizedShared = sanitizedArray;

            fixed (char* sanitized = sanitizedArray)
            fixed (char* raw = value) {
                char* to = sanitized;
                char* last = (char*) IntPtr.Zero;
                char* from = raw;
                if (illegal != null && illegal.Count != 0) {
                    if (!space) {
                        for (int i = value.Length; i > 0; --i) {
                            char c = *from++;
                            if (illegal.Contains(c))
                                continue;
                            if (!EnglishFontCharsSet.Contains(c))
                                continue;
                            if (char.IsWhiteSpace(c))
                                continue;
                            else
                                last = to;
                            *to++ = c;
                        }
                    } else {
                        bool isStart = true;
                        for (int i = value.Length; i > 0; --i) {
                            char c = *from++;
                            if (illegal.Contains(c))
                                continue;
                            if (!EnglishFontCharsSet.Contains(c))
                                continue;
                            if (isStart && char.IsWhiteSpace(c))
                                continue;
                            else
                                last = to;
                            isStart = false;
                            *to++ = c;
                        }
                    }

                } else {
                     if (!space) {
                        for (int i = value.Length; i > 0; --i) {
                            char c = *from++;
                            if (!EnglishFontCharsSet.Contains(c))
                                continue;
                            if (char.IsWhiteSpace(c))
                                continue;
                            else
                                last = to;
                            *to++ = c;
                        }
                    } else {
                        bool isStart = true;
                        for (int i = value.Length; i > 0; --i) {
                            char c = *from++;
                            if (!EnglishFontCharsSet.Contains(c))
                                continue;
                            if (isStart && char.IsWhiteSpace(c))
                                continue;
                            else
                                last = to;
                            isStart = false;
                            *to++ = c;
                        }
                    }
                }

                if (last == (char*) IntPtr.Zero)
                    return "";

                return StringDedupeStaticContext.ToDedupedString(sanitized, (int) (last - sanitized) + 1);
            }
        }

19 Source : StringExtensions.cs
with GNU Lesser General Public License v3.0
from 0xC0000054

public static bool IsEmptyOrWhiteSpace(this string value)
        {
            if (value is null)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(value));
            }

            for (int i = 0; i < value.Length; i++)
            {
                if (!char.IsWhiteSpace(value[i]))
                {
                    return false;
                }
            }

            return true;
        }

19 Source : SourceDocumentProvider.cs
with MIT License
from 0xd4d

static bool IsPartial(string line, int startLine, int endLine, int startColumn, int endColumn, int lineNo) {
			if (lineNo != startLine)
				return false;

			int realStart = 0;
			while (realStart < line.Length) {
				if (!char.IsWhiteSpace(line[realStart]))
					break;
				realStart++;
			}
			int realEnd = line.Length;
			while (realEnd > 0) {
				if (!char.IsWhiteSpace(line[realEnd - 1]))
					break;
				realEnd--;
			}
			if (startColumn <= realStart && endColumn >= realEnd)
				return false;
			return true;
		}

19 Source : PixMapReader.cs
with MIT License
from 0xC0000054

private char GetNextNonWhiteSpaceChar()
        {
            char value;

            do
            {
                value = GetNextChar();
            } while (char.IsWhiteSpace(value));

            return value;
        }

19 Source : StringEx.cs
with GNU General Public License v3.0
from 2dust

public static bool IsWhiteSpace(this string value)
        {
            foreach (char c in value)
            {
                if (char.IsWhiteSpace(c)) continue;

                return false;
            }
            return true;
        }

19 Source : StringExtension.cs
with MIT License
from 3F

public static int FirstNonWhiteSpace(this string str, int offset = 0, bool rightToLeft = false)
        {
            if(str == null) {
                return -1;
            }

            int i = offset;

            while(true)
            {
                if(i < 0 || i > str.Length - 1) {
                    return -1;
                }

                if(!char.IsWhiteSpace(str[i])) {
                    return i;
                }

                i += rightToLeft ? -1 : 1;
            }
        }

19 Source : JSONParser.cs
with MIT License
from 5minlab

public static T FromJson<T>(this string json) {
            //Remove all whitespace not within strings to make parsing simpler
            stringBuilder.Length = 0;
            for (int i = 0; i < json.Length; i++) {
                char c = json[i];
                if (c == '\"') {
                    i = AppendUntilStringEnd(true, i, json);
                    continue;
                }
                if (char.IsWhiteSpace(c))
                    continue;

                stringBuilder.Append(c);
            }

            //Parse the thing!
            return (T)ParseValue(typeof(T), stringBuilder.ToString());
        }

19 Source : String.Extension.cs
with MIT License
from 7Bytes-Studio

public static bool IsNullOrWhiteSpace(this string str)
        {
            if (null!= str)
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (!char.IsWhiteSpace(str[i]))
                    {
                        return false;
                    }
                }
            }
            return true;
        }

19 Source : HtmlRichTextWriter.cs
with MIT License
from Abdesol

void WriteChar(char c)
		{
			bool isWhitespace = char.IsWhiteSpace(c);
			FlushSpace(isWhitespace);
			switch (c) {
				case ' ':
					if (spaceNeedsEscaping)
						htmlWriter.Write(" ");
					else
						hreplacedpace = true;
					break;
				case '\t':
					for (int i = 0; i < options.TabSize; i++) {
						htmlWriter.Write(" ");
					}
					break;
				case '\r':
					break; // ignore; we'll write the <br/> with the following \n
				case '\n':
					htmlWriter.Write("<br/>");
					needIndentation = true;
					break;
				default:
					WebUtility.HtmlEncode(c.ToString(), htmlWriter);
					break;
			}
			// If we just handled a space by setting hreplacedpace = true,
			// we mustn't set spaceNeedsEscaping as doing so would affect our own space,
			// not just the following spaces.
			if (c != ' ') {
				// Following spaces must be escaped if c was a newline/tab;
				// and they don't need escaping if c was a normal character.
				spaceNeedsEscaping = isWhitespace;
			}
		}

19 Source : IndentationReformatter.cs
with MIT License
from Abdesol

public void Step(IDoreplacedentAccessor doc, IndentationSettings set)
		{
			string line = doc.Text;
			if (set.LeaveEmptyLines && line.Length == 0) return; // leave empty lines empty
			line = line.TrimStart();

			StringBuilder indent = new StringBuilder();
			if (line.Length == 0) {
				// Special treatment for empty lines:
				if (blockComment || (inString && verbatim))
					return;
				indent.Append(block.InnerIndent);
				indent.Append(Repeat(set.IndentString, block.OneLineBlock));
				if (block.Continuation)
					indent.Append(set.IndentString);
				if (doc.Text != indent.ToString())
					doc.Text = indent.ToString();
				return;
			}

			if (TrimEnd(doc))
				line = doc.Text.TrimStart();

			Block oldBlock = block;
			bool startInComment = blockComment;
			bool startInString = (inString && verbatim);

			#region Parse char by char
			lineComment = false;
			inChar = false;
			escape = false;
			if (!verbatim) inString = false;

			lastRealChar = '\n';

			char lastchar = ' ';
			char c = ' ';
			char nextchar = line[0];
			for (int i = 0; i < line.Length; i++) {
				if (lineComment) break; // cancel parsing current line

				lastchar = c;
				c = nextchar;
				if (i + 1 < line.Length)
					nextchar = line[i + 1];
				else
					nextchar = '\n';

				if (escape) {
					escape = false;
					continue;
				}

				#region Check for comment/string chars
				switch (c) {
					case '/':
						if (blockComment && lastchar == '*')
							blockComment = false;
						if (!inString && !inChar) {
							if (!blockComment && nextchar == '/')
								lineComment = true;
							if (!lineComment && nextchar == '*')
								blockComment = true;
						}
						break;
					case '#':
						if (!(inChar || blockComment || inString))
							lineComment = true;
						break;
					case '"':
						if (!(inChar || lineComment || blockComment)) {
							inString = !inString;
							if (!inString && verbatim) {
								if (nextchar == '"') {
									escape = true; // skip escaped quote
									inString = true;
								} else {
									verbatim = false;
								}
							} else if (inString && lastchar == '@') {
								verbatim = true;
							}
						}
						break;
					case '\'':
						if (!(inString || lineComment || blockComment)) {
							inChar = !inChar;
						}
						break;
					case '\\':
						if ((inString && !verbatim) || inChar)
							escape = true; // skip next character
						break;
				}
				#endregion

				if (lineComment || blockComment || inString || inChar) {
					if (wordBuilder.Length > 0)
						block.LastWord = wordBuilder.ToString();
					wordBuilder.Length = 0;
					continue;
				}

				if (!Char.IsWhiteSpace(c) && c != '[' && c != '/') {
					if (block.Bracket == '{')
						block.Continuation = true;
				}

				if (Char.IsLetterOrDigit(c)) {
					wordBuilder.Append(c);
				} else {
					if (wordBuilder.Length > 0)
						block.LastWord = wordBuilder.ToString();
					wordBuilder.Length = 0;
				}

				#region Push/Pop the blocks
				switch (c) {
					case '{':
						block.ResetOneLineBlock();
						blocks.Push(block);
						block.StartLine = doc.LineNumber;
						if (block.LastWord == "switch") {
							block.Indent(set.IndentString + set.IndentString);
							/* oldBlock refers to the previous line, not the previous block
							 * The block we want is not available anymore because it was never pushed.
							 * } else if (oldBlock.OneLineBlock) {
							// Inside a one-line-block is another statement
							// with a full block: indent the inner full block
							// by one additional level
							block.Indent(set, set.IndentString + set.IndentString);
							block.OuterIndent += set.IndentString;
							// Indent current line if it starts with the '{' character
							if (i == 0) {
								oldBlock.InnerIndent += set.IndentString;
							}*/
						} else {
							block.Indent(set);
						}
						block.Bracket = '{';
						break;
					case '}':
						while (block.Bracket != '{') {
							if (blocks.Count == 0) break;
							block = blocks.Pop();
						}
						if (blocks.Count == 0) break;
						block = blocks.Pop();
						block.Continuation = false;
						block.ResetOneLineBlock();
						break;
					case '(':
					case '[':
						blocks.Push(block);
						if (block.StartLine == doc.LineNumber)
							block.InnerIndent = block.OuterIndent;
						else
							block.StartLine = doc.LineNumber;
						block.Indent(Repeat(set.IndentString, oldBlock.OneLineBlock) +
									 (oldBlock.Continuation ? set.IndentString : "") +
									 (i == line.Length - 1 ? set.IndentString : new String(' ', i + 1)));
						block.Bracket = c;
						break;
					case ')':
						if (blocks.Count == 0) break;
						if (block.Bracket == '(') {
							block = blocks.Pop();
							if (IsSingleStatementKeyword(block.LastWord))
								block.Continuation = false;
						}
						break;
					case ']':
						if (blocks.Count == 0) break;
						if (block.Bracket == '[')
							block = blocks.Pop();
						break;
					case ';':
					case ',':
						block.Continuation = false;
						block.ResetOneLineBlock();
						break;
					case ':':
						if (block.LastWord == "case"
							|| line.StartsWith("case ", StringComparison.Ordinal)
							|| line.StartsWith(block.LastWord + ":", StringComparison.Ordinal)) {
							block.Continuation = false;
							block.ResetOneLineBlock();
						}
						break;
				}

				if (!Char.IsWhiteSpace(c)) {
					// register this char as last char
					lastRealChar = c;
				}
				#endregion
			}
			#endregion

			if (wordBuilder.Length > 0)
				block.LastWord = wordBuilder.ToString();
			wordBuilder.Length = 0;

			if (startInString) return;
			if (startInComment && line[0] != '*') return;
			if (doc.Text.StartsWith("//\t", StringComparison.Ordinal) || doc.Text == "//")
				return;

			if (line[0] == '}') {
				indent.Append(oldBlock.OuterIndent);
				oldBlock.ResetOneLineBlock();
				oldBlock.Continuation = false;
			} else {
				indent.Append(oldBlock.InnerIndent);
			}

			if (indent.Length > 0 && oldBlock.Bracket == '(' && line[0] == ')') {
				indent.Remove(indent.Length - 1, 1);
			} else if (indent.Length > 0 && oldBlock.Bracket == '[' && line[0] == ']') {
				indent.Remove(indent.Length - 1, 1);
			}

			if (line[0] == ':') {
				oldBlock.Continuation = true;
			} else if (lastRealChar == ':' && indent.Length >= set.IndentString.Length) {
				if (block.LastWord == "case" || line.StartsWith("case ", StringComparison.Ordinal) || line.StartsWith(block.LastWord + ":", StringComparison.Ordinal))
					indent.Remove(indent.Length - set.IndentString.Length, set.IndentString.Length);
			} else if (lastRealChar == ')') {
				if (IsSingleStatementKeyword(block.LastWord)) {
					block.OneLineBlock++;
				}
			} else if (lastRealChar == 'e' && block.LastWord == "else") {
				block.OneLineBlock = Math.Max(1, block.PreviousOneLineBlock);
				block.Continuation = false;
				oldBlock.OneLineBlock = block.OneLineBlock - 1;
			}

			if (doc.IsReadOnly) {
				// We can't change the current line, but we should accept the existing
				// indentation if possible (=if the current statement is not a multiline
				// statement).
				if (!oldBlock.Continuation && oldBlock.OneLineBlock == 0 &&
					oldBlock.StartLine == block.StartLine &&
					block.StartLine < doc.LineNumber && lastRealChar != ':') {
					// use indent StringBuilder to get the indentation of the current line
					indent.Length = 0;
					line = doc.Text; // get untrimmed line
					for (int i = 0; i < line.Length; ++i) {
						if (!Char.IsWhiteSpace(line[i]))
							break;
						indent.Append(line[i]);
					}
					// /* */ multiline comments have an extra space - do not count it
					// for the block's indentation.
					if (startInComment && indent.Length > 0 && indent[indent.Length - 1] == ' ') {
						indent.Length -= 1;
					}
					block.InnerIndent = indent.ToString();
				}
				return;
			}

			if (line[0] != '{') {
				if (line[0] != ')' && oldBlock.Continuation && oldBlock.Bracket == '{')
					indent.Append(set.IndentString);
				indent.Append(Repeat(set.IndentString, oldBlock.OneLineBlock));
			}

			// this is only for blockcomment lines starting with *,
			// all others keep their old indentation
			if (startInComment)
				indent.Append(' ');

			if (indent.Length != (doc.Text.Length - line.Length) ||
				!doc.Text.StartsWith(indent.ToString(), StringComparison.Ordinal) ||
				Char.IsWhiteSpace(doc.Text[indent.Length])) {
				doc.Text = indent.ToString() + line;
			}
		}

19 Source : IndentationReformatter.cs
with MIT License
from Abdesol

static bool TrimEnd(IDoreplacedentAccessor doc)
		{
			string line = doc.Text;
			if (!Char.IsWhiteSpace(line[line.Length - 1])) return false;

			// one space after an empty comment is allowed
			if (line.EndsWith("// ", StringComparison.Ordinal) || line.EndsWith("* ", StringComparison.Ordinal))
				return false;

			doc.Text = line.TrimEnd();
			return true;
		}

19 Source : SecretUtility.cs
with MIT License
from actions

private static string ScrubSecret(string message, string token, string mask, bool replacedertOnDetection, bool maskToken=false)
        {
            int startIndex = -1;

            do
            {
                startIndex = message.IndexOf(token, (startIndex < 0) ? 0 : startIndex, StringComparison.OrdinalIgnoreCase);
                if (startIndex < 0)
                {
                    // Common case, there is not a preplacedword.
                    break;
                }

                //Explicitly check for original preplacedword mask so code that uses the orignal doesn't replacedert
                if (!maskToken && (
                    message.IndexOf(token + mask, StringComparison.OrdinalIgnoreCase) == startIndex
                    || (message.IndexOf(token + PreplacedwordMask, StringComparison.OrdinalIgnoreCase) == startIndex)))
                {
                    // The preplacedword is already masked, move past this string.
                    startIndex += token.Length + mask.Length;
                    continue;
                }

                // At this point we detected a preplacedword that is not masked, remove it!
                try
                {
                    if (!maskToken)
                    {
                        startIndex += token.Length;
                    }
                    // Find the end of the preplacedword.
                    int endIndex = message.Length - 1;

                    if (message[startIndex] == '"' || message[startIndex] == '\'')
                    {
                        // The preplacedword is wrapped in quotes.  The end of the string will be the next unpaired quote. 
                        // Unless the message itself wrapped the connection string in quotes, in which case we may mask out the rest of the message.  Better to be safe than leak the connection string.
                        // Intentionally going to "i < message.Length - 1".  If the quote isn't the second to last character, it is the last character, and we delete to the end of the string anyway.
                        for (int i = startIndex + 1; i < message.Length - 1; i++)
                        {
                            if (message[startIndex] == message[i])
                            {
                                if (message[startIndex] == message[i + 1])
                                {
                                    // we found a pair of quotes. Skip over the pair and continue.
                                    i++;
                                    continue;
                                }
                                else
                                {
                                    // this is a single quote, and the end of the preplacedword.
                                    endIndex = i;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // The preplacedword is not wrapped in quotes.
                        // The end is any whitespace, semi-colon, single, or double quote character.
                        for (int i = startIndex + 1; i < message.Length; i++)
                        {
                            if (Char.IsWhiteSpace(message[i]) || ((IList<Char>)s_validPreplacedwordEnding).Contains(message[i]))
                            {
                                endIndex = i - 1;
                                break;
                            }
                        }
                    }

                    message = message.Substring(0, startIndex) + mask + message.Substring(endIndex + 1);

                    // Bug 94478: We need to scrub the message before replacedert, otherwise we will fall into
                    // a recursive replacedert where the TeamFoundationServerException contains same message
                    if (replacedertOnDetection)
                    {
                        Debug.replacedert(false, String.Format(CultureInfo.InvariantCulture, "Message contains an unmasked secret. Message: {0}", message));
                    }

                    // Trace raw that we have scrubbed a message.
                    //FUTURE: We need a work item to add Tracing to the VSS Client replacedembly.
                    //TraceLevel traceLevel = replacedertOnDetection ? TraceLevel.Error : TraceLevel.Info;
                    //TeamFoundationTracingService.TraceRaw(99230, traceLevel, s_area, s_layer, "An unmasked preplacedword was detected in a message. MESSAGE: {0}. STACK TRACE: {1}", message, Environment.StackTrace);
                }
                catch (Exception /*exception*/)
                {
                    // With an exception here the message may still contain an unmasked preplacedword.
                    // We also do not want to interupt the current thread with this exception, because it may be constucting a message 
                    // for a different exception. Trace this exception and continue on using a generic exception message.
                    //TeamFoundationTracingService.TraceExceptionRaw(99231, s_area, s_layer, exception);
                }
                finally
                {
                    // Iterate to the next preplacedword (if it exists)
                    startIndex += mask.Length;
                }
            } while (startIndex < message.Length);

            return message;
        }

19 Source : PropertyValidation.cs
with MIT License
from actions

public static void ValidatePropertyName(String propertyName)
        {            
            ValidatePropertyString(propertyName, c_maxPropertyNameLengthInChars, "propertyName");

            // Key must not start or end in whitespace. ValidatePropertyString() checks for null and empty strings, 
            // which is why indexing on length without re-checking String.IsNullOrEmpty() is ok.
            if (Char.IsWhiteSpace(propertyName[0]) || Char.IsWhiteSpace(propertyName[propertyName.Length - 1]))
            {
                throw new VssPropertyValidationException(propertyName, CommonResources.InvalidPropertyName(propertyName));
            }
        }

19 Source : LexicalAnalyzer.cs
with MIT License
from actions

private static Boolean TestTokenBoundary(Char c)
        {
            switch (c)
            {
                case ExpressionConstants.StartGroup:    // "("
                case ExpressionConstants.StartIndex:    // "["
                case ExpressionConstants.EndGroup:      // ")"
                case ExpressionConstants.EndIndex:      // "]"
                case ExpressionConstants.Separator:     // ","
                case ExpressionConstants.Dereference:   // "."
                case '!': // "!" and "!="
                case '>': // ">" and ">="
                case '<': // "<" and "<="
                case '=': // "=="
                case '&': // "&&"
                case '|': // "||"
                    return true;
                default:
                    return char.IsWhiteSpace(c);
            }
        }

19 Source : LexicalAnalyzer.cs
with MIT License
from actions

public Boolean TryGetNextToken(ref Token token)
        {
            // Skip whitespace
            while (m_index < m_expression.Length && Char.IsWhiteSpace(m_expression[m_index]))
            {
                m_index++;
            }

            // Test end of string
            if (m_index >= m_expression.Length)
            {
                token = null;
                return false;
            }

            // Read the first character to determine the type of token.
            var c = m_expression[m_index];
            switch (c)
            {
                case ExpressionConstants.StartGroup:    // "("
                    // Function call
                    if (m_lastToken?.Kind == TokenKind.Function)
                    {
                        token = CreateToken(TokenKind.StartParameters, c, m_index++);
                    }
                    // Logical grouping
                    else
                    {
                        token = CreateToken(TokenKind.StartGroup, c, m_index++);
                    }
                    break;
                case ExpressionConstants.StartIndex:    // "["
                    token = CreateToken(TokenKind.StartIndex, c, m_index++);
                    break;
                case ExpressionConstants.EndGroup:      // ")"
                    // Function call
                    if (m_unclosedTokens.FirstOrDefault()?.Kind == TokenKind.StartParameters) // "(" function call
                    {
                        token = CreateToken(TokenKind.EndParameters, c, m_index++);
                    }
                    // Logical grouping
                    else
                    {
                        token = CreateToken(TokenKind.EndGroup, c, m_index++);
                    }
                    break;
                case ExpressionConstants.EndIndex:      // "]"
                    token = CreateToken(TokenKind.EndIndex, c, m_index++);
                    break;
                case ExpressionConstants.Separator:     // ","
                    token = CreateToken(TokenKind.Separator, c, m_index++);
                    break;
                case ExpressionConstants.Wildcard:      // "*"
                    token = CreateToken(TokenKind.Wildcard, c, m_index++);
                    break;
                case '\'':
                    token = ReadStringToken();
                    break;
                case '!':   // "!" and "!="
                case '>':   // ">" and ">="
                case '<':   // "<" and "<="
                case '=':   // "=="
                case '&':   // "&&"
                case '|':   // "||"
                    token = ReadOperator();
                    break;
                default:
                    if (c == '.')
                    {
                        // Number
                        if (m_lastToken == null ||
                            m_lastToken.Kind == TokenKind.Separator ||          // ","
                            m_lastToken.Kind == TokenKind.StartGroup ||         // "(" logical grouping
                            m_lastToken.Kind == TokenKind.StartIndex ||         // "["
                            m_lastToken.Kind == TokenKind.StartParameters ||    // "(" function call
                            m_lastToken.Kind == TokenKind.LogicalOperator)      // "!", "==", etc
                        {
                            token = ReadNumberToken();
                        }
                        // "."
                        else
                        {
                            token = CreateToken(TokenKind.Dereference, c, m_index++);
                        }
                    }
                    else if (c == '-' || c == '+' || (c >= '0' && c <= '9'))
                    {
                        token = ReadNumberToken();
                    }
                    else
                    {
                        token = ReadKeywordToken();
                    }

                    break;
            }

            m_lastToken = token;
            return true;
        }

19 Source : TemplateReader.cs
with MIT License
from actions

private static Boolean MatchesDirective(
            String trimmed,
            String directive,
            Int32 expectedParameters,
            out List<String> parameters,
            out Exception ex)
        {
            if (trimmed.StartsWith(directive, StringComparison.Ordinal) &&
                (trimmed.Length == directive.Length || Char.IsWhiteSpace(trimmed[directive.Length])))
            {
                parameters = new List<String>();
                var startIndex = directive.Length;
                var inString = false;
                var parens = 0;
                for (var i = startIndex; i < trimmed.Length; i++)
                {
                    var c = trimmed[i];
                    if (Char.IsWhiteSpace(c) && !inString && parens == 0)
                    {
                        if (startIndex < i)
                        {
                            parameters.Add(trimmed.Substring(startIndex, i - startIndex));
                        }

                        startIndex = i + 1;
                    }
                    else if (c == '\'')
                    {
                        inString = !inString;
                    }
                    else if (c == '(' && !inString)
                    {
                        parens++;
                    }
                    else if (c == ')' && !inString)
                    {
                        parens--;
                    }
                }

                if (startIndex < trimmed.Length)
                {
                    parameters.Add(trimmed.Substring(startIndex));
                }

                if (expectedParameters != parameters.Count)
                {
                    ex = new ArgumentException(TemplateStrings.ExpectedNParametersFollowingDirective(expectedParameters, directive, parameters.Count));
                    parameters = null;
                    return false;
                }

                ex = null;
                return true;
            }

            ex = null;
            parameters = null;
            return false;
        }

19 Source : LexicalAnalyzer.cs
with MIT License
from actions

private Token ReadKeywordToken()
        {
            // Read to the end of the keyword.
            var startIndex = m_index;
            m_index++; // Skip the first char. It is already known to be the start of the keyword.
            while (m_index < m_expression.Length && !TestTokenBoundary(m_expression[m_index]))
            {
                m_index++;
            }

            // Test if valid keyword character sequence.
            var length = m_index - startIndex;
            var str = m_expression.Substring(startIndex, length);
            if (ExpressionUtility.IsLegalKeyword(str))
            {
                // Test if follows property dereference operator.
                if (m_lastToken != null && m_lastToken.Kind == TokenKind.Dereference)
                {
                    return CreateToken(TokenKind.PropertyName, str, startIndex);
                }

                // Null
                if (str.Equals(ExpressionConstants.Null, StringComparison.Ordinal))
                {
                    return CreateToken(TokenKind.Null, str, startIndex);
                }
                // Boolean
                else if (str.Equals(ExpressionConstants.True, StringComparison.Ordinal))
                {
                    return CreateToken(TokenKind.Boolean, str, startIndex, true);
                }
                else if (str.Equals(ExpressionConstants.False, StringComparison.Ordinal))
                {
                    return CreateToken(TokenKind.Boolean, str, startIndex, false);
                }
                // NaN
                else if (str.Equals(ExpressionConstants.NaN, StringComparison.Ordinal))
                {
                    return CreateToken(TokenKind.Number, str, startIndex, Double.NaN);
                }
                // Infinity
                else if (str.Equals(ExpressionConstants.Infinity, StringComparison.Ordinal))
                {
                    return CreateToken(TokenKind.Number, str, startIndex, Double.PositiveInfinity);
                }

                // Lookahead
                var tempIndex = m_index;
                while (tempIndex < m_expression.Length && Char.IsWhiteSpace(m_expression[tempIndex]))
                {
                    tempIndex++;
                }

                // Function
                if (tempIndex < m_expression.Length && m_expression[tempIndex] == ExpressionConstants.StartGroup)   // "("
                {
                    return CreateToken(TokenKind.Function, str, startIndex);
                }
                // Named-value
                else
                {
                    return CreateToken(TokenKind.NamedValue, str, startIndex);
                }
            }
            else
            {
                // Invalid keyword
                return CreateToken(TokenKind.Unexpected, str, startIndex);
            }
        }

19 Source : ParentLexer.cs
with MIT License
from Actipro

public override MergableLexerResult GetNextToken(ITextBufferReader reader, ILexicalState lexicalState) {
			// Initialize
			int tokenId = ParentTokenId.Invalid;

			// Get the next character
			char ch = reader.Read();

			switch (lexicalState.Id) {
				case ParentLexicalStateId.Default: {
					// If the character is a letter or digit...
					if ((Char.IsLetter(ch) || (ch == '_'))) {
						// Parse the identifier
						tokenId = this.ParseIdentifier(reader, ch);
					}
					else if (Char.IsWhiteSpace(ch)) {
						// Consume sequential whitespace
						while (Char.IsWhiteSpace(reader.Peek())) 
							reader.Read();
						tokenId = ParentTokenId.Whitespace;
					}
					else {
						// Invalid
						tokenId = ParentTokenId.Invalid;
					}
					break;
				}
			}

			if (tokenId != ParentTokenId.Invalid) {
				return new MergableLexerResult(MatchType.ExactMatch, new LexicalStateTokenData(lexicalState, tokenId));
			}
			else {
				reader.ReadReverse();
				return MergableLexerResult.NoMatch;
			}
		}

19 Source : SimpleLexer.cs
with MIT License
from Actipro

public override MergableLexerResult GetNextToken(ITextBufferReader reader, ILexicalState lexicalState) {
			// Initialize
			int tokenId = SimpleTokenId.Invalid;

			// Get the next character
			char ch = reader.Read();

			// If the character is a letter or digit...
			if ((Char.IsLetter(ch) || (ch == '_'))) {
				// Parse the identifier
				tokenId = this.ParseIdentifier(reader, ch);
			}
			else if ((ch != '\n') && (Char.IsWhiteSpace(ch))) {
				while ((reader.Peek() != '\n') && (Char.IsWhiteSpace(reader.Peek())))
					reader.Read();
				tokenId = SimpleTokenId.Whitespace;
			}
			else {
				tokenId = SimpleTokenId.Invalid;
				switch (ch) {
					case ',':
						tokenId = SimpleTokenId.Comma;
						break;
					case '(':
						tokenId = SimpleTokenId.OpenParenthesis;
						break;
					case ')':
						tokenId = SimpleTokenId.CloseParenthesis;
						break;
					case ';':
						tokenId = SimpleTokenId.SemiColon;
						break;
					case '\n':
						// Line terminator
						tokenId = SimpleTokenId.Whitespace;
						break;
					case '{':
						tokenId = SimpleTokenId.OpenCurlyBrace;
						break;
					case '}':
						tokenId = SimpleTokenId.CloseCurlyBrace;
						break;
					case '/':
						tokenId = SimpleTokenId.Division;
						switch (reader.Peek()) {
							case '/':
								// Parse a single-line comment
								tokenId = this.ParseSingleLineComment(reader);
								break;
							case '*':
								// Parse a multi-line comment
								tokenId = this.ParseMultiLineComment(reader);
								break;
						}
						break;
					case '=':
						if (reader.Peek() == '=') {
							reader.Read();
							tokenId = SimpleTokenId.Equality;
						}
						else
							tokenId = SimpleTokenId.replacedignment;
						break;
					case '!':
						if (reader.Peek() == '=') {
							reader.Read();
							tokenId = SimpleTokenId.Inequality;
						}
						break;
					case '+':
						tokenId = SimpleTokenId.Addition;
						break;
					case '-':
						tokenId = SimpleTokenId.Subtraction;
						break;
					case '*':
						tokenId = SimpleTokenId.Multiplication;
						break;
					default:
						if ((ch >= '0') && (ch <= '9')) {
							// Parse the number
							tokenId = this.ParseNumber(reader, ch);
						}
						break;
				}
			}

			if (tokenId != SimpleTokenId.Invalid) {
				return new MergableLexerResult(MatchType.ExactMatch, new LexicalStateTokenData(lexicalState, tokenId));
			}
			else {
				reader.ReadReverse();
				return MergableLexerResult.NoMatch;
			}
		}

19 Source : MiniJson.cs
with MIT License
from AdamCarballo

public static bool IsWordBreak(char c) {
				return Char.IsWhiteSpace(c) || WORD_BREAK.IndexOf(c) != -1;
			}

19 Source : MiniJson.cs
with MIT License
from AdamCarballo

void EatWhitespace() {
				while (Char.IsWhiteSpace(PeekChar)) {
					json.Read();
					
					if (json.Peek() == -1) {
						break;
					}
				}
			}

19 Source : POGenerator.cs
with MIT License
from adams85

private int GetStringBreakIndex()
        {
            var result = -1;

            var endIndex = _builder.Length;
            int index;

            if (!HasFlags(Flags.IgnoreLongLines) && endIndex - _lineStartIndex > MaxLineLength)
            {
                result = _lineStartIndex + MaxLineLength - 1;

                char c;
                for (index = result - 1; index > _lineStartIndex; index--)
                    if ((c = _builder[index]) == '-' || char.IsWhiteSpace(c))
                    {
                        result = index + 1;
                        break;
                    }

                // escape sequences are kept together
                if (IsEscaped(_builder, result, _lineStartIndex))
                    result--;
            }

            if (!HasFlags(Flags.IgnoreLineBreaks) && (index = IndexOfNewLine(_lineStartIndex + 1, endIndex - 1)) >= 0 &&
                (result < 0 || index < result))
                result = index;

            return result;

            bool IsEscaped(StringBuilder sb, int currentIndex, int startIndex)
            {
                bool isEscaped = false;

                for (currentIndex--; currentIndex > startIndex; currentIndex--)
                    if (sb[currentIndex] == '\\')
                        isEscaped = !isEscaped;
                    else
                        break;

                return isEscaped;
            }
        }

19 Source : POParser.cs
with MIT License
from adams85

private List<POComment> ParseComments()
        {
            var result = new List<POComment>();

            KeyValuePair<TextLocation, string> commentKvp;
            string comment;
            int commentLength;
            for (int i = 0, n = _commentBuffer.Count; i < n; i++)
                if ((commentLength = (comment = (commentKvp = _commentBuffer[i]).Value).Length) > 0)
                {
                    var index = 0;
                    var c = comment[index++];
                    POCommentKind kind;
                    switch (c)
                    {
                        case '.': kind = POCommentKind.Extracted; break;
                        case ':': kind = POCommentKind.Reference; break;
                        case ',': kind = POCommentKind.Flags; break;
                        case '|': kind = POCommentKind.PreviousValue; break;
                        default:
                            if (char.IsWhiteSpace(c))
                            {
                                kind = POCommentKind.Translator;
                                break;
                            }
                            else
                                continue;
                    }

                    if (kind != POCommentKind.Translator &&
                        (index >= commentLength || !char.IsWhiteSpace(comment[index++])))
                        continue;

                    comment = comment.Substring(index);
                    switch (kind)
                    {
                        case POCommentKind.Translator:
                            result.Add(new POTranslatorComment { Text = comment.Trim() });
                            break;
                        case POCommentKind.Extracted:
                            result.Add(new POExtractedComment { Text = comment.Trim() });
                            break;
                        case POCommentKind.Reference:
                            if (POReferenceComment.TryParse(comment, out POReferenceComment referenceComment))
                                result.Add(referenceComment);
                            else
                                AddWarning(DiagnosticCodes.MalformedComment, commentKvp.Key);
                            break;
                        case POCommentKind.Flags:
                            result.Add(POFlagsComment.Parse(comment));
                            break;
                        case POCommentKind.PreviousValue:
                            if (POPreviousValueComment.TryParse(comment, _keyStringNewLine, out POPreviousValueComment previousValueComment))
                                result.Add(previousValueComment);
                            else
                                AddWarning(DiagnosticCodes.MalformedComment, commentKvp.Key);
                            break;
                    }
                }

            return result;
        }

19 Source : CSVConvert.cs
with Mozilla Public License 2.0
from agebullhu

private static int Split(string values, Action<List<string>, bool, int> action)
        {
            var cnt = 0;
            var first = true;
            var line = new List<string>();
            var sb = new StringBuilder();
            var inQuotation = false; //在引号中
            var preQuotation = false; //前一个也是引号
            var preSeparator = true;//前面是做字段分隔符号吗
            int empty = 0;
            foreach (var c in values)
            {
                if (empty > 100)
                    break;
                if (c == '\"')
                {
                    empty = 0;
                    if (inQuotation)
                    {
                        if (preQuotation)//连续引号当成正常的引号
                        {
                            sb.Append('\"');
                            preQuotation = false;
                        }
                        else//否则得看下一个,如果还是引号则认为正常引号,是引号当成引号来使用,其它情况不符合CVS的文件标准
                        {
                            preQuotation = true;
                        }
                        continue;
                    }

                    if (preSeparator)//分隔符后的引号者才是字段内容起止
                    {
                        inQuotation = true;
                        preSeparator = false;
                        sb.Clear();
                        continue;
                    }
                }
                else if (preQuotation)//字段可中止
                {
                    preQuotation = false;
                    inQuotation = false;
                }
                else if (inQuotation)//所有都是普通内容
                {
                    sb.Append(c);
                    continue;
                }
                switch (c)
                {
                    case ',':
                        if (sb.Length == 0)
                        {
                            line.Add(null);
                        }
                        else
                        {
                            line.Add(sb.ToString());
                            sb.Clear();
                        }
                        preSeparator = true;
                        continue;
                    case '\r':
                        continue;
                    case '\n':
                        if (sb.Length != 0)
                        {
                            line.Add(sb.ToString());
                            sb.Clear();
                        }
                        if (line.Count > 0 && line.Any(p => p != null))
                        {
                            if (preSeparator)
                                line.Add(null);
                            action(line, first, ++cnt);
                            line = new List<string>();
                        }
                        else
                        {
                            ++empty;
                            continue;
                        }
                        first = false;
                        preSeparator = true;
                        empty = 0;
                        continue;
                }
                empty = 0;
                if (preSeparator && !char.IsWhiteSpace(c))
                {
                    preSeparator = false;
                }
                sb.Append(c);
            }
            if (sb.Length != 0)
            {
                line.Add(sb.ToString());
                sb.Clear();
            }
            if (line.Count > 0 && line.Any(p => p != null))
            {
                line.Add(null);
                action(line, first, ++cnt);
            }
            return cnt;
        }

19 Source : Lexer.cs
with MIT License
from agens-no

void ScanString(Token tok)
        {
            tok.type = TokenType.String;
            tok.begin = pos;
            while (pos < length)
            {
                char ch = text[pos];
                char ch2 = text[pos+1];
                
                if (Char.IsWhiteSpace(ch))
                    break;
                else if (ch == '\"')
                    break;
                else if (ch == '/' && ch2 == '*')
                    break;
                else if (ch == '/' && ch2 == '/')
                    break;
                else if (IsOperator(ch))
                    break;
                pos++;
            }
            tok.end = pos;
            tok.line = line;
        }

19 Source : Lexer.cs
with MIT License
from agens-no

void ScanOne(Token tok)
        {
            while (true)
            {
                while (pos < length && Char.IsWhiteSpace(text[pos]))
                {
                    UpdateNewlineStats(text[pos]);
                    pos++;
                }
                
                if (pos >= length)
                {
                    tok.type = TokenType.EOF;
                    break;
                }
                
                char ch = text[pos];
                char ch2 = text[pos+1];
                
                if (ch == '\"')
                    ScanQuotedString(tok);
                else if (ch == '/' && ch2 == '*')
                    ScanMultilineComment(tok);
                else if (ch == '/' && ch2 == '/')
                    ScanComment(tok);
                else if (IsOperator(ch))
                    ScanOperator(tok);
                else
                    ScanString(tok); // be more robust and accept whatever is left
                return;
            }    
        }

19 Source : KeyUtil.cs
with GNU General Public License v3.0
from ahmed605

public static bool IsNullOrWhiteSpace(string value)
            {
                if (value != null)
                {
                    for (int i = 0; i < value.Length; i++)
                    {
                        if (!char.IsWhiteSpace(value[i]))
                        {
                            return false;
                        }
                    }
                }
                return true;
            }

19 Source : CommandsNextUtilities.cs
with MIT License
from Aiko-IT-Systems

internal static string ExtractNextArgument(this string str, ref int startPos)
        {
            if (string.IsNullOrWhiteSpace(str))
                return null;

            var inBacktick = false;
            var inTripleBacktick = false;
            var inQuote = false;
            var inEscape = false;
            var removeIndices = new List<int>(str.Length - startPos);

            var i = startPos;
            for (; i < str.Length; i++)
                if (!char.IsWhiteSpace(str[i]))
                    break;
            startPos = i;

            var endPosition = -1;
            var startPosition = startPos;
            for (i = startPosition; i < str.Length; i++)
            {
                if (char.IsWhiteSpace(str[i]) && !inQuote && !inTripleBacktick && !inBacktick && !inEscape)
                    endPosition = i;

                if (str[i] == '\\' && str.Length > i + 1)
                {
                    if (!inEscape && !inBacktick && !inTripleBacktick)
                    {
                        inEscape = true;
                        if (str.IndexOf("\\`", i) == i || str.IndexOf("\\\"", i) == i || str.IndexOf("\\\\", i) == i || (str.Length >= i && char.IsWhiteSpace(str[i + 1])))
                            removeIndices.Add(i - startPosition);
                        i++;
                    }
                    else if ((inBacktick || inTripleBacktick) && str.IndexOf("\\`", i) == i)
                    {
                        inEscape = true;
                        removeIndices.Add(i - startPosition);
                        i++;
                    }
                }

                if (str[i] == '`' && !inEscape)
                {
                    var tripleBacktick = str.IndexOf("```", i) == i;
                    if (inTripleBacktick && tripleBacktick)
                    {
                        inTripleBacktick = false;
                        i += 2;
                    }
                    else if (!inBacktick && tripleBacktick)
                    {
                        inTripleBacktick = true;
                        i += 2;
                    }

                    if (inBacktick && !tripleBacktick)
                        inBacktick = false;
                    else if (!inTripleBacktick && tripleBacktick)
                        inBacktick = true;
                }

                if (str[i] == '"' && !inEscape && !inBacktick && !inTripleBacktick)
                {
                    removeIndices.Add(i - startPosition);

                    inQuote = !inQuote;
                }

                if (inEscape)
                    inEscape = false;

                if (endPosition != -1)
                {
                    startPos = endPosition;
                    return startPosition != endPosition ? str.Substring(startPosition, endPosition - startPosition).CleanupString(removeIndices) : null;
                }
            }

            startPos = str.Length;
            return startPos != startPosition ? str.Substring(startPosition).CleanupString(removeIndices) : null;
        }

19 Source : CommandBuilder.cs
with MIT License
from Aiko-IT-Systems

public CommandBuilder WithName(string name)
        {
            if (name == null || name.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
                throw new ArgumentException("Command name cannot be null or contain any whitespace characters.", nameof(name));

            if (this.Name != null)
                throw new InvalidOperationException("This command already has a name.");

            if (this.AliasList.Contains(name))
                throw new ArgumentException("Command name cannot be one of its aliases.", nameof(name));

            this.Name = name;
            return this;
        }

19 Source : CommandBuilder.cs
with MIT License
from Aiko-IT-Systems

public CommandBuilder WithAlias(string alias)
        {
            if (alias.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
                throw new ArgumentException("Aliases cannot contain whitespace characters or null strings.", nameof(alias));

            if (this.Name == alias || this.AliasList.Contains(alias))
                throw new ArgumentException("Aliases cannot contain the command name, and cannot be duplicate.", nameof(alias));

            this.AliasList.Add(alias);
            return this;
        }

19 Source : StringUtils.cs
with MIT License
from akaskela

public static bool IsWhiteSpace(string s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            if (s.Length == 0)
            {
                return false;
            }

            for (int i = 0; i < s.Length; i++)
            {
                if (!char.IsWhiteSpace(s[i]))
                {
                    return false;
                }
            }

            return true;
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private bool ParsePostValue()
        {
            while (true)
            {
                char currentChar = _chars[_charPos];

                switch (currentChar)
                {
                    case '\0':
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(false) == 0)
                            {
                                _currentState = State.Finished;
                                return false;
                            }
                        }
                        else
                        {
                            _charPos++;
                        }
                        break;
                    case '}':
                        _charPos++;
                        SetToken(JsonToken.EndObject);
                        return true;
                    case ']':
                        _charPos++;
                        SetToken(JsonToken.EndArray);
                        return true;
                    case ')':
                        _charPos++;
                        SetToken(JsonToken.EndConstructor);
                        return true;
                    case '/':
                        ParseComment(true);
                        return true;
                    case ',':
                        _charPos++;

                        // finished parsing
                        SetStateBasedOnCurrent();
                        return false;
                    case ' ':
                    case StringUtils.Tab:
                        // eat
                        _charPos++;
                        break;
                    case StringUtils.CarriageReturn:
                        ProcessCarriageReturn(false);
                        break;
                    case StringUtils.LineFeed:
                        ProcessLineFeed();
                        break;
                    default:
                        if (char.IsWhiteSpace(currentChar))
                        {
                            // eat
                            _charPos++;
                        }
                        else
                        {
                            throw JsonReaderException.Create(this, "After parsing a value an unexpected character was encountered: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
                        }
                        break;
                }
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private bool ParseObject()
        {
            while (true)
            {
                char currentChar = _chars[_charPos];

                switch (currentChar)
                {
                    case '\0':
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(false) == 0)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            _charPos++;
                        }
                        break;
                    case '}':
                        SetToken(JsonToken.EndObject);
                        _charPos++;
                        return true;
                    case '/':
                        ParseComment(true);
                        return true;
                    case StringUtils.CarriageReturn:
                        ProcessCarriageReturn(false);
                        break;
                    case StringUtils.LineFeed:
                        ProcessLineFeed();
                        break;
                    case ' ':
                    case StringUtils.Tab:
                        // eat
                        _charPos++;
                        break;
                    default:
                        if (char.IsWhiteSpace(currentChar))
                        {
                            // eat
                            _charPos++;
                        }
                        else
                        {
                            return ParseProperty();
                        }
                        break;
                }
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private void ParseUnquotedProperty()
        {
            int initialPosition = _charPos;

            // parse unquoted property name until whitespace or colon
            while (true)
            {
                switch (_chars[_charPos])
                {
                    case '\0':
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(true) == 0)
                            {
                                throw JsonReaderException.Create(this, "Unexpected end while parsing unquoted property name.");
                            }

                            break;
                        }

                        _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition);
                        return;
                    default:
                        char currentChar = _chars[_charPos];

                        if (ValidIdentifierChar(currentChar))
                        {
                            _charPos++;
                            break;
                        }
                        else if (char.IsWhiteSpace(currentChar) || currentChar == ':')
                        {
                            _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition);
                            return;
                        }

                        throw JsonReaderException.Create(this, "Invalid JavaScript property identifier character: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
                }
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private bool ParseValue()
        {
            while (true)
            {
                char currentChar = _chars[_charPos];

                switch (currentChar)
                {
                    case '\0':
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(false) == 0)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            _charPos++;
                        }
                        break;
                    case '"':
                    case '\'':
                        ParseString(currentChar, ReadType.Read);
                        return true;
                    case 't':
                        ParseTrue();
                        return true;
                    case 'f':
                        ParseFalse();
                        return true;
                    case 'n':
                        if (EnsureChars(1, true))
                        {
                            char next = _chars[_charPos + 1];

                            if (next == 'u')
                            {
                                ParseNull();
                            }
                            else if (next == 'e')
                            {
                                ParseConstructor();
                            }
                            else
                            {
                                throw CreateUnexpectedCharacterException(_chars[_charPos]);
                            }
                        }
                        else
                        {
                            _charPos++;
                            throw CreateUnexpectedEndException();
                        }
                        return true;
                    case 'N':
                        ParseNumberNaN(ReadType.Read);
                        return true;
                    case 'I':
                        ParseNumberPositiveInfinity(ReadType.Read);
                        return true;
                    case '-':
                        if (EnsureChars(1, true) && _chars[_charPos + 1] == 'I')
                        {
                            ParseNumberNegativeInfinity(ReadType.Read);
                        }
                        else
                        {
                            ParseNumber(ReadType.Read);
                        }
                        return true;
                    case '/':
                        ParseComment(true);
                        return true;
                    case 'u':
                        ParseUndefined();
                        return true;
                    case '{':
                        _charPos++;
                        SetToken(JsonToken.StartObject);
                        return true;
                    case '[':
                        _charPos++;
                        SetToken(JsonToken.StartArray);
                        return true;
                    case ']':
                        _charPos++;
                        SetToken(JsonToken.EndArray);
                        return true;
                    case ',':
                        // don't increment position, the next call to read will handle comma
                        // this is done to handle multiple empty comma values
                        SetToken(JsonToken.Undefined);
                        return true;
                    case ')':
                        _charPos++;
                        SetToken(JsonToken.EndConstructor);
                        return true;
                    case StringUtils.CarriageReturn:
                        ProcessCarriageReturn(false);
                        break;
                    case StringUtils.LineFeed:
                        ProcessLineFeed();
                        break;
                    case ' ':
                    case StringUtils.Tab:
                        // eat
                        _charPos++;
                        break;
                    default:
                        if (char.IsWhiteSpace(currentChar))
                        {
                            // eat
                            _charPos++;
                            break;
                        }
                        if (char.IsNumber(currentChar) || currentChar == '-' || currentChar == '.')
                        {
                            ParseNumber(ReadType.Read);
                            return true;
                        }

                        throw CreateUnexpectedCharacterException(currentChar);
                }
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

public override byte[] ReadAsBytes()
        {
            EnsureBuffer();
            bool isWrapped = false;

            switch (_currentState)
            {
                case State.Start:
                case State.Property:
                case State.Array:
                case State.ArrayStart:
                case State.Constructor:
                case State.ConstructorStart:
                case State.PostValue:
                    while (true)
                    {
                        char currentChar = _chars[_charPos];

                        switch (currentChar)
                        {
                            case '\0':
                                if (ReadNullChar())
                                {
                                    SetToken(JsonToken.None, null, false);
                                    return null;
                                }
                                break;
                            case '"':
                            case '\'':
                                ParseString(currentChar, ReadType.ReadAsBytes);
                                byte[] data = (byte[])Value;
                                if (isWrapped)
                                {
                                    ReaderReadAndreplacedert();
                                    if (TokenType != JsonToken.EndObject)
                                    {
                                        throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
                                    }
                                    SetToken(JsonToken.Bytes, data, false);
                                }
                                return data;
                            case '{':
                                _charPos++;
                                SetToken(JsonToken.StartObject);
                                ReadIntoWrappedTypeObject();
                                isWrapped = true;
                                break;
                            case '[':
                                _charPos++;
                                SetToken(JsonToken.StartArray);
                                return ReadArrayIntoByteArray();
                            case 'n':
                                HandleNull();
                                return null;
                            case '/':
                                ParseComment(false);
                                break;
                            case ',':
                                ProcessValueComma();
                                break;
                            case ']':
                                _charPos++;
                                if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue)
                                {
                                    SetToken(JsonToken.EndArray);
                                    return null;
                                }
                                throw CreateUnexpectedCharacterException(currentChar);
                            case StringUtils.CarriageReturn:
                                ProcessCarriageReturn(false);
                                break;
                            case StringUtils.LineFeed:
                                ProcessLineFeed();
                                break;
                            case ' ':
                            case StringUtils.Tab:
                                // eat
                                _charPos++;
                                break;
                            default:
                                _charPos++;

                                if (!char.IsWhiteSpace(currentChar))
                                {
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }

                                // eat
                                break;
                        }
                    }
                case State.Finished:
                    ReadFinished();
                    return null;
                default:
                    throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState));
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

public override bool? ReadAsBoolean()
        {
            EnsureBuffer();

            switch (_currentState)
            {
                case State.Start:
                case State.Property:
                case State.Array:
                case State.ArrayStart:
                case State.Constructor:
                case State.ConstructorStart:
                case State.PostValue:
                    while (true)
                    {
                        char currentChar = _chars[_charPos];

                        switch (currentChar)
                        {
                            case '\0':
                                if (ReadNullChar())
                                {
                                    SetToken(JsonToken.None, null, false);
                                    return null;
                                }
                                break;
                            case '"':
                            case '\'':
                                ParseString(currentChar, ReadType.Read);
                                return ReadBooleanString(_stringReference.ToString());
                            case 'n':
                                HandleNull();
                                return null;
                            case '-':
                            case '.':
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                ParseNumber(ReadType.Read);
                                bool b;
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
                                if (Value is BigInteger)
                                {
                                    b = (BigInteger)Value != 0;
                                }
                                else
#endif
                                {
                                    b = Convert.ToBoolean(Value, CultureInfo.InvariantCulture);
                                }
                                SetToken(JsonToken.Boolean, b, false);
                                return b;
                            case 't':
                            case 'f':
                                bool isTrue = currentChar == 't';
                                string expected = isTrue ? JsonConvert.True : JsonConvert.False;

                                if (!MatchValueWithTrailingSeparator(expected))
                                {
                                    throw CreateUnexpectedCharacterException(_chars[_charPos]);
                                }
                                SetToken(JsonToken.Boolean, isTrue);
                                return isTrue;
                            case '/':
                                ParseComment(false);
                                break;
                            case ',':
                                ProcessValueComma();
                                break;
                            case ']':
                                _charPos++;
                                if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue)
                                {
                                    SetToken(JsonToken.EndArray);
                                    return null;
                                }
                                throw CreateUnexpectedCharacterException(currentChar);
                            case StringUtils.CarriageReturn:
                                ProcessCarriageReturn(false);
                                break;
                            case StringUtils.LineFeed:
                                ProcessLineFeed();
                                break;
                            case ' ':
                            case StringUtils.Tab:
                                // eat
                                _charPos++;
                                break;
                            default:
                                _charPos++;

                                if (!char.IsWhiteSpace(currentChar))
                                {
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }

                                // eat
                                break;
                        }
                    }
                case State.Finished:
                    ReadFinished();
                    return null;
                default:
                    throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState));
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private object ReadNumberValue(ReadType readType)
        {
            EnsureBuffer();

            switch (_currentState)
            {
                case State.Start:
                case State.Property:
                case State.Array:
                case State.ArrayStart:
                case State.Constructor:
                case State.ConstructorStart:
                case State.PostValue:
                    while (true)
                    {
                        char currentChar = _chars[_charPos];

                        switch (currentChar)
                        {
                            case '\0':
                                if (ReadNullChar())
                                {
                                    SetToken(JsonToken.None, null, false);
                                    return null;
                                }
                                break;
                            case '"':
                            case '\'':
                                ParseString(currentChar, readType);
                                switch (readType)
                                {
                                    case ReadType.ReadAsInt32:
                                        return ReadInt32String(_stringReference.ToString());
                                    case ReadType.ReadAsDecimal:
                                        return ReadDecimalString(_stringReference.ToString());
                                    case ReadType.ReadAsDouble:
                                        return ReadDoubleString(_stringReference.ToString());
                                    default:
                                        throw new ArgumentOutOfRangeException(nameof(readType));
                                }
                            case 'n':
                                HandleNull();
                                return null;
                            case 'N':
                                return ParseNumberNaN(readType);
                            case 'I':
                                return ParseNumberPositiveInfinity(readType);
                            case '-':
                                if (EnsureChars(1, true) && _chars[_charPos + 1] == 'I')
                                {
                                    return ParseNumberNegativeInfinity(readType);
                                }
                                else
                                {
                                    ParseNumber(readType);
                                    return Value;
                                }
                            case '.':
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                ParseNumber(readType);
                                return Value;
                            case '/':
                                ParseComment(false);
                                break;
                            case ',':
                                ProcessValueComma();
                                break;
                            case ']':
                                _charPos++;
                                if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue)
                                {
                                    SetToken(JsonToken.EndArray);
                                    return null;
                                }
                                throw CreateUnexpectedCharacterException(currentChar);
                            case StringUtils.CarriageReturn:
                                ProcessCarriageReturn(false);
                                break;
                            case StringUtils.LineFeed:
                                ProcessLineFeed();
                                break;
                            case ' ':
                            case StringUtils.Tab:
                                // eat
                                _charPos++;
                                break;
                            default:
                                _charPos++;

                                if (!char.IsWhiteSpace(currentChar))
                                {
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }

                                // eat
                                break;
                        }
                    }
                case State.Finished:
                    ReadFinished();
                    return null;
                default:
                    throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState));
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private bool IsSeparator(char c)
        {
            switch (c)
            {
                case '}':
                case ']':
                case ',':
                    return true;
                case '/':
                    // check next character to see if start of a comment
                    if (!EnsureChars(1, false))
                    {
                        return false;
                    }

                    var nextChart = _chars[_charPos + 1];

                    return (nextChart == '*' || nextChart == '/');
                case ')':
                    if (CurrentState == State.Constructor || CurrentState == State.ConstructorStart)
                    {
                        return true;
                    }
                    break;
                case ' ':
                case StringUtils.Tab:
                case StringUtils.LineFeed:
                case StringUtils.CarriageReturn:
                    return true;
                default:
                    if (char.IsWhiteSpace(c))
                    {
                        return true;
                    }
                    break;
            }

            return false;
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private object ReadStringValue(ReadType readType)
        {
            EnsureBuffer();

            switch (_currentState)
            {
                case State.Start:
                case State.Property:
                case State.Array:
                case State.ArrayStart:
                case State.Constructor:
                case State.ConstructorStart:
                case State.PostValue:
                    while (true)
                    {
                        char currentChar = _chars[_charPos];

                        switch (currentChar)
                        {
                            case '\0':
                                if (ReadNullChar())
                                {
                                    SetToken(JsonToken.None, null, false);
                                    return null;
                                }
                                break;
                            case '"':
                            case '\'':
                                ParseString(currentChar, readType);
                                switch (readType)
                                {
                                    case ReadType.ReadAsBytes:
                                        return Value;
                                    case ReadType.Readreplacedtring:
                                        return Value;
                                    case ReadType.ReadAsDateTime:
                                        if (Value is DateTime)
                                        {
                                            return (DateTime)Value;
                                        }
                                        return ReadDateTimeString((string)Value);
#if !NET20
                                    case ReadType.ReadAsDateTimeOffset:
                                        if (Value is DateTimeOffset)
                                        {
                                            return (DateTimeOffset)Value;
                                        }
                                        return ReadDateTimeOffsetString((string)Value);
#endif
                                    default:
                                        throw new ArgumentOutOfRangeException(nameof(readType));
                                }
                            case '-':
                                if (EnsureChars(1, true) && _chars[_charPos + 1] == 'I')
                                {
                                    return ParseNumberNegativeInfinity(readType);
                                }
                                else
                                {
                                    ParseNumber(readType);
                                    return Value;
                                }
                            case '.':
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                if (readType != ReadType.Readreplacedtring)
                                {
                                    _charPos++;
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }
                                ParseNumber(ReadType.Readreplacedtring);
                                return Value;
                            case 't':
                            case 'f':
                                if (readType != ReadType.Readreplacedtring)
                                {
                                    _charPos++;
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }
                                string expected = currentChar == 't' ? JsonConvert.True : JsonConvert.False;
                                if (!MatchValueWithTrailingSeparator(expected))
                                {
                                    throw CreateUnexpectedCharacterException(_chars[_charPos]);
                                }
                                SetToken(JsonToken.String, expected);
                                return expected;
                            case 'I':
                                return ParseNumberPositiveInfinity(readType);
                            case 'N':
                                return ParseNumberNaN(readType);
                            case 'n':
                                HandleNull();
                                return null;
                            case '/':
                                ParseComment(false);
                                break;
                            case ',':
                                ProcessValueComma();
                                break;
                            case ']':
                                _charPos++;
                                if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue)
                                {
                                    SetToken(JsonToken.EndArray);
                                    return null;
                                }
                                throw CreateUnexpectedCharacterException(currentChar);
                            case StringUtils.CarriageReturn:
                                ProcessCarriageReturn(false);
                                break;
                            case StringUtils.LineFeed:
                                ProcessLineFeed();
                                break;
                            case ' ':
                            case StringUtils.Tab:
                                // eat
                                _charPos++;
                                break;
                            default:
                                _charPos++;

                                if (!char.IsWhiteSpace(currentChar))
                                {
                                    throw CreateUnexpectedCharacterException(currentChar);
                                }

                                // eat
                                break;
                        }
                    }
                case State.Finished:
                    ReadFinished();
                    return null;
                default:
                    throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState));
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private void ReadNumberIntoBuffer()
        {
            int charPos = _charPos;

            while (true)
            {
                switch (_chars[charPos])
                {
                    case '\0':
                        _charPos = charPos;

                        if (_charsUsed == charPos)
                        {
                            if (ReadData(true) == 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                        break;
                    case '-':
                    case '+':
                    case 'a':
                    case 'A':
                    case 'b':
                    case 'B':
                    case 'c':
                    case 'C':
                    case 'd':
                    case 'D':
                    case 'e':
                    case 'E':
                    case 'f':
                    case 'F':
                    case 'x':
                    case 'X':
                    case '.':
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        charPos++;
                        break;
                    default:
                        _charPos = charPos;

                        char currentChar = _chars[_charPos];
                        if (char.IsWhiteSpace(currentChar) || currentChar == ',' || currentChar == '}' || currentChar == ']' || currentChar == ')' || currentChar == '/')
                        {
                            return;
                        }

                        throw JsonReaderException.Create(this, "Unexpected character encountered while parsing number: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
                }
            }
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private bool EatWhitespace(bool oneOrMore)
        {
            bool finished = false;
            bool ateWhitespace = false;
            while (!finished)
            {
                char currentChar = _chars[_charPos];

                switch (currentChar)
                {
                    case '\0':
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(false) == 0)
                            {
                                finished = true;
                            }
                        }
                        else
                        {
                            _charPos++;
                        }
                        break;
                    case StringUtils.CarriageReturn:
                        ProcessCarriageReturn(false);
                        break;
                    case StringUtils.LineFeed:
                        ProcessLineFeed();
                        break;
                    default:
                        if (currentChar == ' ' || char.IsWhiteSpace(currentChar))
                        {
                            ateWhitespace = true;
                            _charPos++;
                        }
                        else
                        {
                            finished = true;
                        }
                        break;
                }
            }

            return (!oneOrMore || ateWhitespace);
        }

19 Source : JsonTextReader.cs
with MIT License
from akaskela

private void ParseConstructor()
        {
            if (MatchValueWithTrailingSeparator("new"))
            {
                EatWhitespace(false);

                int initialPosition = _charPos;
                int endPosition;

                while (true)
                {
                    char currentChar = _chars[_charPos];
                    if (currentChar == '\0')
                    {
                        if (_charsUsed == _charPos)
                        {
                            if (ReadData(true) == 0)
                            {
                                throw JsonReaderException.Create(this, "Unexpected end while parsing constructor.");
                            }
                        }
                        else
                        {
                            endPosition = _charPos;
                            _charPos++;
                            break;
                        }
                    }
                    else if (char.IsLetterOrDigit(currentChar))
                    {
                        _charPos++;
                    }
                    else if (currentChar == StringUtils.CarriageReturn)
                    {
                        endPosition = _charPos;
                        ProcessCarriageReturn(true);
                        break;
                    }
                    else if (currentChar == StringUtils.LineFeed)
                    {
                        endPosition = _charPos;
                        ProcessLineFeed();
                        break;
                    }
                    else if (char.IsWhiteSpace(currentChar))
                    {
                        endPosition = _charPos;
                        _charPos++;
                        break;
                    }
                    else if (currentChar == '(')
                    {
                        endPosition = _charPos;
                        break;
                    }
                    else
                    {
                        throw JsonReaderException.Create(this, "Unexpected character while parsing constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
                    }
                }

                _stringReference = new StringReference(_chars, initialPosition, endPosition - initialPosition);
                string constructorName = _stringReference.ToString();

                EatWhitespace(false);

                if (_chars[_charPos] != '(')
                {
                    throw JsonReaderException.Create(this, "Unexpected character while parsing constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, _chars[_charPos]));
                }

                _charPos++;

                ClearRecentString();

                SetToken(JsonToken.StartConstructor, constructorName);
            }
            else
            {
                throw JsonReaderException.Create(this, "Unexpected content while parsing JSON.");
            }
        }

19 Source : HtmlLexicalAnalyzer.cs
with GNU Affero General Public License v3.0
from akshinmustafayev

internal void GetNextAtomToken()
        {
            Debug.replacedert(_nextTokenType != HtmlTokenType.EOF);
            _nextToken.Length = 0;

            this.SkipWhiteSpace();

            _nextTokenType = HtmlTokenType.Atom;

            if ((this.NextCharacter == '\'' || this.NextCharacter == '"') && !this.IsNextCharacterEnreplacedy)
            {
                char startingQuote = this.NextCharacter;
                this.GetNextCharacter();

                // Consume all characters between quotes
                while (!(this.NextCharacter == startingQuote && !this.IsNextCharacterEnreplacedy) && !this.IsAtEndOfStream)
                {
                    _nextToken.Append(this.NextCharacter);
                    this.GetNextCharacter();
                }
                if (this.NextCharacter == startingQuote)
                {
                    this.GetNextCharacter();
                }

                // complete the quoted value
                // NOTE: our recovery here is different from IE's
                // IE keeps reading until it finds a closing quote or end of file
                // if end of file, it treats current value as text
                // if it finds a closing quote at any point within the text, it eats everything between the quotes
                // TODO: Suggestion:
                // however, we could stop when we encounter end of file or an angle bracket of any kind
                // and replacedume there was a quote there
                // so the attribute value may be meaningless but it is never treated as text
            }
            else
            {
                while (!this.IsAtEndOfStream && !Char.IsWhiteSpace(this.NextCharacter) && this.NextCharacter != '>')
                {
                    _nextToken.Append(this.NextCharacter);
                    this.GetNextCharacter();
                }
            }
        }

19 Source : HtmlLexicalAnalyzer.cs
with GNU Affero General Public License v3.0
from akshinmustafayev

private void SkipWhiteSpace()
        {
            // TODO: handle character enreplacedies while processing comments, cdata, and directives
            // TODO: SUGGESTION: we could check if lookahead and previous characters are enreplacedies also
            while (true)
            {
                if (_nextCharacter == '<' && (_lookAheadCharacter == '?' || _lookAheadCharacter == '!'))
                {
                    this.GetNextCharacter();

                    if (_lookAheadCharacter == '[')
                    {
                        // Skip CDATA block and DTDs(?)
                        while (!this.IsAtEndOfStream && !(_previousCharacter == ']' && _nextCharacter == ']' && _lookAheadCharacter == '>'))
                        {
                            this.GetNextCharacter();
                        }
                        if (_nextCharacter == '>')
                        {
                            this.GetNextCharacter();
                        }
                    }
                    else
                    {
                        // Skip processing instruction, comments
                        while (!this.IsAtEndOfStream && _nextCharacter != '>')
                        {
                            this.GetNextCharacter();
                        }
                        if (_nextCharacter == '>')
                        {
                            this.GetNextCharacter();
                        }
                    }
                }


                if (!Char.IsWhiteSpace(this.NextCharacter))
                {
                    break;
                }

                this.GetNextCharacter();
            }
        }

19 Source : HtmlCssParser.cs
with GNU Affero General Public License v3.0
from akshinmustafayev

private static void ParseWhiteSpace(string styleValue, ref int nextIndex)
        {
            while (nextIndex < styleValue.Length && Char.IsWhiteSpace(styleValue[nextIndex]))
            {
                nextIndex++;
            }
        }

19 Source : Scanner.cs
with Apache License 2.0
from alaatm

private void ReadIdentifier()
        {
            while (char.IsLetterOrDigit(Peek()))
            {
                Advance();
            }

            var text = _source.Substring(_start, _current - _start);

            // "not" can only be used with "like"
            if (text.ToLower() == "not")
            {
                while (char.IsWhiteSpace(Peek()))
                {
                    Advance();
                }

                var start = _current;

                while (char.IsLetter(Peek()))
                {
                    Advance();
                }

                text = _source.Substring(start, _current - start).ToLower();
                if (text == "like")
                {
                    AddToken(TokenType.NotLike);
                }
                else
                {
                    throw new QueryEngineException($"Unexpected character at position '{start + 1}': \"not\" keyword may only be used with \"like\" keyword.");
                }
            }
            else
            {
                var type = _keywords.ContainsKey(text.ToLower()) ? _keywords[text.ToLower()] : (TokenType?)null;
                AddToken(type is null ? TokenType.Identifier : type.Value);
            }
        }

19 Source : ProgramArguments.cs
with MIT License
from Alan-FGR

private bool LexFileArguments(string fileName, out string[] arguments)
		{
			string args = null;

			try
			{
				using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
				{
					args = (new StreamReader(file)).ReadToEnd();
				}
			}
			catch (Exception e)
			{
				this.reporter(string.Format("Error: Can't open command line argument file '{0}' : '{1}'", fileName, e.Message));
				arguments = null;
				return false;
			}

			bool hadError = false;
			ArrayList argArray = new ArrayList();
			StringBuilder currentArg = new StringBuilder();
			bool inQuotes = false;
			int index = 0;

			// while (index < args.Length)
			try
			{
				while (true)
				{
					// skip whitespace
					while (char.IsWhiteSpace(args[index]))
					{
						index += 1;
					}

					// # - comment to end of line
					if (args[index] == '#')
					{
						index += 1;
						while (args[index] != '\n')
						{
							index += 1;
						}
						continue;
					}

					// do one argument
					do
					{
						if (args[index] == '\\')
						{
							int cSlashes = 1;
							index += 1;
							while (index == args.Length && args[index] == '\\')
							{
								cSlashes += 1;
							}

							if (index == args.Length || args[index] != '"')
							{
								currentArg.Append('\\', cSlashes);
							}
							else
							{
								currentArg.Append('\\', (cSlashes >> 1));
								if (0 != (cSlashes & 1))
								{
									currentArg.Append('"');
								}
								else
								{
									inQuotes = !inQuotes;
								}
							}
						}
						else if (args[index] == '"')
						{
							inQuotes = !inQuotes;
							index += 1;
						}
						else
						{
							currentArg.Append(args[index]);
							index += 1;
						}
					} while (!char.IsWhiteSpace(args[index]) || inQuotes);
					argArray.Add(currentArg.ToString());
					currentArg.Length = 0;
				}
			}
			catch (System.IndexOutOfRangeException)
			{
				// got EOF 
				if (inQuotes)
				{
					this.reporter(string.Format("Error: Unbalanced '\"' in command line argument file '{0}'", fileName));
					hadError = true;
				}
				else if (currentArg.Length > 0)
				{
					// valid argument can be terminated by EOF
					argArray.Add(currentArg.ToString());
				}
			}

			arguments = (string[])argArray.ToArray(typeof(string));
			return hadError;
		}

19 Source : Formatter.cs
with MIT License
from AlenToma

public static string PrettyPrint(string input, string spaces)
        {
            _indent = spaces;
            var output = new StringBuilder();
            int depth = 0;
            int len = input.Length;
            char[] chars = input.ToCharArray();
            for (int i = 0; i < len; ++i)
            {
                char ch = chars[i];

                if (ch == '\"') // found string span
                {
                    bool str = true;
                    while (str)
                    {
                        output.Append(ch);
                        ch = chars[++i];
                        if (ch == '\\')
                        {
                            output.Append(ch);
                            ch = chars[++i];
                        }
                        else if (ch == '\"')
                            str = false;
                    }
                }

                switch (ch)
                {
                    case '{':
                    case '[':
                        output.Append(ch);
                        output.AppendLine();
                        AppendIndent(output, ++depth);
                        break;
                    case '}':
                    case ']':
                        output.AppendLine();
                        AppendIndent(output, --depth);
                        output.Append(ch);
                        break;
                    case ',':
                        output.Append(ch);
                        output.AppendLine();
                        AppendIndent(output, depth);
                        break;
                    case ':':
                        output.Append(" : ");
                        break;
                    default:
                        if (!char.IsWhiteSpace(ch))
                            output.Append(ch);
                        break;
                }
            }

            return output.ToString();
        }

19 Source : Solution.cs
with MIT License
from AlexChesser

public int MyAtoi(string s) {
        if(s.Length == 0){
            return 0;
        }
        char check;
        bool IsNegative = false;
        List<char> digits = new List<char>();;
        for(int i = 0; i < s.Length; i++){
            check = s[i];
            if(digits.Count == 0){
                if(char.IsWhiteSpace(check)){
                    continue;
                }
                if(i == s.Length - 1 && (!char.IsNumber(check) || check == ZERO) ){
                    return 0;   
                }
                if(check == ZERO && !char.IsNumber(s[i+1])){
                    return 0;
                }
                if(check == ZERO){
                    continue;
                }
                if(check == '-'){
                    if(!char.IsNumber(s[i+1])){
                        return 0;
                    }
                    IsNegative = true;
                    continue;
                }
                if(check == '+' ){
                    if(!char.IsNumber(s[i+1])){
                        return 0;
                    }
                    continue;
                }
                if(check < ZERO || check > NINE){
                    return 0;
                }
            }
            if(char.IsNumber(check)){
                digits.Add(check);
                if(digits.Count > 10){
                    return IsNegative ? int.MinValue : int.MaxValue; 
                }
                continue;
            }
            break;
        }
        if(digits.Count == 0){
            return 0;
        }
        if(digits.Count <= 10){
            try{
                return int.Parse(string.Join(null, digits)) * (IsNegative ? -1 : 1);
            } catch {

            }
        }
        return IsNegative ? int.MinValue : int.MaxValue;
    }

See More Examples