idTech4.Text.idLexer.ReadString C# (CSharp) Method

ReadString() private method

private ReadString ( idToken token, char quote ) : bool
token idToken
quote char
return bool
		private bool ReadString(idToken token, char quote)
		{
			char ch;
			int tmpScriptPosition;
			int tmpLine;

			if(quote == '"')
			{
				token.Type = TokenType.String;
			}
			else
			{
				token.Type = TokenType.Literal;
			}

			// leading quote
			_scriptPosition++;

			while(true)
			{
				// if there is an escape character and escape characters are allowed.
				if((GetBufferCharacter(_scriptPosition) == '\\') && ((_options & LexerOptions.NoStringEscapeCharacters) == 0))
				{
					if(ReadEscapeCharacter(out ch) == false)
					{
						return false;
					}

					token.Append(ch);
				}
				// if a trailing quote
				else if(GetBufferCharacter(_scriptPosition) == quote)
				{
					// step over the quote
					_scriptPosition++;

					// if consecutive strings should not be concatenated
					if(((_options & LexerOptions.NoStringConcatination) == LexerOptions.NoStringConcatination) 
						&& (((_options & LexerOptions.AllowBackslashStringConcatination) == 0) || (quote != '"')))
					{
						break;
					}

					tmpScriptPosition = _scriptPosition;
					tmpLine = _line;

					// read white space between possible two consecutive strings
					if(ReadWhiteSpace() == false)
					{
						_scriptPosition = tmpScriptPosition;
						_line = tmpLine;

						break;
					}

					if((_options & LexerOptions.NoStringConcatination) == LexerOptions.NoStringConcatination)
					{
						if(GetBufferCharacter(_scriptPosition) != '\\')
						{
							_scriptPosition = tmpScriptPosition;
							_line = tmpLine;

							break;
						}

						// step over the '\\'
						_scriptPosition++;

						if((ReadWhiteSpace() == false) || (GetBufferCharacter(_scriptPosition) != quote))
						{
							Error("expecting string after '\\' terminated line");
							return false;
						}
					}

					// if there's no leading qoute
					if(GetBufferCharacter(_scriptPosition) != quote)
					{
						_scriptPosition = tmpScriptPosition;
						_line = tmpLine;

						break;
					}

					// step over the new leading quote
					_scriptPosition++;
				}
				else
				{
					if(GetBufferCharacter(_scriptPosition) == '\0')
					{
						Error("missing trailing quote");
						return false;
					}

					if(GetBufferCharacter(_scriptPosition) == '\n')
					{
						Error("newline inside string");
						return false;
					}

					token.Append(GetBufferCharacter(_scriptPosition++));
				}
			}

			if(token.Type == TokenType.Literal)
			{
				if((_options & LexerOptions.AllowMultiCharacterLiterals) == 0)
				{
					if(token.Length != 1)
					{
						Warning("literal is not one character long");
					}
				}

				token.SubType = (TokenSubType) token.ToString()[0];
			}
			else
			{
				// the sub type is the length of the string
				token.SubType = (TokenSubType) token.ToString().Length;
			}

			return true;
		}