def string
str = ""
count = 1
while count != 0
@buffer.ready_token(false, false)
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("")
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