当前位置: 首页>>代码示例>>C#>>正文


C# TextReader.ReadBlock方法代码示例

本文整理汇总了C#中System.IO.TextReader.ReadBlock方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.ReadBlock方法的具体用法?C# TextReader.ReadBlock怎么用?C# TextReader.ReadBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.TextReader的用法示例。


在下文中一共展示了TextReader.ReadBlock方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseText

        public List<string> ParseText(TextReader pReader)
        {
            result.Clear();

            int	count = 0;
            do
            {
                count = pReader.ReadBlock(buffer, 0, BUFFER_SIZE);
                for (int i = 0; i < count; ++i)
                {
                    char c = buffer[i];
                    if (char.IsWhiteSpace(c))
                    {
                        ParseWhitespace();
                    }
                    else if (Contains(punctuation, c))
                    {
                        ParsePunctuation(c);
                    }
                    else if (char.IsLetterOrDigit(c))
                    {
                        ParseLetter(c);
                    }else{
                        ParseLetter(c);
                    }
                }

            } while(count == BUFFER_SIZE);
            return result;
        }
开发者ID:substans,项目名称:MarkovChainFoolery,代码行数:30,代码来源:WordTokenizer.cs

示例2: Process

 public void Process(string source, string target, string config,
                     TextReader input, TextWriter output)
 {
     Reader reader =
         delegate (IntPtr data)
         {
             int c = input.ReadBlock(chars, 0, charSize);
             int b = encoding.GetBytes(chars, 0, c, bytes, 0);
             Marshal.Copy(bytes, 0, data, b);
             return b;
         };
     Writer writer =
         delegate (IntPtr data, int length)
         {
             if (length > 0) {
                 Marshal.Copy(data, bytes, 0, length);
                 int c = encoding.GetChars(bytes, 0, length, chars, 0);
                 output.Write(chars, 0, c);
             }
         };
     string err = Native.pandoc(byteSize,
                                Bytes(source),
                                Bytes(target),
                                Bytes(config),
                                reader,
                                writer);
     if (err != null) {
         throw new PandocException(err);
     }
 }
开发者ID:t0yv0,项目名称:libpandoc-dotnet,代码行数:30,代码来源:Pandoc.cs

示例3: Parse

 public CompilationUnit Parse(TextReader reader)
 {
     // TODO: can we optimize this to avoid the text->stream->text roundtrip?
     using (MemoryStream stream = new MemoryStream ()) {
         StreamWriter w = new StreamWriter(stream, Encoding.UTF8);
         char[] buffer = new char[2048];
         int read;
         while ((read = reader.ReadBlock(buffer, 0, buffer.Length)) > 0)
             w.Write(buffer, 0, read);
         w.Flush(); // we can't close the StreamWriter because that would also close the MemoryStream
         stream.Position = 0;
         return Parse(stream);
     }
 }
开发者ID:HEskandari,项目名称:ILSpy,代码行数:14,代码来源:CSharpParser.cs

示例4: Texto

        public static string Texto(TextReader leitor)
        {
            char[] buffer = new char[140];
            StringBuilder builder = new StringBuilder("");

            leitor.ReadBlock(buffer, 0, 140);   //lê um bloco de 140 caracteres e coloca no buffer
                                                //foreach (var caracter in buffer)
                                                //show = show + caracter.ToString();

            foreach (char c in buffer)          //transforma o char[] em um construtor de strings
                builder.Append(c);
            //if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))

            return builder.ToString();          //retorna a string lida
        }
开发者ID:KyoZeus,项目名称:BuscaLogo,代码行数:15,代码来源:AutoPost.cs

示例5: Parse

        public virtual Text Parse(TextReader reader)
        {
            Text textResult = new Text();
            char[] buffer = new char[Bufferlength];
            StringBuilder builder = new StringBuilder(Bufferlength);

            int readCharsCount = 0;
            do
            {
                readCharsCount = reader.ReadBlock(buffer, 0, Bufferlength);
                if (readCharsCount <= 0) continue;

                builder.Append(buffer, 0, readCharsCount);
                int endIndex;
                textResult += ParseText(builder.ToString(), out endIndex);
                builder.Remove(0, endIndex + 1);
            } while (readCharsCount != 0);

            return textResult;
        }
开发者ID:SergeyKononovich,项目名称:EpamTraining,代码行数:20,代码来源:SimpleTextParser.cs

示例6: GetDiffTreeLine

        private static string GetDiffTreeLine(TextReader reader)
        {
            var sb = new StringBuilder();

            char[] block = new char[98];
            var bytesRead = reader.ReadBlock(block, 0, 98);
            if (bytesRead == 0)
            {
                return null;
            }
            else if (bytesRead != 98)
            {
                throw new Exception("Invalid input.");
            }

            var nullBytesLeft = 2;
            if (block[97] == 'C' || block[97] == 'R')
            {
                nullBytesLeft = 3;
            }

            sb.Append(block);

            while (nullBytesLeft > 0)
            {
                var currentByte = reader.Read();
                if (currentByte == -1)
                {
                    throw new Exception("Invalid input.");
                }
                else if (currentByte == 0)
                {
                    nullBytesLeft--;
                }

                sb.Append((char)currentByte);
            }

            return sb.ToString();
        }
