Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7776b4d

Browse files
Eliminate GeneralError, per review
1 parent d162df6 commit 7776b4d

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

‎src/iconv.jl‎

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,68 @@ export InvalidEncodingError, InvalidSequenceError, IncompleteSequenceError, ICon
1010

1111
abstract StringEncodingError
1212

13-
# General purpose error handling type, which supports variable number of arguments,
14-
# and can be extended to work with different locales
15-
16-
type GeneralError <: Exception
17-
errcls::UTF8String
18-
errmsg::UTF8String
19-
args
20-
GeneralError(class::AbstractString, msg::AbstractString, args...) =
21-
new(UTF8String(class), UTF8String(msg), args)
22-
end
23-
24-
function show(io::IO, exc::GeneralError)
25-
str = exc.errcls == "" ? exc.errmsg : string(exc.errcls, ": ", exc.errmsg)
26-
if contains(exc.errmsg, "<<")
27-
for i = 1:length(exc.args)
28-
str = replace(str, "<<$i>>", exc.args[i])
29-
end
30-
end
31-
print(io, str)
32-
end
33-
3413
# For now, don't display module name, maybe want it if this changes to StringEncoders
3514
const modulename = ""
3615

3716
# specified encodings are not supported
3817
type InvalidEncodingError <: StringEncodingError
39-
err::GeneralError
40-
InvalidEncodingError(args...) = new(GeneralError(modulename, "Conversion from <<1>> to <<2>> not supported by iconv implementation, check that specified encodings are correct", args...))
18+
mod::ByteString
19+
msg::ByteString
20+
args
21+
InvalidEncodingError(from, to) = new(modulename, "Conversion from <<1>> to <<2>> not supported by iconv implementation, check that specified encodings are correct", (from, to))
4122
end
4223

4324
# Encountered invalid byte sequence
4425
type InvalidSequenceError <: StringEncodingError
45-
err::GeneralError
46-
InvalidSequenceError(args...) = new(GeneralError(modulename, "Byte sequence 0x<<1>> is invalid in source encoding or cannot be represented in target encoding", args...))
26+
mod::ByteString
27+
msg::ByteString
28+
args
29+
InvalidSequenceError(seq) = new(modulename, "Byte sequence 0x<<1>> is invalid in source encoding or cannot be represented in target encoding", (seq,))
4730
end
4831

4932
# Input ended with incomplete byte sequence
5033
type IncompleteSequenceError <: StringEncodingError
51-
err::GeneralError
34+
mod::ByteString
35+
msg::ByteString
36+
args
5237
IncompleteSequenceError() =
53-
new(GeneralError(modulename, "Incomplete byte sequence at end of input"))
38+
new(modulename, "Incomplete byte sequence at end of input", ())
5439
end
5540

5641
type IConvError <: StringEncodingError
57-
err::GeneralError
58-
IConvError(func) = new(GeneralError(func, "<<1>> (<<2>>)", errno(), strerror(errno())))
42+
mod::ByteString
43+
msg::ByteString
44+
args
45+
IConvError(func) = new(func, "<<1>> (<<2>>)", (errno(), strerror(errno())))
5946
end
6047

6148
type OutputBufferError <: StringEncodingError
62-
err::GeneralError
49+
mod::ByteString
50+
msg::ByteString
51+
args
6352
OutputBufferError(func) =
64-
new(GeneralError(modulename, "Ran out of space in the output buffer"))
53+
new(modulename, "Ran out of space in the output buffer", ())
6554
end
6655

6756
type InvalidBytesError <: StringEncodingError
68-
err::GeneralError
57+
mod::ByteString
58+
msg::ByteString
59+
args
6960
InvalidBytesError() =
70-
new(GeneralError(modulename, "Invalid byte sequence in input"))
61+
new(modulename, "Invalid byte sequence in input", ())
7162
end
7263

7364
iconv_error(func) = throw(IConvError(func))
7465

75-
show{T<:StringEncodingError}(io::IO, exc::T) = show(io, exc.err)
66+
function show{T <: StringEncodingError}(io::IO, exc::T)
67+
str = exc.mod == "" ? exc.msg : string(exc.mod, ": ", exc.msg)
68+
if contains(exc.msg, "<<")
69+
for i = 1:length(exc.args)
70+
str = replace(str, "<<$i>>", exc.args[i])
71+
end
72+
end
73+
print(io, str)
74+
end
7675

7776
depsjl = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
7877
isfile(depsjl) ? include(depsjl) : error("libiconv not properly installed. Please run\nPkg.build(\"iconv\")")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /