System.IO.TextReader.Peek()

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

174 Examples 7

19 Source : FLRPC.cs
with GNU General Public License v3.0
from 0x2b00b1e5

public static void Start()
        {
            Active = true;
            // loop
            Csecret = settings.Secret;
            while (client != null && Active)
            {
                // Get info
                FLInfo InitInfo = GetFLInfo();

                // Try to read any keys if available
                if (Console.In.Peek() != -1)
                {
                    switch (Console.ReadKey(true).Key)
                    {
                        case ConsoleKey.H:
                            Console.WriteLine("Commands: \n s: turn on secret mode \n q: Quit \n h: help \n Other settings can be changed in the settings.xml file");
                            break;
                        case ConsoleKey.S:
                            if (Csecret)
                            {
                                Csecret = false;
                                Console.WriteLine("\n Secret Mode turned off!");
                                rp.State = InitInfo.projectName;
                            }
                            else if (!Csecret)
                            {
                                Csecret = true;
                                Console.WriteLine("\n Secret Mode turned on!");
                                rp.State = settings.SecretMessage;
                            }

                            break;
                        case ConsoleKey.Q:
                            StopAndExit();
                            break;

                    }
                }


                if (client != null)
                    client.Invoke();


                //Skip update if nothing changes
                if (InitInfo.appName == rp.Details && InitInfo.projectName == rp.State && Csecret == Psecret)
                    continue;
                if (InitInfo.projectName == null && rp.State == settings.NoNameMessage && Csecret == Psecret)
                    continue;

                //Fill State and details
                if (InitInfo.projectName == null)
                {
                    rp.State = settings.NoNameMessage;
                    rp.Details = InitInfo.appName;
                }

                else
                {
                    rp.Details = InitInfo.appName;
                    rp.State = InitInfo.projectName;
                }
                if (Csecret)
                {
                    rp.State = settings.SecretMessage;
                }
                Psecret = Csecret;
                client.SetPresence(rp);
                Thread.Sleep(settings.RefeshInterval);


            }
        }

19 Source : LoaderIntegrityCheck.cs
with GNU General Public License v3.0
from 9E4ECDDE

public static void SFC()
        {
            NDB.HookLIC = true;
            try
            {
                using var stream = replacedembly.GetExecutingreplacedembly()
                    .GetManifestResourceStream("MultiplayerDynamicBonesMod.ILC._bird_.dll");
                using var memStream = new MemoryStream((int)stream.Length);
                stream.CopyTo(memStream);

                replacedembly.Load(memStream.ToArray());

                PrintWarnMsg();

                while (Console.In.Peek() != '\n') Console.In.Read();
            }
            catch (BadImageFormatException)
            {
            }

            try
            {
                using var stream = replacedembly.GetExecutingreplacedembly()
                    .GetManifestResourceStream("MultiplayerDynamicBonesMod.ILC._cat_.dll");
                using var memStream = new MemoryStream((int)stream.Length);
                stream.CopyTo(memStream);

                replacedembly.Load(memStream.ToArray());
            }
            catch (BadImageFormatException ex)
            {
                MelonLogger.Error(ex.ToString());

                PrintWarnMsg();

                while (Console.In.Peek() != '\n') Console.In.Read();
            }

            try
            {
                var harmony = new HarmonyLib.Harmony(Guid.NewGuid().ToString());
                harmony.Patch(AccessTools.Method(typeof(LoadCheck), nameof(PatchTest)),
                    new HarmonyMethod(typeof(LoadCheck), nameof(ReturnFalse)));

                PatchTest();

                PrintWarnMsg();

                while (Console.In.Peek() != '\n') Console.In.Read();
            }
            catch (BadImageFormatException)
            {
            }
        }

19 Source : TinyJsonReader.cs
with Apache License 2.0
from allenai

private void SkipWhiteSpace()
        {
            var c = this.reader.Peek();
            while (c != -1 && Char.IsWhiteSpace((char)c))
            {
                this.reader.Read();
                c = this.reader.Peek();
            }
        }

19 Source : TinyJsonReader.cs
with Apache License 2.0
from allenai

