diff --git a/stdlib/Base64/src/decode.jl b/stdlib/Base64/src/decode.jl index 056293528e142..df7ef1f0cfc38 100644 --- a/stdlib/Base64/src/decode.jl +++ b/stdlib/Base64/src/decode.jl @@ -9,7 +9,7 @@ for (i, c) in enumerate(BASE64_ENCODE) BASE64_DECODE[Int(c)+1] = UInt8(i - 1) end BASE64_DECODE[Int(encodepadding())+1] = BASE64_CODE_PAD -decode(x::UInt8) = @inbounds return BASE64_DECODE[x + 1] +decode(x::UInt8) = @inbounds return BASE64_DECODE[x+1] """ Base64DecodePipe(istream) @@ -69,9 +69,9 @@ function read_until_end(pipe::Base64DecodePipe, ptr::Ptr{UInt8}, n::UInt) while true if b1 < 0x40 && b2 < 0x40 && b3 < 0x40 && b4 < 0x40 && p + 2 < p_end # fast path to decode - unsafe_store!(p , b1 << 2 | b2 >> 4) + unsafe_store!(p, b1 << 2 | b2 >> 4) unsafe_store!(p + 1, b2 << 4 | b3 >> 2) - unsafe_store!(p + 2, b3 << 6 | b4 ) + unsafe_store!(p + 2, b3 << 6 | b4) p += 3 else i, p, ended = decode_slow(b1, b2, b3, b4, buffer, i, pipe.io, p, p_end - p, pipe.rest) @@ -182,7 +182,7 @@ function decode_slow(b1, b2, b3, b4, buffer, i, input, ptr, n, rest) end k ≥ 1 && output(b1 << 2 | b2 >> 4) k ≥ 2 && output(b2 << 4 | b3 >> 2) - k ≥ 3 && output(b3 << 6 | b4 ) + k ≥ 3 && output(b3 << 6 | b4) return i, p, k == 0 end diff --git a/stdlib/Base64/src/encode.jl b/stdlib/Base64/src/encode.jl index 588b49aa28d97..bbf2b279209c3 100644 --- a/stdlib/Base64/src/encode.jl +++ b/stdlib/Base64/src/encode.jl @@ -2,8 +2,8 @@ # Generate encode table. const BASE64_ENCODE = [UInt8(x) for x in append!(['A':'Z'; 'a':'z'; '0':'9'], ['+', '/'])] -encode(x::UInt8) = @inbounds return BASE64_ENCODE[(x & 0x3f) + 1] -encodepadding() = UInt8('=') +encode(x::UInt8) = @inbounds return BASE64_ENCODE[(x&0x3f)+1] +encodepadding() = UInt8('=') """ Base64EncodePipe(ostream) @@ -69,10 +69,10 @@ function Base.unsafe_write(pipe::Base64EncodePipe, ptr::Ptr{UInt8}, n::UInt)::In i = 0 p_end = ptr + n while true - buffer[i+1] = encode(b1 >> 2 ) + buffer[i+1] = encode(b1 >> 2) buffer[i+2] = encode(b1 << 4 | b2 >> 4) buffer[i+3] = encode(b2 << 2 | b3 >> 6) - buffer[i+4] = encode( b3 ) + buffer[i+4] = encode(b3) i += 4 if p + 2 < p_end b1 = unsafe_load(p, 1) @@ -113,23 +113,23 @@ function Base.close(pipe::Base64EncodePipe) # no leftover and padding elseif k == 1 write(pipe.io, - encode(b1 >> 2), - encode(b1 << 4), - encodepadding(), - encodepadding()) + encode(b1 >> 2), + encode(b1 << 4), + encodepadding(), + encodepadding()) elseif k == 2 write(pipe.io, - encode( b1 >> 2), - encode(b1 << 4 | b2 >> 4), - encode(b2 << 2 ), - encodepadding()) + encode(b1 >> 2), + encode(b1 << 4 | b2 >> 4), + encode(b2 << 2), + encodepadding()) else @assert k == 3 write(pipe.io, - encode(b1 >> 2 ), - encode(b1 << 4 | b2 >> 4), - encode(b2 << 2 | b3 >> 6), - encode( b3 )) + encode(b1 >> 2), + encode(b1 << 4 | b2 >> 4), + encode(b2 << 2 | b3 >> 6), + encode(b3)) end return nothing end diff --git a/stdlib/Base64/test/runtests.jl b/stdlib/Base64/test/runtests.jl index 11d0a3cca4348..0d8969e272b0f 100644 --- a/stdlib/Base64/test/runtests.jl +++ b/stdlib/Base64/test/runtests.jl @@ -75,18 +75,18 @@ const longDecodedText = "name = \"Genie\"\nuuid = \"c43c736e-a2d1-11e8-161f-af95 #@test read(ipipe, String) == inputText # Decode with two padding characters ("==") - ipipe = Base64DecodePipe(IOBuffer(string(encodedMaxLine76[1:end - 2], "=="))) - @test read(ipipe, String) == inputText[1:end - 1] + ipipe = Base64DecodePipe(IOBuffer(string(encodedMaxLine76[1:end-2], "=="))) + @test read(ipipe, String) == inputText[1:end-1] # Test incorrect format - ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end - 3])) + ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-3])) @test_throws ArgumentError read(ipipe, String) # issue #21314 @test base64decode(chomp("test")) == base64decode("test") # issue #32397 - @test String(base64decode(longEncodedText)) == longDecodedText; + @test String(base64decode(longEncodedText)) == longDecodedText # Optional padding @test base64decode("AQ==") == base64decode("AQ") @@ -116,16 +116,16 @@ struct PNG end Base.show(io::IO, ::MIME"image/png", ::PNG) = print(io, "PNG") @testset "stringmime" begin - @test stringmime("text/plain", [1 2;3 4]) == repr("text/plain", [1 2;3 4]) + @test stringmime("text/plain", [1 2; 3 4]) == repr("text/plain", [1 2; 3 4]) @test stringmime("text/html", "raw html data") == "raw html data" @test stringmime("text/plain", "string") == "\"string\"" - @test stringmime("image/png", UInt8[2,3,4,7]) == "AgMEBw==" - @test stringmime("text/plain", 3.141592653589793, context = :compact => true) == "3.14159" + @test stringmime("image/png", UInt8[2, 3, 4, 7]) == "AgMEBw==" + @test stringmime("text/plain", 3.141592653589793, context=:compact => true) == "3.14159" @test stringmime("image/png", PNG()) == stringmime(MIME("image/png"), PNG()) == "UE5H" end -function splace(in::String, p = 0.3) - spaces = ["\n"," "] +function splace(in::String, p=0.3) + spaces = ["\n", " "] len = length(in) len == 0 && return in rc::String = ""