Skip to content

Commit 1633082

Browse files
committed
Adding Converts for CosString
1 parent 55f75cb commit 1633082

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/CosDoc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ attach_object(doc::CosDocImpl, indstm::CosIndirectObject{CosStream})=
178178

179179
function attach_object(doc::CosDocImpl, stm::CosStream)
180180
tmpfile = get(get(stm, CosName("F")))
181-
push!(doc.tmpfiles, tmpfile)
181+
push!(doc.tmpfiles, String(tmpfile))
182182
return nothing
183183
end
184184

src/CosObjStream.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
function read_object_info_from_stm(stm::CosStream,
9393
oids::Vector{Int}, oloc::Vector{Int}, n::Int, first::Int)
9494
filename = get(stm, CosName("F"))
95-
io = util_open(filename |> get,"r")
95+
io = util_open(String(filename),"r")
9696
try
9797
for i = 1:n
9898
val = readuntil(io, ' ')
@@ -123,7 +123,7 @@ end
123123
function cosObjectStreamGetObject(stm::CosObjectStream,
124124
ref::CosNullType, loc::Int)
125125
filename = get(stm, CosName("F"))
126-
io = util_open(filename |> get,"r")
126+
io = util_open(String(filename),"r")
127127
ps = BufferedInputStream(io)
128128
try
129129
seek(ps, stm.oloc[loc+1])

src/CosObject.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,28 @@ get(o::CosIndirectObject) = get(o.obj)
5757
end
5858

5959
@compat struct CosXString <: CosString
60-
val::String
61-
CosXString(str::String)=new(str)
60+
val::Vector{UInt8}
61+
CosXString(arr::Vector{UInt8})=new(arr)
6262
end
6363

64+
Base.convert(::Type{Vector{UInt8}}, xstr::CosXString)=
65+
(xstr.val |> String |> hex2bytes)
66+
67+
Base.convert(::Type{String}, xstr::CosXString)=
68+
String(convert(Vector{UInt8},xstr))
69+
70+
6471
@compat struct CosLiteralString <: CosString
65-
val::String
66-
CosLiteralString(str::String)=new(str)
72+
val::Vector{UInt8}
73+
CosLiteralString(arr::Vector{UInt8})=new(arr)
6774
end
6875

76+
CosLiteralString(str::AbstractString)=CosLiteralString(transcode(UInt8,str))
77+
78+
Base.convert(::Type{Vector{UInt8}}, str::CosLiteralString)=str.val
79+
80+
Base.convert(::Type{String}, str::CosLiteralString)=String(str.val)
81+
6982
@compat mutable struct CosArray <: CosObject
7083
val::Array{CosObject,1}
7184
function CosArray(arr::Array{T,1} where {T<:CosObject})

src/CosReader.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function parse_string(ps::BufferedInputStream)
173173
paren_cnt-=1
174174
else
175175
chomp_space!(ps)
176-
return CosLiteralString(String(b))
176+
return CosLiteralString(b)
177177
end
178178
end
179179
push!(b, c)
@@ -196,7 +196,7 @@ function parse_xstring(ps::BufferedInputStream)
196196
push!(b, NULL)
197197
end
198198
chomp_space!(ps)
199-
return CosXString(String(b))
199+
return CosXString(b)
200200
elseif !ispdfxdigit(c)
201201
_error(E_UNEXPECTED_CHAR, ps)
202202
else

src/CosStream.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function cosStreamRemoveFilters(stm::CosObject)
7777
data = read(bufstm)
7878
close(bufstm)
7979
filename = get(stm, CosName("F"))
80-
write(filename |> get, data)
80+
write(filename |> get |> String, data)
8181
set!(stm, CosName("FFilter"),CosNull)
8282
end
8383
return stm
@@ -92,7 +92,7 @@ function decode(stm::CosObject)
9292
filters = get(stm, CosName("FFilter"))
9393
parms = get(stm, CosName("FDecodeParms"))
9494

95-
io = (util_open(filename |> get, "r") |> BufferedInputStream)
95+
io = (util_open(String(filename), "r") |> BufferedInputStream)
9696

9797
return decode_filter(io, filters, parms)
9898
end

0 commit comments

Comments
 (0)