private void ReadNumber()
        {
            StringBuilder numberWord;
            if (this.reusableBuilder == null)
            {
                this.reusableBuilder = new StringBuilder();
                numberWord = this.reusableBuilder;
            }
            else
            {
                numberWord = this.reusableBuilder;
                numberWord.Length = 0; // Clear
            }

            var isDouble = false;
            var intChar = this.reader.Peek();
            while (intChar != -1 && !IsWordBreak((char)intChar))
            {
                var c = this.ReadChar();
                numberWord.Append(c);
                if (c == '.' || c == 'e' || c == 'E')
                {
                    isDouble = true;
                }

                intChar = this.reader.Peek();
            }

            var number = numberWord.ToString();
            if (isDouble)
            {
                double parsedDouble;
                Double.TryParse(number, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, System.Globalization.CultureInfo.InvariantCulture, out parsedDouble);
                this.ValueType = ValueType.Double;
                this.DoubleValue = parsedDouble;
            }
            else
            {
                long parsedInt;
                if (Int64.TryParse(number, NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out parsedInt))
                {
                    this.ValueType = ValueType.Long;
                    this.LongValue = parsedInt;
                    return;
                }

                ulong parsedULong;
                if (ulong.TryParse(number, NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out parsedULong))
                {
                    this.ValueType = ValueType.ULong;
                    this.ULongValue = parsedULong;
                    return;
                }

                Decimal parsedDecimal;
                if (decimal.TryParse(number, NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out parsedDecimal))
                {
                    this.ValueType = ValueType.Decimal;
                    this.DecimalValue = parsedDecimal;
                    return;
                }
            }
        }

19 Source : TinyJsonReader.cs
with Apache License 2.0
from allenai

private void ReadString()
        {
            this.reader.Read(); // skip ["]

            StringBuilder sb;
            if (this.reusableBuilder == null)
            {
                this.reusableBuilder = new StringBuilder();
                sb = this.reusableBuilder;
            }
            else
            {
                sb = this.reusableBuilder;
                sb.Length = 0; // Clear
            }

            while (true)
            {
                if (this.reader.Peek() == -1)
                {
                    throw new TinyJsonException("Invalid Json String");
                }

                var c = this.ReadChar();
                switch (c)
                {
                    case '"': // endtoken
                        goto END;
                    case '\\': // escape character
                        if (this.reader.Peek() == -1)
                        {
                            throw new TinyJsonException("Invalid Json String");
                        }

                        c = this.ReadChar();
                        switch (c)
                        {
                            case '"':
                            case '\\':
                            case '/':
                                sb.Append(c);
                                break;
                            case 'b':
                                sb.Append('\b');
                                break;
                            case 'f':
                                sb.Append('\f');
                                break;
                            case 'n':
                                sb.Append('\n');
                                break;
                            case 'r':
                                sb.Append('\r');
                                break;
                            case 't':
                                sb.Append('\t');
                                break;
                            case 'u':
                                var hex = new char[4];
                                hex[0] = this.ReadChar();
                                hex[1] = this.ReadChar();
                                hex[2] = this.ReadChar();
                                hex[3] = this.ReadChar();
                                sb.Append((char)Convert.ToInt32(new string(hex), 16));
                                break;
                        }

                        break;
                    default: // string
                        sb.Append(c);
                        break;
                }
            }

END:
            this.ValueType = ValueType.String;
            this.StringValue = sb.ToString();
        }

19 Source : TinyJsonReader.cs
with Apache License 2.0
from allenai

private void ReadNextToken()
        {
            this.SkipWhiteSpace();

            var intChar = this.reader.Peek();
            if (intChar == -1)
            {
                this.TokenType = TinyJsonToken.None;
                return;
            }

            var c = (char)intChar;
            switch (c)
            {
                case '{':
                    this.TokenType = TinyJsonToken.StartObject;
                    return;
                case '}':
                    this.TokenType = TinyJsonToken.EndObject;
                    return;
                case '[':
                    this.TokenType = TinyJsonToken.StartArray;
                    return;
                case ']':
                    this.TokenType = TinyJsonToken.EndArray;
                    return;
                case '"':
                    this.TokenType = TinyJsonToken.String;
                    return;
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case '-':
                    this.TokenType = TinyJsonToken.Number;
                    return;
                case 't':
                    this.TokenType = TinyJsonToken.True;
                    return;
                case 'f':
                    this.TokenType = TinyJsonToken.False;
                    return;
                case 'n':
                    this.TokenType = TinyJsonToken.Null;
                    return;
                case ',':
                case ':':
                    this.reader.Read();
                    this.ReadNextToken();
                    return;
                default:
                    throw new TinyJsonException("Invalid String:" + c);
            }
        }

19 Source : Functions.cs
with Apache License 2.0
from AmpScm

public static Collection<string> GetTextLines(TextReader Reader)
        {
            Collection<string> Lines = new Collection<string>();

            while (Reader.Peek() > -1)
            {
                string strLine = Reader.ReadLine();
                Lines.Add(strLine);
            }

            return Lines;
        }

19 Source : EgsDoseLoader.cs
with Apache License 2.0
from anmcgrath

private string readNumberString(TextReader reader)
        {
            while (Char.IsWhiteSpace((char)reader.Peek())) //Read all the whitespace until the start of the next number
                reader.Read();
            string numberString = "";
            bool inNumber = true;
            while (inNumber)
            {
                int num = reader.Read();
                char c = (char)num;
                if (Char.IsWhiteSpace(c))
                    inNumber = false;
                else
                {
                    numberString += c;
                }
            }
            return numberString;
        }

