|
2 | 2 |
|
3 | 3 | module StringEncodings
|
4 | 4 |
|
5 |
| -using Libdl |
6 |
| - |
7 |
| -# Load in `deps.jl`, complaining if it does not exist |
8 |
| -const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl") |
9 |
| -if !isfile(depsjl_path) |
10 |
| - error("iconv not installed properly, run Pkg.build(\"StringEncodings\"), restart Julia and try again") |
11 |
| -end |
12 |
| -include(depsjl_path) |
13 |
| - |
14 |
| -# Module initialization function |
15 |
| -function __init__() |
16 |
| - # Always check dependencies from `deps.jl` |
17 |
| - check_deps() |
18 |
| -end |
| 5 | +using Libiconv_jll |
19 | 6 |
|
20 | 7 | using Base.Libc: errno, strerror, E2BIG, EINVAL, EILSEQ
|
21 | 8 |
|
@@ -75,13 +62,13 @@ show(io::IO, exc::T) where {T<:Union{IncompleteSequenceError,OutputBufferError}}
|
75 | 62 |
|
76 | 63 | function iconv_close(cd::Ptr{Nothing})
|
77 | 64 | if cd != C_NULL
|
78 |
| - ccall((iconv_close_s, libiconv), Cint, (Ptr{Nothing},), cd) == 0 || |
| 65 | + ccall((:libiconv_close, libiconv), Cint, (Ptr{Nothing},), cd) == 0 || |
79 | 66 | throw(IConvError("iconv_close"))
|
80 | 67 | end
|
81 | 68 | end
|
82 | 69 |
|
83 | 70 | function iconv_open(tocode::String, fromcode::String)
|
84 |
| - p = ccall((iconv_open_s, libiconv), Ptr{Nothing}, (Cstring, Cstring), tocode, fromcode) |
| 71 | + p = ccall((:libiconv_open, libiconv), Ptr{Nothing}, (Cstring, Cstring), tocode, fromcode) |
85 | 72 | if p != Ptr{Nothing}(-1)
|
86 | 73 | return p
|
87 | 74 | elseif errno() == EINVAL
|
@@ -144,7 +131,7 @@ function iconv!(cd::Ptr{Nothing}, inbuf::Vector{UInt8}, outbuf::Vector{UInt8},
|
144 | 131 | inbytesleft_orig = inbytesleft[]
|
145 | 132 | outbytesleft[] = BUFSIZE
|
146 | 133 |
|
147 |
| - ret = ccall((iconv_s, libiconv), Csize_t, |
| 134 | + ret = ccall((:libiconv, libiconv), Csize_t, |
148 | 135 | (Ptr{Nothing}, Ptr{Ptr{UInt8}}, Ref{Csize_t}, Ptr{Ptr{UInt8}}, Ref{Csize_t}),
|
149 | 136 | cd, inbufptr, inbytesleft, outbufptr, outbytesleft)
|
150 | 137 |
|
@@ -176,7 +163,7 @@ function iconv_reset!(s::Union{StringEncoder, StringDecoder})
|
176 | 163 |
|
177 | 164 | s.outbufptr[] = pointer(s.outbuf)
|
178 | 165 | s.outbytesleft[] = BUFSIZE
|
179 |
| - ret = ccall((iconv_s, libiconv), Csize_t, |
| 166 | + ret = ccall((:libiconv, libiconv), Csize_t, |
180 | 167 | (Ptr{Nothing}, Ptr{Ptr{UInt8}}, Ref{Csize_t}, Ptr{Ptr{UInt8}}, Ref{Csize_t}),
|
181 | 168 | s.cd, C_NULL, C_NULL, s.outbufptr, s.outbytesleft)
|
182 | 169 |
|
@@ -278,9 +265,6 @@ read from `stream` into text in the encoding `to`. Calling `close` on the
|
278 | 265 | stream does not close `stream`.
|
279 | 266 |
|
280 | 267 | `to` and `from` can be specified either as a string or as an `Encoding` object.
|
281 |
| -
|
282 |
| -Note that some implementations may accept invalid sequences |
283 |
| -in the input data without raising an error. |
284 | 268 | """
|
285 | 269 | function StringDecoder(stream::IO, from::Encoding, to::Encoding=enc"UTF-8")
|
286 | 270 | cd = iconv_open(String(to), String(from))
|
@@ -542,7 +526,7 @@ encode(s::AbstractString, enc::AbstractString) = encode(s, Encoding(enc))
|
542 | 526 |
|
543 | 527 | function test_encoding(enc::String)
|
544 | 528 | # We assume that an encoding is supported if it's possible to convert from it to UTF-8:
|
545 |
| - cd = ccall((iconv_open_s, libiconv), Ptr{Nothing}, (Cstring, Cstring), enc, "UTF-8") |
| 529 | + cd = ccall((:libiconv_open, libiconv), Ptr{Nothing}, (Cstring, Cstring), enc, "UTF-8") |
546 | 530 | if cd == Ptr{Nothing}(-1)
|
547 | 531 | return false
|
548 | 532 | else
|
|
0 commit comments