开发者ID:EdwinTai,项目名称:git-tfs,代码行数:40,代码来源:GitChangeInfo.cs

示例7: ParseText

        public List<object> ParseText(TextReader pReader)
        {
            result.Clear();
            int	count = 0;
            do
            {
                count = pReader.ReadBlock(buffer, 0, BUFFER_SIZE);
                for (int i = 0; i < count; i++)
                {
                    char c = buffer[i];
                    if (escape)
                    {
                        switch (c)
                        {
                            case 't':
                                AddLetter('\t');
                            break;
                            case 'r':
                                AddLetter('\r');
                            break;
                            case 'n':
                                AddLetter('\n');
                            break;
                            case 'b':
                                AddLetter('\b');
                            break;
                            case 'f':
                                AddLetter('\f');
                            break;
                            case 'v':
                                AddLetter('\v');
                            break;
                            default:
                                AddLetter(c);
                            break;
                        }
                        escape = false;
                    }
                    else
                    {
                        switch (c)
                        {
                            case '{':
                            case '[':
                            case '}':
                            case ']':
                            case ':':
                            case ',': //Structural chars
                                if (insideQuotes)
                                {
                                    AddLetter(c);
                                }
                                else
                                {
                                    PushStringToken();
                                    AddLetter(c);
                                    PushStringToken();
                                }
                            break;
                            case '"': //Quotes, string start stop
                                if (insideQuotes)
                                {
                                    if (escape)
                                    {
                                        AddLetter(c);
                                    }
                                    else
                                    {
                                        PushStringDelimiter();
                                        insideQuotes = false;
                                    }
                                }
                                else
                                {
                                    PushStringDelimiter();
                                    insideQuotes = true;
                                }
                            break;
                            case '\'': //Whitespace and garbage
                            case '\f':
                            case '\v':
                            case '\b':
                            case '\r':
                            case '\n':
                            case ' ':
                            case '\t':
                                if (insideQuotes)
                                {
                                    AddLetter(c);
                                }
                            break;
                            case '\\':
                                if (insideQuotes)
                                {
                                    //don't add this letter, only escape next
                                    escape = true;
                                }
                            break;
                            default:
                                AddLetter(c);
//.........这里部分代码省略.........
开发者ID:substans,项目名称:JohJSON,代码行数:101,代码来源:Tokenizer.cs

示例8: FillBuffer

 ///<summary>
 ///根据context的上下文情况,填充segmentBuff 
 /// </summary>
 /// <returns>返回待分析的(有效的)字串长度</returns>
 private int FillBuffer(TextReader reader)
 {
     int readCount = 0;
     if (context.BuffOffset == 0)
     {
         //首次读取reader
         readCount = reader.ReadBlock(segmentBuff, 0, segmentBuff.Length);
     }
     else
     {
         int offset = context.Available - context.LastAnalyzed;
         if (offset > 0)
         {
             //最近一次读取的>最近一次处理的,将未处理的字串拷贝到segmentBuff头部
             Array.Copy(segmentBuff, context.LastAnalyzed, this.segmentBuff, 0, offset);
             readCount = offset;
         }
         //继续读取reader ,以onceReadIn - onceAnalyzed为起始位置,继续填充segmentBuff剩余的部分
         readCount += reader.Read(segmentBuff, offset, BUFF_SIZE - offset);
     }
     //记录最后一次从Reader中读入的可用字符长度
     context.Available = readCount;
     return readCount;
 }
开发者ID:mamboer,项目名称:IKAnalyzer.Net,代码行数:28,代码来源:IKSegmentation.cs

示例9: ReadString

        private static string ReadString(TextReader reader)
        {
            reader.Read();	// read '"'
            StringBuilder builder = new StringBuilder();
            bool isControl = false;
            while (reader.Peek()>=0)
            {
                char c = (char)reader.Read();
                if (isControl)
                {
                    switch (c)
                    {
                        case '"':
                            builder.Append('"');
                            break;
                        case '\\':
                            builder.Append('\\');
                            break;
                        case '/':
                            builder.Append('/');
                            break;
                        case 'b':
                            builder.Append('\b');
                            break;
                        case 'f':
                            builder.Append('\f');
                            break;
                        case 'n':
                            builder.Append('\n');
                            break;
                        case 'r':
                            builder.Append('\r');
                            break;
                        case 't':
                            builder.Append('\t');
                            break;
                        case 'u':
                            {
                                if (reader.ReadBlock(hexBuffer, 0, 4) < 4)
                                    throw new IOException("Invalid JSON format.");

                                string hexString = new string(hexBuffer);
                                long result = long.Parse(hexString, System.Globalization.NumberStyles.HexNumber);

                                char hexChar = (char)result;
                                builder.Append(hexChar);
                            }

                            break;
                        default:
                            throw new IOException("Invalid JSON format.");
                    }
                    isControl = false;
                }
                else
                {
                    if (c == '"')
                        break;
                    else if (c == '\\')
                    {
                        isControl = true;
                    }
                    else
                    {
                        builder.Append(c);
                    }
                }
            }
            return builder.ToString();
        }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:70,代码来源:JsonParser.cs

示例10: ReadEscapedCharacter

        /// <summary>
        /// Read an escaped character e.g. "\n". Must be performed after the backslash has been read.
        /// </summary>
        /// <param name="reader">The text reader.</param>
        /// <returns>The escaped character.</returns>
        private char ReadEscapedCharacter(TextReader reader)
        {
            char c;
            if (!reader.TryRead(out c))
                throw new Exception("Expected escape character");

            switch (c) {
            case '0':
                return '\0';
            case 't':
                return '\t';
            case 'r':
                return '\r';
            case 'n':
                return '\n';
            case 'x':
                char[] hexCode = new char[4];
                if (reader.ReadBlock(hexCode, 0, 4) != 4)
                    throw new Exception("Wrong format for escaped unicode character.");
                return (char)Int32.Parse(new string(hexCode), NumberStyles.AllowHexSpecifier);
            default:
                return c;
            }
        }
开发者ID:danidoedel,项目名称:OpenRCT2Launcher,代码行数:29,代码来源:IniConfiguration.cs

示例11: Preprocess

        public static void Preprocess(TextReader reader, TextWriter writer, IReadOnlyDictionary<string, string> values)
        {
            // $$ is the escape for a $, which we can just replicate in the algorithm by giving the empty replacement the known value
            var maximumKeyLength = values.Keys.Max<string, int?>(k => k.Length).GetValueOrDefault(0);
            char[] buffer = new char[Math.Max(4096, maximumKeyLength + 2)];

            int charsInBuffer = reader.ReadBlock(buffer, 0, buffer.Length);

            while (charsInBuffer != 0)
            {
                int indexOfDelimiter = Array.IndexOf(buffer, PreprocessorDelimiter, 0, charsInBuffer);

                if (indexOfDelimiter == -1)
                {
                    // If the buffer doesn't contain any delimiters, then we can immediately write it out and move on
                    writer.Write(buffer, 0, charsInBuffer);
                    charsInBuffer = reader.ReadBlock(buffer, 0, buffer.Length);
                }
                else
                {
                    // Write whatever is before the $ and advance up to the $
                    writer.Write(buffer, 0, indexOfDelimiter);
                    Advance(reader, buffer, ref charsInBuffer, charsToAdvance: indexOfDelimiter);

                    // Let's read in the token name
                    var token = new StringBuilder();
                    int position = 1;

                    while (true)
                    {
                        if (position == buffer.Length)
                        {
                            Advance(reader, buffer, ref charsInBuffer, buffer.Length);
                            position = 0;
                        }

                        // If at end, we'll want to fall through to the last case
                        var c = position < charsInBuffer ? buffer[position] : '\0';

                        if (c == PreprocessorDelimiter)
                        {
                            position++;

                            // Is it the escape case?
                            string value;
                            if (token.Length == 0)
                            {
                                writer.Write(PreprocessorDelimiter);
                            }
                            else if (values.TryGetValue(token.ToString(), out value))
                            {
                                writer.Write(value);
                            }
                            else
                            {
                                throw new ExceptionFromResource(nameof(Strings.UnspecifiedToken), PreprocessorDelimiter + token.ToString() + PreprocessorDelimiter);
                            }

                            break;
                        }
                        else if (IsTokenCharacter(c))
                        {
                            token.Append(c);
                            position++;
                        }
                        else
                        {
                            // The token ended prematurely, so we just treat it verbatim and write it out
                            writer.Write(PreprocessorDelimiter);
                            writer.Write(token);

                            break;
                        }
                    }

                    // Advance to the next position to start all over
                    Advance(reader, buffer, ref charsInBuffer, position);
                }
            }
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:80,代码来源:Preprocessor.cs

示例12: Advance

        private static void Advance(TextReader reader, char[] buffer, ref int charsInBuffer, int charsToAdvance)
        {
            Debug.Assert(charsToAdvance <= charsInBuffer);

            // Move the remaining characters in the buffer forward
            Array.Copy(sourceArray: buffer, sourceIndex: charsToAdvance, destinationArray: buffer, destinationIndex: 0, length: charsInBuffer - charsToAdvance);
            charsInBuffer -= charsToAdvance;
            charsInBuffer += reader.ReadBlock(buffer, charsInBuffer, buffer.Length - charsInBuffer);
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:9,代码来源:Preprocessor.cs

示例13: ReadChunksFromTextReader

        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 likley 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();
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:41,代码来源:LargeText.cs


注:本文中的System.IO.TextReader.ReadBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。