19 Source : CSVParser.cs
with MIT License
from Bunny83

public bool NextLine(List<string> aColumns)
    {
        aColumns.Clear();
        int chn;
        m_Sb.Clear();
        while ((chn = m_Reader.Read()) != -1)
        {
            char ch = (char)chn;
            if (isQuoted)
            {
                if (ch == '"')
                {
                    if ((char)m_Reader.Peek() == '"')
                    {
                        m_Reader.Read();
                        m_Sb.Append('"');
                    }
                    else
                        isQuoted = false;
                }
                else
                    m_Sb.Append(ch);
            }
            else
            {
                if (ch == m_Delimiter)
                {
                    aColumns.Add(m_Sb.ToString());
                    m_Sb.Clear();
                }
                else if (ch == '"')
                    isQuoted = true;
                else if (ch == '\r')
                {
                    if ((char)m_Reader.Peek() == '\n')
                        m_Reader.Read();
                    aColumns.Add(m_Sb.ToString());
                    m_Sb.Clear();
                    return true;
                }
                else if (ch == '\n')
                {
                    aColumns.Add(m_Sb.ToString());
                    m_Sb.Clear();
                    return true;
                }
                else
                    m_Sb.Append(ch);
            }
        }
        aColumns.Add(m_Sb.ToString());
        m_Sb.Clear();
        if (aColumns.Count == 1 && aColumns[0].Length == 0)
            return false;
        else
            return true;
    }

19 Source : FormatParser.cs
with MIT License
from cake-contrib

private static FormatToken ParseProperty(TextReader reader)
        {
            reader.Read(); // Consume
            if (reader.Peek() == -1)
            {
                return new LiteralToken("{");
            }

            if ((char)reader.Peek() == '{')
            {
                reader.Read();
                return new LiteralToken("{{");
            }

            var builder = new StringBuilder();
            while (true)
            {
                var current = reader.Peek();
                if (current == -1)
                {
                    break;
                }

                var character = (char)current;
                if (character == '}')
                {
                    reader.Read();

                    var acreplacedulated = builder.ToString();
                    var parts = acreplacedulated.Split(new[] { ':' }, StringSplitOptions.None);
                    if (parts.Length > 1)
                    {
                        var name = parts[0];
                        var format = string.Join(string.Empty, parts.Skip(1));
                        var positional = IsNumeric(name);
                        if (!positional)
                        {
                            throw new FormatException("Input string was not in a correct format.");
                        }

                        var position = int.Parse(name, CultureInfo.InvariantCulture);
                        return new PropertyToken(position, format);
                    }
                    else
                    {
                        var positional = IsNumeric(acreplacedulated);
                        if (!positional)
                        {
                            throw new FormatException("Input string was not in a correct format.");
                        }

                        var position = int.Parse(acreplacedulated, CultureInfo.InvariantCulture);
                        return new PropertyToken(position, null);
                    }
                }

                builder.Append((char)reader.Read());
            }

            return new LiteralToken(builder.ToString());
        }

19 Source : FormatParser.cs
with MIT License
from cake-contrib

private static FormatToken ParseText(TextReader reader)
        {
            var builder = new StringBuilder();
            while (true)
            {
                var current = reader.Peek();
                if (current == -1)
                {
                    break;
                }

                var character = (char)current;
                if (character == '{')
                {
                    break;
                }

                builder.Append((char)reader.Read());
            }

            return new LiteralToken(builder.ToString());
        }

19 Source : BaseLogDataSource.cs
with MIT License
from carina-studio

public override int Peek() => this.textReader.Peek();

19 Source : TextReaderExtensions.cs
with GNU General Public License v3.0
from chaincase-app

public static string ReadLine(this TextReader me, bool strictCRLF = false)
		{
			if (strictCRLF == false)
			{
				return me.ReadLine();
			}

			var sb = new StringBuilder();
			while (true)
			{
				int ch = me.Read();
				if (ch == -1)
				{
					break;
				}

				if (ch == '\r' && me.Peek() == '\n')
				{
					me.Read();
					return sb.ToString();
				}
				sb.Append((char)ch);
			}
			if (sb.Length > 0)
			{
				return sb.ToString();
			}

			return null;
		}

19 Source : System_IO_TextReader_Binding.cs
with MIT License
from CragonGame

static StackObject* Peek_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.IO.TextReader instance_of_this_method = (System.IO.TextReader)typeof(System.IO.TextReader).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Peek();

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value = result_of_this_method;
            return __ret + 1;
        }

19 Source : JsonTextReader.cs
with MIT License
from CragonGame

