示例#1
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self)
        {
            self.AssertOpenedForReading();

            if (!self.PreserveEndOfLines)
            {
                MutableString result = MutableString.CreateBinary();
                int           c;
                while ((c = self.ReadByteNormalizeEoln()) != -1)
                {
                    result.Append((byte)c);
                }
                return(result);
            }
            else
            {
                // TODO: change this once Binary mutable string uses resizable byte[] instead of List<byte>
                return(MutableString.CreateBinary(ReadAllBytes(self)));
            }
        }
示例#2
0
 public MutableString ReadLineOrParagraph(MutableString separator, RubyEncoding /*!*/ encoding, bool preserveEndOfLines)
 {
     if (separator == null)
     {
         var result = MutableString.CreateBinary();
         return(AppendBytes(result, Int32.MaxValue, preserveEndOfLines) == 0 ? null : result);
     }
     else if (separator.StartsWith('\n') && separator.GetLength() == 1)
     {
         return(ReadLine(encoding, preserveEndOfLines));
     }
     else if (separator.IsEmpty)
     {
         return(ReadParagraph(encoding, preserveEndOfLines));
     }
     else
     {
         return(ReadLine(separator, encoding, preserveEndOfLines));
     }
 }
示例#3
0
        public void Set(MutableString /*!*/ pattern, RubyRegexOptions options)
        {
            ContractUtils.RequiresNotNull(pattern, "pattern");

            // RubyRegexOptions.Once is only used to determine how the Regexp object should be created and cached.
            // It is not a property of the final object. /foo/ should compare equal with /foo/o.
            _options = options & ~RubyRegexOptions.Once;

            RubyEncoding encoding = RubyEncoding.GetRegexEncoding(options);

            if (encoding != null || pattern.Encoding.IsKCoding)
            {
                _pattern = MutableString.CreateBinary(pattern.ToByteArray(), encoding ?? RubyEncoding.Binary).Freeze();
            }
            else
            {
                _pattern = pattern.PrepareForCharacterRead().Clone().Freeze();
            }

            TransformPattern(encoding, options & RubyRegexOptions.EncodingMask);
        }
示例#4
0
文件: IoOps.cs 项目: ltwlf/IronSP
        public static MutableString Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            self.RequireReadable();
            if (bytes < 0)
            {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer == null)
            {
                buffer = MutableString.CreateBinary();
            }
            else
            {
                buffer.Clear();
            }

            int bytesRead = self.AppendBytes(buffer, bytes);

            return((bytesRead == 0 && bytes != 0) ? null : buffer);
        }
示例#5
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            self.AssertOpenedForReading();
            if (self.IsEndOfStream())
            {
                return(null);
            }

            if (buffer == null)
            {
                buffer = MutableString.CreateBinary();
            }

            buffer.Clear();
            if (!self.PreserveEndOfLines)
            {
                for (int i = 0; i < bytes; ++i)
                {
                    int c = self.ReadByteNormalizeEoln();
                    if (c == -1)
                    {
                        return(buffer);
                    }
                    else
                    {
                        buffer.Append((byte)c);
                    }
                }
            }
            else
            {
                var fixedBuffer = new byte[bytes];
                bytes = self.ReadBytes(fixedBuffer, 0, bytes);
                buffer.Append(fixedBuffer, 0, bytes);
            }

            return(buffer);
        }
示例#6
0
        public MutableString ReadLine(MutableString /*!*/ separator, RubyEncoding /*!*/ encoding, bool preserveEndOfLines, int limit)
        {
            // TODO: limit

            int b = ReadByteNormalizeEoln(preserveEndOfLines);

            if (b == -1)
            {
                return(null);
            }

            int           separatorOffset = 0;
            int           separatorLength = separator.GetByteCount();
            MutableString result          = MutableString.CreateBinary(encoding);

            do
            {
                result.Append((byte)b);

                if (b == separator.GetByte(separatorOffset))
                {
                    if (separatorOffset == separatorLength - 1)
                    {
                        break;
                    }
                    separatorOffset++;
                }
                else if (separatorOffset > 0)
                {
                    separatorOffset = 0;
                }

                b = ReadByteNormalizeEoln(preserveEndOfLines);
            } while (b != -1);

            return(result);
        }
示例#7
0
 public override MutableString /*!*/ GetPattern()
 {
     return(MutableString.CreateBinary(_pattern));
 }
示例#8
0
 public MutableStringStream()
     : this(MutableString.CreateBinary())
 {
 }