Skip to content

Commit

Permalink
partial revert of last commit: keep b"..." but use "..." in places
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Dec 14, 2017
1 parent 178da98 commit 80548a6
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 42 deletions.
8 changes: 0 additions & 8 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3033,14 +3033,6 @@ end
# Associative -> AbstractDict (#25012)
@deprecate_binding Associative AbstractDict

# PR #25073
macro b_str(s)
r = repr(s)
depwarn("`b$r` is deprecated, use `Vector{UInt8}($r)` instead", Symbol("@b_str"))
:(Vector{UInt8}($(unescape_string(s))))
end
export @b_str

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ export
@cmd, # `commands`

# notation for certain types
@b_str, # byte vector
@r_str, # regex
@s_str, # regex substitution string
@v_str, # version number
Expand Down
4 changes: 2 additions & 2 deletions base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ function decode_hex(d::Integer, symbols::Array{UInt8,1})
return Int32(pt), Int32(pt), neg
end

const hex_symbols = Vector{UInt8}("0123456789abcdef")
const HEX_symbols = Vector{UInt8}("0123456789ABCDEF")
const hex_symbols = b"0123456789abcdef"
const HEX_symbols = b"0123456789ABCDEF"

decode_hex(x::Integer) = decode_hex(x,hex_symbols)
decode_HEX(x::Integer) = decode_hex(x,HEX_symbols)
Expand Down
2 changes: 2 additions & 0 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ function unescape_string(io, s::AbstractString)
end
end

macro b_str(s); :(Vector{UInt8}($(unescape_string(s)))); end