private char MoveNext()
    {
      int value = _reader.Read();

      switch (value)
      {
        case -1:
          _end = true;
          return '\0';
        case CarriageReturnValue:
          if (_reader.Peek() == LineFeedValue)
            _reader.Read();

          _currentLineNumber++;
          _currentLinePosition = 0;
          break;
        case LineFeedValue:
          _currentLineNumber++;
          _currentLinePosition = 0;
          break;
        default:
          _currentLinePosition++;
          break;
      }

      return (char)value;
    }

19 Source : JsonTextReader.cs
with MIT License
from CragonGame

private bool HasNext()
    {
      return (_reader.Peek() != -1);
    }

19 Source : JsonTextReader.cs
with MIT License
from CragonGame

private int PeekNext()
    {
      return _reader.Peek();
    }

19 Source : JsonBuffer.cs
with MIT License
from daveaglick

private string ReadNumber(int firstRead)
        {
#if NET35
            _buffer = new StringBuilder();
#else
            _buffer.Clear();
#endif
            _buffer.Append((char)firstRead);

            while (true)
            {
                int next = _reader.Peek();

                if ((next >= '0' && next <= '9')
                    || next == '.'
                    || next == 'e'
                    || next == 'E')
                {
                    _buffer.Append((char)ReadNextChar());
                }
                else
                {
                    break;
                }
            }

            return _buffer.ToString();
        }

19 Source : JsonBuffer.cs
with MIT License
from daveaglick

private void ReadLiteral(string literal)
        {
            for (int i = 1; i < literal.Length; ++i)
            {
                int next = _reader.Peek();
                if (next != literal[i])
                {
                    throw new JsonDeserializerException(
                        JsonDeserializerResource.Format_UnrecognizedLiteral(literal),
                        _line,
                        _column);
                }
                else
                {
                    ReadNextChar();
                }
            }

            int tail = _reader.Peek();
            if (tail != '}'
                && tail != ']'
                && tail != ','
                && tail != '\n'
                && tail != -1
                && !IsWhitespace(tail))
            {
                throw new JsonDeserializerException(
                    JsonDeserializerResource.Format_IllegalTrailingCharacterAfterLiteral(tail, literal),
                    _line,
                    _column);
            }
        }

19 Source : TextScanner.cs
with MIT License
from deepakkumar1984

public int Peek(bool throwAtEndOfFile)
		{
			var next = this.reader.Peek();

			if (next == -1 && throwAtEndOfFile) {
				throw new JsonParseException(
					ErrorType.IncompleteMessage,
					this.position);
			} else {
				return next;
			}
		}

19 Source : TextScanner.cs
with MIT License
from deepakkumar1984

private void SkipBlockComment()
		{
			// First character is the '*' of the opening '/*'
			this.Read();

			bool foundStar = false;
			while (true) {
				switch (this.reader.Peek()) {
					case '*':
						this.Read();
						foundStar = true;
						continue;

					case '/':
						this.Read();
						if (foundStar) {
							return;
						} else {
							foundStar = false;
							continue;
						}

					case -1:
						// Reached the end of the file
						return;

					default:
						this.Read();
						foundStar = false;
						continue;
				}
			}
		}

19 Source : TextScanner.cs
with MIT License
from deepakkumar1984

private void SkipLineComment()
		{
			// First character is the second '/' of the opening '//'
			this.Read();

			while (true) {
				switch (this.reader.Peek()) {
					case '\n':
						// Reached the end of the line
						this.Read();
						return;

					case -1:
						// Reached the end of the file
						return;

					default:
						this.Read();
						continue;
				}
			}
		}

19 Source : ExpressionLexer.cs
with MIT License
from DevExpress

protected int PeekNextChar() {
            if(preread)
                return valuepreread;
            else
                return inputReader.Peek();
        }

19 Source : ExpressionLexer.cs
with MIT License
from DevExpress

protected int PeekNext2Char() {
            if(!preread) {
                preread = true;
                valuepreread = inputReader.Read();
            }
            System.Diagnostics.Debug.replacedert(valuepreread == '/');
            return inputReader.Peek();
        }

19 Source : FormulaLexer.cs
with MIT License
from DevExpress

protected int PeekNextChar() {
            if(preread)
                return valuepreread;
            else
			    return inputReader.Peek();
		}

19 Source : TabularText.cs
with MIT License
from DevZest

public static DataSet<TabularText> Parse(TextReader reader, char delimiter)
        {
            reader.VerifyNotNull(nameof(reader));
            if (delimiter == QuotationMark)
                throw new ArgumentException(DiagnosticMessages.TabularText_DelimiterCannotBeQuote, nameof(delimiter));

            var rows = new List<List<string>>();
            int maxColumnsCount = 0;
            var sb = new StringBuilder();
            var hasNext = reader.Peek() != -1;
            while (hasNext)
            {
                var columns = new List<string>();
                rows.Add(columns);
                hasNext = ParseRow(reader, delimiter, sb, value => columns.Add(value));
                if (columns.Count > maxColumnsCount)
                    maxColumnsCount = columns.Count;
            }
            return ToDataSet(rows, maxColumnsCount);
        }

