42
42
"""
43
43
=#
44
44
function convert (:: Type{UTF16String} , str:: AbstractString )
45
- len, flags, num4byte = check_string_abs (str)
45
+ len, flags, num4byte = check_string (str)
46
46
buf = Vector {UInt16} (len+ num4byte+ 1 )
47
47
out = 0
48
48
@inbounds for ch in str
71
71
"""
72
72
=#
73
73
function convert (:: Type{UTF32String} , str:: AbstractString )
74
- len, flags = check_string_abs (str)
74
+ len, flags = check_string (str)
75
75
buf = Vector {Char} (len+ 1 )
76
76
out = 0
77
77
@inbounds for ch in str ; buf[out += 1 ] = ch ; end
@@ -95,7 +95,7 @@ function convert(::Type{UTF16String}, str::UTF8String)
95
95
# handle zero length string quickly
96
96
sizeof (dat) == 0 && return empty_utf16
97
97
# Check that is correct UTF-8 encoding and get number of words needed
98
- len, flags, num4byte = check_string_utf8 (dat)
98
+ len, flags, num4byte = check_string (dat)
99
99
len += num4byte
100
100
buf = Vector {UInt16} (len+ 1 )
101
101
@inbounds buf[len+ 1 ] = 0
@@ -143,7 +143,7 @@ function convert(::Type{UTF8String}, dat::Vector{UInt16})
143
143
# handle zero length string quickly
144
144
len == 0 && return UTF8String (" " )
145
145
# get number of bytes to allocate
146
- len, flags, num4byte, num3byte, num2byte = check_string_utf16 (dat, len>>> 1 )
146
+ len, flags, num4byte, num3byte, num2byte = check_string (dat, len>>> 1 )
147
147
flags == 0 && @inbounds return UTF8String (copy! (Vector {UInt8} (len), dat))
148
148
return encode_to_utf8 (UInt16, dat, len + num2byte + num3byte* 2 + num4byte* 3 )
149
149
end
@@ -165,7 +165,7 @@ function convert(::Type{UTF8String}, str::UTF16String)
165
165
# handle zero length string quickly
166
166
len <= 1 && return UTF8String (" " )
167
167
# get number of bytes to allocate
168
- len, flags, num4byte, num3byte, num2byte = check_string_utf16 (dat, len- 1 )
168
+ len, flags, num4byte, num3byte, num2byte = check_string (dat, len- 1 )
169
169
flags == 0 && @inbounds return UTF8String (copy! (Vector {UInt8} (len), 1 , dat, 1 , len))
170
170
return encode_to_utf8 (UInt16, dat, len + num2byte + num3byte* 2 + num4byte* 3 )
171
171
end
@@ -186,7 +186,7 @@ function convert(::Type{UTF8String}, dat::Vector{UInt32})
186
186
# handle zero length string quickly
187
187
len == 0 && return UTF8String (" " )
188
188
# get number of bytes to allocate
189
- len, flags, num4byte, num3byte, num2byte = check_string_utf32 (dat, len>>> 2 )
189
+ len, flags, num4byte, num3byte, num2byte = check_string (dat, len>>> 2 )
190
190
flags == 0 && @inbounds return UTF8String (copy! (Vector {UInt8} (len), 1 , dat, 1 , len))
191
191
return encode_to_utf8 (UInt32, dat, len + num2byte + num3byte* 2 + num4byte* 3 )
192
192
end
@@ -208,7 +208,7 @@ function convert(::Type{UTF8String}, str::UTF32String)
208
208
# handle zero length string quickly
209
209
len <= 1 && return UTF8String (" " )
210
210
# get number of bytes to allocate
211
- len, flags, num4byte, num3byte, num2byte = check_string_utf32 (dat, len- 1 )
211
+ len, flags, num4byte, num3byte, num2byte = check_string (dat, len- 1 )
212
212
flags == 0 && @inbounds return UTF8String (copy! (Vector {UInt8} (len), 1 , dat, 1 , len))
213
213
return encode_to_utf8 (UInt32, dat, len + num2byte + num3byte* 2 + num4byte* 3 )
214
214
end
@@ -271,7 +271,7 @@ function convert(::Type{UTF32String}, str::UTF8String)
271
271
# handle zero length string quickly
272
272
sizeof (dat) == 0 && return empty_utf32
273
273
# Validate UTF-8 encoding, and get number of words to create
274
- len, flags = check_string_utf8 (dat)
274
+ len, flags = check_string (dat)
275
275
# Optimize case where no characters > 0x7f
276
276
totlen = len+ 1
277
277
flags == 0 && return fast_utf_copy (UTF32String, Char, totlen, dat)
@@ -329,7 +329,7 @@ function convert(::Type{UTF32String}, str::UTF16String)
329
329
# handle zero length string quickly (account for trailing \0)
330
330
len <= 2 && return empty_utf32
331
331
# get number of words to create
332
- len, flags, num4byte = check_string_utf16 (dat, len>>> 1 )
332
+ len, flags, num4byte = check_string (dat, len>>> 1 )
333
333
# No surrogate pairs, do optimized copy
334
334
(flags & UTF_UNICODE4) == 0 && @inbounds return UTF32String (copy! (Vector {Char} (len), dat))
335
335
local ch:: UInt32
@@ -361,7 +361,7 @@ function convert(::Type{UTF16String}, dat::Vector{UInt32})
361
361
# handle zero length string quickly
362
362
len <= 4 && return empty_utf16
363
363
# get number of words to allocate
364
- len, flags, num4byte = check_string_utf32 (dat, len>>> 2 )
364
+ len, flags, num4byte = check_string (dat, len>>> 2 )
365
365
len += num4byte + 1
366
366
# optimized path, no surrogates
367
367
num4byte == 0 && return fast_utf_copy (UTF16String, UInt16, len, dat)
@@ -385,7 +385,7 @@ function convert(::Type{UTF16String}, str::UTF32String)
385
385
# handle zero length string quickly
386
386
len <= 4 && return empty_utf16
387
387
# get number of words to allocate
388
- len, flags, num4byte = check_string_utf32 (dat, len>>> 2 )
388
+ len, flags, num4byte = check_string (dat, len>>> 2 )
389
389
# optimized path, no surrogates
390
390
num4byte == 0 && @inbounds return UTF16String (copy! (Vector {UInt16} (len), dat))
391
391
return encode_to_utf16 (dat, len + num4byte)
@@ -429,7 +429,7 @@ function convert(::Type{UTF16String}, str::ASCIIString)
429
429
end
430
430
431
431
function convert (:: Type{UTF16String} , data:: AbstractVector{UInt16} )
432
- ! isvalid (UTF16String, data) && throw ( ArgumentError ( " invalid UTF16 data " ) )
432
+ ! isvalid (UTF16String, data) && utf_errfunc (UTF_ERR_INVALID_16, 0 , 0 )
433
433
fast_utf_copy (UTF16String, UInt16, length (data), data, true )
434
434
end
435
435
0 commit comments