"""
@raw_str -> String
Expand Down
2 changes: 1 addition & 1 deletion base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ julia> hex2bytes(s)
0x30
0x39
julia> a = Vector{UInt8}("01abEF")
julia> a = b"01abEF"
6-element Array{UInt8,1}:
0x30
0x31
Expand Down
6 changes: 3 additions & 3 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ write(io,[1,2,3])
skip(io,1)
@test write(io,UInt8(104)) === 1
skip(io,3)
@test write(io,Vector{UInt8}("apples")) === 3
@test write(io,b"apples") === 3
skip(io,71)
@test write(io,'y') === 1
@test read(io, String) == "happy"
Expand Down Expand Up @@ -190,7 +190,7 @@ end
# pr #11554
let a,
io = IOBuffer(SubString("***αhelloworldω***", 4, 16)),
io2 = IOBuffer(Vector{UInt8}("goodnightmoon"), true, true)
io2 = IOBuffer(b"goodnightmoon", true, true)

@test read(io, Char) == 'α'
@test_throws ArgumentError write(io,"!")
Expand All @@ -204,7 +204,7 @@ let a,
@test read(io, String) == ""
@test bufcontents(io) == "αhelloworldω"
@test_throws ArgumentError write(io,"!")
@test take!(io) == Vector{UInt8}("αhelloworldω")
@test take!(io) == b"αhelloworldω"
seek(io, 2)
seekend(io2)
write(io2, io)
Expand Down
4 changes: 2 additions & 2 deletions test/perf/shootout/fasta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const alu = string(
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC",
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA")

const iub1 = Vector{UInt8}("acgtBDHKMNRSVWY")
const iub1 = b"acgtBDHKMNRSVWY"
const iub2 = [0.27, 0.12, 0.12, 0.27, 0.02,0.02, 0.02, 0.02, 0.02, 0.02,0.02, 0.02, 0.02, 0.02, 0.02]

const homosapiens1 = Vector{UInt8}("acgt")
const homosapiens1 = b"acgt"
const homosapiens2 = [0.3029549426680, 0.1979883004921,0.1975473066391, 0.3015094502008]

const IM = 139968.0
Expand Down
4 changes: 2 additions & 2 deletions test/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end

# Module
create_serialization_stream() do s # user-defined module
mod = Vector{UInt8}("SomeModule")
mod = b"SomeModule"
modstring = String(mod)
eval(Meta.parse("module $(modstring); end"))
modtype = eval(Meta.parse("$(modstring)"))
Expand Down Expand Up @@ -505,7 +505,7 @@ let io = IOBuffer()
seekstart(io)
b = read(io)
@test b[1] == Serializer.HEADER_TAG
@test b[2:3] == Vector{UInt8}("JL")
@test b[2:3] == b"JL"
@test b[4] == Serializer.ser_version
@test (b[5] & 0x3) == (ENDIAN_BOM == 0x01020304)
@test ((b[5] & 0xc)>>2) == (sizeof(Int) == 8)
Expand Down
16 changes: 8 additions & 8 deletions test/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ end
# @test_throws BoundsError rsearchindex("foo", Char[], 5)

# @test_throws ErrorException in("foobar","bar")
@test_throws BoundsError search(Vector{UInt8}("\x1\x2"), 0x1, 0)
@test rsearchindex(Vector{UInt8}("foo"), Vector{UInt8}("o"), 0) == 0
@test rsearchindex(SubString("", 1, 0), SubString("", 1, 0)) == 1

@test search(Vector{UInt8}("foo"), 'o') == 2
@test rsearch(Vector{UInt8}("foo"), 'o') == 3
@test search(Vector{UInt8}("foó"), 'ó') == 3
@test rsearch(Vector{UInt8}("foó"), 'ó') == 3
@test_throws BoundsError search(b"\x1\x2",0x1,0)
@test rsearchindex(b"foo",b"o",0) == 0
@test rsearchindex(SubString("",1,0),SubString("",1,0)) == 1

@test search(b"foo",'o') == 2
@test rsearch(b"foo",'o') == 3
@test search(b"foó",'ó') == 3
@test rsearch(b"foó",'ó') == 3

# ascii search
for str in [astr, GenericString(astr)]
Expand Down
14 changes: 7 additions & 7 deletions test/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,23 @@ end
@test_throws ArgumentError hex2bytes("0123456789abcdefABCDEFGH")

@testset "Issue 23161" begin
arr = Vector{UInt8}("0123456789abcdefABCDEF")
arr = b"0123456789abcdefABCDEF"
arr1 = Vector{UInt8}(uninitialized, length(arr) >> 1)
@test hex2bytes!(arr1, arr) === arr1 # check in-place
@test "0123456789abcdefabcdef" == bytes2hex(arr1)
@test hex2bytes("0123456789abcdefABCDEF") == hex2bytes(arr)
@test_throws ArgumentError hex2bytes!(arr1, UInt8[]) # incorrect arr1 length
@test hex2bytes(UInt8[]) == UInt8[]
@test hex2bytes(view(Vector{UInt8}("012345"),1:6)) == UInt8[0x01,0x23,0x45]
@test_throws ArgumentError hex2bytes!(arr1, b"") # incorrect arr1 length
@test hex2bytes(b"") == UInt8[]
@test hex2bytes(view(b"012345",1:6)) == UInt8[0x01,0x23,0x45]
@test begin
s = view(Vector{UInt8}("012345ab"),1:6)
s = view(b"012345ab",1:6)
d = view(zeros(UInt8, 10),1:3)
hex2bytes!(d,s) == UInt8[0x01,0x23,0x45]
end
# odd size
@test_throws ArgumentError hex2bytes(Vector{UInt8}("0123456789abcdefABCDEF0"))
@test_throws ArgumentError hex2bytes(b"0123456789abcdefABCDEF0")

#non-hex characters
@test_throws ArgumentError hex2bytes(Vector{UInt8}("0123456789abcdefABCDEFGH"))
@test_throws ArgumentError hex2bytes(b"0123456789abcdefABCDEFGH")
end
end
20 changes: 11 additions & 9 deletions test/unicode/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ end
@test reverse("abc") == "cba"
@test reverse("xyz\uff\u800\uffff\U10ffff") == "\U10ffff\uffff\u800\uffzyx"
for (s, r) in [
"xyz\xc1" => "\xc1zyx",
"xyz\xd0" => "\xd0zyx",
"xyz\xe0" => "\xe0zyx",
"xyz\xed\x80" => "\xed\x80zyx",
"xyz\xf0" => "\xf0zyx",
"xyz\xf0\x80" => "\xf0\x80zyx",
"xyz\xf0\x80\x80" => "\xf0\x80\x80zyx",
"xyz\xc1" => "\xc1zyx",
"xyz\xd0" => "\xd0zyx",
"xyz\xe0" => "\xe0zyx",
"xyz\xed\x80" => "\xed\x80zyx",
"xyz\xf0" => "\xf0zyx",
"xyz\xf0\x80" => "\xf0\x80zyx",
"xyz\xf0\x80\x80" => "\xf0\x80\x80zyx",
]
@test reverse(s) == r
end
end

@testset "string convert" begin
@test "this is a test\xed\x80\x80" == "this is a test\ud000"
@test String(b"this is a test\xed\x80\x80") ==
"this is a test\xed\x80\x80" ==
"this is a test\ud000"
# Specifically check UTF-8 string whose lead byte is same as a surrogate
@test "\xed\x9f\xbf" == "\ud7ff"
@test String(b"\xed\x9f\xbf") == "\xed\x9f\xbf" == "\ud7ff"
end

0 comments on commit 80548a6

Please sign in to comment.