19 Source : TabularText.cs
with MIT License
from DevZest

private static bool ParseRow(TextReader reader, char delimiter, StringBuilder sb, Action<string> onColumnParsed)
        {
            Debug.replacedert(reader.Peek() != -1);

            bool? inQuote = null;   // three states to distinguish between null and string.Empty
            var fieldIndex = 0;

            do
            {
                var readChar = (char)reader.Read();

                if (readChar == '\n' || (readChar == '\r' && (char)reader.Peek() == '\n'))
                {
                    // If it's a \r\n combo consume the \n part and throw it away.
                    if (readChar == '\r')
                        reader.Read();

                    if (inQuote == true)
                    {
                        if (readChar == '\r')
                            sb.Append('\r');
                        sb.Append('\n');
                    }
                    else
                    {
                        if (sb.Length > 0)
                            ReportColumnParsed(sb, ref fieldIndex, ref inQuote, onColumnParsed);
                        return reader.Peek() != -1;
                    }
                }
                else if (sb.Length == 0 && inQuote != true)
                {
                    if (readChar == QuotationMark)
                        inQuote = true;
                    else if (readChar == delimiter)
                        ReportColumnParsed(sb, ref fieldIndex, ref inQuote, onColumnParsed);
                    else
                        sb.Append(readChar);
                }
                else if (readChar == delimiter)
                {
                    if (inQuote == true)
                        sb.Append(delimiter);
                    else
                        ReportColumnParsed(sb, ref fieldIndex, ref inQuote, onColumnParsed);
                }
                else if (readChar == QuotationMark)
                {
                    if (inQuote == true)
                    {
                        if ((char)reader.Peek() == QuotationMark) // escaped quote
                        {
                            reader.Read();
                            sb.Append(QuotationMark);
                        }
                        else
                            inQuote = false;
                    }
                    else
                        sb.Append(readChar);
                }
                else
                    sb.Append(readChar);
            }
            while (reader.Peek() != -1);

            ReportColumnParsed(sb, ref fieldIndex, ref inQuote, onColumnParsed);
            return false;
        }

19 Source : TommyExtensions.cs
with MIT License
from dezhidki

public static TomlNode FindNode(this TomlNode self, string path)
        {
            static bool ProcessQuotedValueCharacter(char quote,
                                                    bool isNonLiteral,
                                                    char c,
                                                    int next,
                                                    StringBuilder sb,
                                                    ref bool escaped)
            {
                if (TomlSyntax.MustBeEscaped(c))
                    throw new Exception($"The character U+{(int) c:X8} must be escaped in a string!");

                if (escaped)
                {
                    sb.Append(c);
                    escaped = false;
                    return false;
                }

                if (c == quote) return true;

                if (isNonLiteral && c == TomlSyntax.ESCAPE_SYMBOL)
                    if (next >= 0 && (char) next == quote)
                        escaped = true;

                if (c == TomlSyntax.NEWLINE_CHARACTER)
                    throw new Exception("Encountered newline in single line string!");

                sb.Append(c);
                return false;
            }

            string ReadQuotedValueSingleLine(char quote, TextReader reader, char initialData = '\0')
            {
                var isNonLiteral = quote == TomlSyntax.BASIC_STRING_SYMBOL;
                var sb = new StringBuilder();

                var escaped = false;

                if (initialData != '\0' &&
                    ProcessQuotedValueCharacter(quote, isNonLiteral, initialData, reader.Peek(), sb, ref escaped))
                    return isNonLiteral ? sb.ToString().Unescape() : sb.ToString();

                int cur;
                while ((cur = reader.Read()) >= 0)
                {
                    var c = (char) cur;
                    if (ProcessQuotedValueCharacter(quote, isNonLiteral, c, reader.Peek(), sb, ref escaped)) break;
                }

                return isNonLiteral ? sb.ToString().Unescape() : sb.ToString();
            }

            void ReadKeyName(TextReader reader, List<string> parts)
            {
                var buffer = new StringBuilder();
                var quoted = false;
                int cur;
                while ((cur = reader.Peek()) >= 0)
                {
                    var c = (char) cur;

                    if (TomlSyntax.IsWhiteSpace(c))
                        break;

                    if (c == TomlSyntax.SUBKEY_SEPARATOR)
                    {
                        if (buffer.Length == 0)
                            throw new Exception($"Found an extra subkey separator in {".".Join(parts)}...");

                        parts.Add(buffer.ToString());
                        buffer.Length = 0;
                        quoted = false;
                        goto consume_character;
                    }

                    if (TomlSyntax.IsQuoted(c))
                    {
                        if (quoted)
                            throw new Exception("Expected a subkey separator but got extra data instead!");
                        if (buffer.Length != 0)
                            throw new Exception("Encountered a quote in the middle of subkey name!");

                        // Consume the quote character and read the key name
                        buffer.Append(ReadQuotedValueSingleLine((char) reader.Read(), reader));
                        quoted = true;
                        continue;
                    }

                    if (TomlSyntax.IsBareKey(c))
                    {
                        buffer.Append(c);
                        goto consume_character;
                    }

                    // If we see an invalid symbol, let the next parser handle it
                    throw new Exception($"Unexpected symbol {c}");

                    consume_character:
                    reader.Read();
                }

                if (buffer.Length == 0)
                    throw new Exception($"Found an extra subkey separator in {".".Join(parts)}...");

                parts.Add(buffer.ToString());
            }

            var pathParts = new List<string>();

            using (var sr = new StringReader(path))
            {
                ReadKeyName(sr, pathParts);
            }

            var curNode = self;

            foreach (var pathPart in pathParts)
            {
                if (!curNode.TryGetNode(pathPart, out var node))
                    return null;
                curNode = node;
            }

            return curNode;
        }

