string (PDF::Reader::Parser)

    # File lib/pdf/reader/parser.rb, line 116
        def string
          str = ""
          count = 1

          while count != 0
            @buffer.ready_token(false, false)

            # find the first occurance of ( ) [ \ or ]
            #
            # I originally just used the regexp form of index(), but it seems to be
            # buggy on some OSX systems (returns nil when there is a match). This
            # version is more reliable and was suggested by Andrès Koetsier.
            #
            i = nil
            @buffer.raw.unpack("C*").each_with_index do |charint, idx|
              if [40, 41, 92].include?(charint)
                i = idx
                break
              end
            end

            if i.nil?
              str << @buffer.raw + "\n"
              @buffer.raw.replace("")
              # if a content stream opens a string, but never closes it, we'll
              # hit the end of the stream and still be appending stuff to the
              # string. bad! This check prevents a hard loop.
              raise MalformedPDFError, 'unterminated string in content stream' if @buffer.eof?
              next
            end

            str << @buffer.head(i, false)
            to_remove = 1

            case @buffer.raw[0, 1]
            when "("
              str << "("
              count += 1
            when ")"
              count -= 1
              str << ")" unless count == 0
            when "\\"
              to_remove = 2
              case @buffer.raw[1, 1]
              when ""   then to_remove = 1
              when "n"  then str << "\n"
              when "r"  then str << "\r"
              when "t"  then str << "\t"
              when "b"  then str << "\b"
              when "f"  then str << "\f"
              when "("  then str << "("
              when ")"  then str << ")"
              when "\\" then str << "\\"
              else
                if m = @buffer.raw.match(/^\\(\d{1,3})/)
                  to_remove = m[0].size
                  str << m[1].oct.chr
                end
              end
            end

            @buffer.head(to_remove, false)
          end
          str
        end