Skip to content

Commit

Permalink
datafmt no longer depends on char / int comparisons to be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Oct 26, 2014
1 parent 92764b3 commit 5de9a78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function store_cell{T,S<:String}(dlmstore::DLMStore{T,S}, row::Int, col::Int, qu
tmp64 = dlmstore.tmp64

endpos = prevind(sbuff, nextind(sbuff,endpos))
(endpos > 0) && ('\n' == dlmstore.eol) && ('\r' == sbuff[endpos]) && (endpos = prevind(sbuff, endpos))
(endpos > 0) && ('\n' == dlmstore.eol) && ('\r' == char(sbuff[endpos])) && (endpos = prevind(sbuff, endpos))
sval = quoted ? SubString(sbuff, startpos+1, endpos-1) : SubString(sbuff, startpos, endpos)

if drow > 0
Expand Down Expand Up @@ -335,7 +335,7 @@ function dlm_parse{T,D}(dbuff::T, eol::D, dlm::D, qchar::D, cchar::D, ign_adj_dl
all_ascii = (D <: Uint8) || (isascii(eol) && isascii(dlm) && (!allow_quote || isascii(qchar)) && (!allow_comments || isascii(cchar)))
(T <: UTF8String) && all_ascii && (return dlm_parse(dbuff.data, uint8(eol), uint8(dlm), uint8(qchar), uint8(cchar), ign_adj_dlm, allow_quote, allow_comments, skipstart, skipblanks, dh))
ncols = nrows = col = 0
is_default_dlm = (dlm == invalid_dlm % D)
is_default_dlm = (dlm == uint32(invalid_dlm) % D)
error_str = ""
# 0: begin field, 1: quoted field, 2: unquoted field, 3: second quote (could either be end of field or escape character), 4: comment, 5: skipstart
state = (skipstart > 0) ? 5 : 0
Expand All @@ -347,13 +347,13 @@ function dlm_parse{T,D}(dbuff::T, eol::D, dlm::D, qchar::D, cchar::D, ign_adj_dl
was_cr = false
while idx <= slen
val,idx = next(dbuff, idx)
if (is_eol = (val == eol))
if (is_eol = (char(val) == char(eol)))
is_dlm = is_comment = is_cr = is_quote = false
elseif (is_dlm = (is_default_dlm ? in(val, _default_delims) : (val == dlm)))
elseif (is_dlm = (is_default_dlm ? in(char(val), _default_delims) : (char(val) == char(dlm))))
is_comment = is_cr = is_quote = false
elseif (is_quote = (val == qchar))
elseif (is_quote = (char(val) == char(qchar)))
is_comment = is_cr = false
elseif (is_comment = (val == cchar))
elseif (is_comment = (char(val) == char(cchar)))
is_cr = false
else
is_cr = (char(eol) == '\n') && (char(val) == '\r')
Expand Down
1 change: 1 addition & 0 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ print(io::IO,ip::IPv4) = print(io,dec((ip.host&(0xFF000000))>>24),".",

immutable IPv6 <: IPAddr
host::Uint128

IPv6(host::Uint128) = new(host)
IPv6(a::Uint16,b::Uint16,c::Uint16,d::Uint16,
e::Uint16,f::Uint16,g::Uint16,h::Uint16) = new(uint128(a)<<(7*16)|
Expand Down
6 changes: 3 additions & 3 deletions test/readdlm.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

isequaldlm(m1, m2, t) = isequal(m1, m2) && (eltype(m1) == eltype(m2) == t)

@test isequaldlm(readdlm(IOBuffer("1\t2\n3\t4\n5\t6\n")), [1. 2; 3 4; 5 6], Float64)
Expand Down Expand Up @@ -53,12 +52,14 @@ let result1 = reshape(Any["abc", "hello", "def,ghi", " \"quote\" ", "new\nline",
@test isequaldlm(readdlm(IOBuffer("abc,\"def,ghi\",\"new\nline\"\n\"hello\",\" \"\"quote\"\" \",world"), ',', quotes=false), result2, Any)
end


let result1 = reshape(Any["t", "c", "", "c"], 2, 2),
result2 = reshape(Any["t", "\"c", "t", "c"], 2, 2)
@test isequaldlm(readdlm(IOBuffer("t \n\"c\" c")), result1, Any)
@test isequaldlm(readdlm(IOBuffer("t t \n\"\"\"c\" c")), result2, Any)
end


@test isequaldlm(readcsv(IOBuffer("\n1,2,3\n4,5,6\n\n\n"), skipblanks=false),
reshape(Any["",1.0,4.0,"","","",2.0,5.0,"","","",3.0,6.0,"",""], 5, 3), Any)
@test isequaldlm(readcsv(IOBuffer("\n1,2,3\n4,5,6\n\n\n"), skipblanks=true), reshape([1.0,4.0,2.0,5.0,3.0,6.0], 2, 3), Float64)
Expand Down Expand Up @@ -105,7 +106,7 @@ end
@test isequaldlm(readcsv(IOBuffer("1,2,\"#3\"\n4,5,6")), [1. 2. "#3";4. 5. 6.], Any)
@test isequaldlm(readcsv(IOBuffer("1,2,3\n #with leading whitespace\n4,5,6")), [1. 2. 3.;" " "" "";4. 5. 6.], Any)

# test skipstart
#test skipstart
let x = ["a" "b" "c"; "d" "e" "f"; "g" "h" "i"; "A" "B" "C"; 1 2 3; 4 5 6; 7 8 9], io = IOBuffer()
writedlm(io, x, quotes=false)
seek(io, 0)
Expand Down Expand Up @@ -197,4 +198,3 @@ let i18n_data = ["Origin (English)", "Name (English)", "Origin (Native)", "Name
writedlm(i18n_buff, i18n_arr, '\t')
@test (data, hdr) == readdlm(i18n_buff, '\t', header=true)
end

0 comments on commit 5de9a78

Please sign in to comment.