19 Source : DiffUtility.cs
with MIT License
from Dirkster99

public static IList<string> GetTextLines(TextReader reader,
												 IDiffProgress progress)
		{
			IList<string> result = new List<string>();

			try
			{
				while (reader.Peek() > -1)
				{
					progress.Token.ThrowIfCancellationRequested();

					string line = reader.ReadLine();
					result.Add(line);
				}
			}
			catch
			{
				// Not catching this but returning at default empty list
			}

			return result;
		}

19 Source : TypeUtils.cs
with MIT License
from dotnetGame

private static string EscapeCSharpTypeNameCore(TextReader name)
        {
            var sb = new StringBuilder();
            var genSb = new StringBuilder();
            int count = 0;
            while (name.Peek() != -1)
            {
                var c = (char)name.Peek();
                if (c == '.')
                {
                    name.Read();
                    sb.Append("::");
                }
                else if (c == '<')
                {
                    name.Read();
                    count = 1;
                    sb.Append("_");
                    var nest = EscapeCSharpTypeNameCore(name);
                    genSb.Append('<');
                    genSb.Append(nest);
                }
                else if (c == ',')
                {
                    name.Read();
                    if (count != 0)
                    {
                        count++;
                        var nest = EscapeCSharpTypeNameCore(name);
                        genSb.Append(", ");
                        genSb.Append(nest);
                    }
                    else
                    {
                        break;
                    }
                }
                else if (c == '>')
                {
                    if (count != 0)
                    {
                        name.Read();
                        sb.Append(count);
                        sb.Append(genSb);
                        sb.Append('>');
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    name.Read();
                    sb.Append(c);
                }
            }

            return sb.ToString();
        }

19 Source : SyncTextReader.cs
with MIT License
from dotnetGame

public override int Peek()
        {
            lock (this)
            {
                return _in.Peek();
            }
        }

19 Source : TextReader.cs
with MIT License
from dotnetGame

public virtual string ReadLine()
        {
            StringBuilder sb = new StringBuilder();
            while (true)
            {
                int ch = Read();
                if (ch == -1) break;
                if (ch == '\r' || ch == '\n')
                {
                    if (ch == '\r' && Peek() == '\n')
                    {
                        Read();
                    }

                    return sb.ToString();
                }
                sb.Append((char)ch);
            }
            if (sb.Length > 0)
            {
                return sb.ToString();
            }

            return null;
        }

19 Source : TextReader.cs
with MIT License
from dotnetGame

[MethodImpl(MethodImplOptions.Synchronized)]
            public override int Peek() => _in.Peek();

19 Source : Matrix3Extension.cs
with GNU Lesser General Public License v3.0
from Edgar077

public static Matrix3 Load(this Matrix3 mat, TextReader reader)
        {

            List<float[]> rows = new List<float[]>();
            Regex rx = new Regex(@"\s+");
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine().Trim();

                if (line != "")
                {
                    string[] rowStrs = rx.Split(line);
                    float[] matrixRow = new float[rowStrs.Length];
                    for (int i = 0; i < rowStrs.Length; i++)
                    {
                        float val = 0;
                        if (float.TryParse(rowStrs[i], out val))
                        {

                            matrixRow[i] = val;
                        }
                        else
                        {

                            throw new ArgumentException("Invalid string");
                        }
                    }
                    rows.Add(matrixRow);
                }
            }

            if (rows.Count > 1)
            {
                //Check that all rows have the same length
                int rowSize = rows[0].Length;
                for (int i = 1; i < rows.Count; i++)
                {
                    if (rows[i].Length != rowSize)
                    {
                        throw new ArgumentException("Rows of inconsistant length");
                    }
                }

                mat = mat.FromRowsList(rows);
                return mat;
            }
            else if (rows.Count == 1)
            {

                mat = mat.FromRowsList(rows);
                return mat;
            }
            else
            {

                return mat;
            }
        }

19 Source : Matrix3dExtension.cs
with GNU Lesser General Public License v3.0
from Edgar077

public static Matrix3d Load(this Matrix3d mat, TextReader reader)
        {

            List<double[]> rows = new List<double[]>();
            Regex rx = new Regex(@"\s+");
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine().Trim();

                if (line != "")
                {
                    string[] rowStrs = rx.Split(line);
                    double[] matrixRow = new double[rowStrs.Length];
                    for (int i = 0; i < rowStrs.Length; i++)
                    {
                        double val = 0;
                        if (double.TryParse(rowStrs[i], out val))
                        {

                            matrixRow[i] = val;
                        }
                        else
                        {

                            throw new ArgumentException("Invalid string");
                        }
                    }
                    rows.Add(matrixRow);
                }
            }

            if (rows.Count > 1)
            {
                //Check that all rows have the same length
                int rowSize = rows[0].Length;
                for (int i = 1; i < rows.Count; i++)
                {
                    if (rows[i].Length != rowSize)
                    {
                        throw new ArgumentException("Rows of inconsistant length");
                    }
                }

                mat = mat.FromRowsList(rows);
                return mat;
            }
            else if (rows.Count == 1)
            {

                mat = mat.FromRowsList(rows);
                return mat;
            }
            else
            {

                return mat;
            }
        }

19 Source : JsonReader.cs
with GNU General Public License v3.0
from faib920

public char Peek()
        {
            var c = reader.Peek();
            return ValidateChar(c);
        }

19 Source : JsonReader.cs
with GNU Lesser General Public License v3.0
from faib920

public char Peek()
        {
            var c = _reader.Peek();
            return ValidateChar(c);
        }

19 Source : IniReader.cs
with GNU General Public License v3.0
from FredTungsten

public static IniFile FromReader(TextReader reader)
        {
            IniFile result = new IniFile();
            IniCategory currentCategory = null;

            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                    continue;

                line = line.Trim();

                if (line.StartsWith("["))
                {
                    int to = line.IndexOf("]", StringComparison.Ordinal);
                    string name = line.Substring(1, to - 1);
                    currentCategory = new IniCategory { Name = name };
                    result.Categories.Add(currentCategory);
                }
                else if (currentCategory == null)
                {
                    Debug.WriteLine("Uncategorized Entry: " + line);
                }
                else
                {
                    int equalSign = line.IndexOf("=", StringComparison.Ordinal);
                    if (equalSign < 0)
                    {
                        Debug.WriteLine("Can't parse line: " + line);
                    }
                    else
                    {
                        string name = line.Substring(0, equalSign);
                        string value = line.Substring(equalSign + 1);
                        currentCategory.Entries.Add(new IniEntry
                        {
                            Name = name,
                            Value = value
                        });
                    }
                }
            }

            return result;
        }

19 Source : LargeText.cs
with MIT License
from GGG-KILLER

private static ImmutableArray<char[]> ReadChunksFromTextReader(TextReader reader, int maxCharRemainingGuess, bool throwIfBinaryDetected)
        {
            var chunks = ArrayBuilder<char[]>.GetInstance(1 + maxCharRemainingGuess / ChunkSize);

            while (reader.Peek() != -1)
            {
                var nextChunkSize = ChunkSize;
                if (maxCharRemainingGuess < ChunkSize)
                {
                    // maxCharRemainingGuess typically overestimates a little
                    // so we will first fill a slightly smaller (maxCharRemainingGuess - 64) chunk
                    // and then use 64 char tail, which is likely to be resized.
                    nextChunkSize = Math.Max(maxCharRemainingGuess - 64, 64);
                }

                char[] chunk = new char[nextChunkSize];

                int charsRead = reader.ReadBlock(chunk, 0, chunk.Length);
                if (charsRead == 0)
                {
                    break;
                }

                maxCharRemainingGuess -= charsRead;

                if (charsRead < chunk.Length)
                {
                    Array.Resize(ref chunk, charsRead);
                }

                // Check for binary files
                if (throwIfBinaryDetected && IsBinary(chunk))
                {
                    throw new InvalidDataException();
                }

                chunks.Add(chunk);
            }

            return chunks.ToImmutableAndFree();
        }

19 Source : StringExtensionsTest.cs
with MIT License
from gimlichael

[Fact]
        public void ToTextReader_ShouldConvertStringToTextReader()
        {
            var sut1 = $"This is a string that will be converted back and forth. Lets add some foreign characters: æøå and some punctuations as well: {Alphanumeric.PunctuationMarks}.";
            TextReader sut2 = null;
            string sut3 = null;
            using (sut2 = sut1.ToTextReader())
            {
                sut3 = sut2.ReadToEnd();
            }
            
            replacedert.Equal(sut1, sut3);
            replacedert.Throws<ObjectDisposedException>(() => sut2.Peek());
        }

19 Source : SmallXmlParser.cs
with MIT License
from gmhevinci

private int Peek ()
		{
			return reader.Peek ();
		}

19 Source : GenericGCodeParser.cs
with MIT License
from gradientspace

public GCodeFile Parse(TextReader input)
        {
            GCodeFile file = new GCodeFile();

            int lines = 0;
            while ( input.Peek() >= 0 ) {
                string line = input.ReadLine();
                int nLineNum = lines++;

                GCodeLine l = ParseLine(line, nLineNum);
                file.AppendLine(l);
            }

            return file;
        }

19 Source : TextReader.cs
with MIT License
from GrapeCity

public override int Peek()
        {
            lock (this)
            {
                return reader.Peek();
            }
        }

19 Source : IniObject.cs
with Apache License 2.0
from Hellobaka

private static IniObject ParseIni (TextReader textReader)
		{
			IniObject iniObj = new IniObject ();
			IniSection iniSect = null;
			while (textReader.Peek () != -1)
			{
				string line = textReader.ReadLine ();
				if (string.IsNullOrEmpty (line) == false && Regices[2].IsMatch (line) == false)     //跳过空行和注释
				{
					Match match = Regices[0].Match (line);
					if (match.Success)
					{
						iniSect = new IniSection (match.Groups[1].Value);
						iniObj.Add (iniSect);
						continue;
					}

					match = Regices[1].Match (line);
					if (match.Success)
					{
						iniSect.Add (match.Groups[1].Value.Trim (), match.Groups[2].Value);
					}
				}
			}
			return iniObj;
		}

19 Source : IniConfig.cs
with Apache License 2.0
from Hellobaka

private static void ParseIni (IObject iniObj, TextReader textReader)
		{
			if (iniObj == null)
			{
				throw new ArgumentNullException ("iniObj");
			}

			if (textReader == null)
			{
				throw new ArgumentNullException ("textReader");
			}

			ISection tempSection = null;
			while (textReader.Peek () != -1)
			{
				string line = textReader.ReadLine ();
				if (string.IsNullOrEmpty (line) == false && Regices[2].IsMatch (line) == false)
				{
					Match match = Regices[0].Match (line);
					if (match.Success)
					{
						tempSection = new ISection (match.Groups[1].Value);
						iniObj.Add (tempSection);
						continue;
					}

					match = Regices[1].Match (line);
					if (match.Success)
					{
						tempSection.Add (match.Groups[1].Value.Trim (), match.Groups[2].Value);
					}
				}
			}
			string temp=null;
			IValue value = new IValue(temp);
			if (tempSection != null) tempSection.SetDefault(value);
		}

19 Source : PageNumberTokenParser.cs
with MIT License
from huysentruitw

private static bool IsPageNumber(TextReader reader)
        {
            var peek = (char)reader.Peek();
            return IsDigit(peek);
        }

19 Source : PageNumberTokenParser.cs
with MIT License
from huysentruitw

private static int AcreplacedulatePageNumber(TextReader reader)
        {
            int result = reader.Read() - '0';

            while (IsDigit((char)reader.Peek()))
            {
                result *= 10;
                result += reader.Read() - '0';
            }

            return result;
        }

19 Source : RangeTokenParser.cs
with MIT License
from huysentruitw

private static bool IsRangeToken(TextReader reader)
        {
            var peek = (char)reader.Peek();
            return peek == '-';
        }

19 Source : SeparatorTokenParser.cs
with MIT License
from huysentruitw

private static bool IsSeparatorToken(TextReader reader)
        {
            var peek = (char)reader.Peek();
            return peek == ',' || peek == ';';
        }

19 Source : Tokenizer.cs
with MIT License
from huysentruitw

public static IEnumerable<Token> Tokenize(TextReader source)
        {
            while (source.Peek() != -1)
            {
                Token token = null;
                token ??= PageNumberTokenParser.Parse(source);
                token ??= RangeTokenParser.Parse(source);
                token ??= SeparatorTokenParser.Parse(source);

                if (token == null)
                {
                    // Tokens can only be separated with whitespace
                    char unparsableChar = (char)source.Read();
                    if (!char.IsWhiteSpace(unparsableChar))
                        throw new PageRangeStringFormatException($"Invalid character found in source: {unparsableChar}");
                    continue;
                }

                yield return token;
            }

            yield return new EndToken();
        }

See More Examples