@@ -9,7 +9,7 @@ function loadfile(T, file::File)
9
9
end
10
10
11
11
function loadfile (T, file:: TextFile )
12
- _ignore_crlf (read (file. filename, String))
12
+ _ignore_CR (read (file. filename, String))
13
13
end
14
14
15
15
function loadfile (:: Type{<:Number} , file:: File{format"TXT"} )
41
41
# Some target formats are not supported by FileIO and thus require an encoding/compression process
42
42
# before saving. For other formats, we should trust IO backends and make as few changes as possible.
43
43
# Otherwise, reference becomes unfaithful. The encoding process helps making the actual data matches
44
- # the reference data, which is load from reference file via IO backends.
44
+ # the reference data, which is loaded from reference file via IO backends.
45
45
#
46
46
# TODO : split `maybe_encode` to `maybe_preprocess` and `maybe_encode`
47
47
"""
@@ -54,9 +54,9 @@ If there is no known method to encode `x`, then it directly return `x` without w
54
54
maybe_encode (:: Type{<:DataFormat} , x; kw... ) = x
55
55
56
56
# plain TXT
57
- maybe_encode (:: Type{DataFormat{:TXT}} , x; kw... ) = _ignore_crlf (string (x))
57
+ maybe_encode (:: Type{DataFormat{:TXT}} , x; kw... ) = _ignore_CR (string (x))
58
58
maybe_encode (:: Type{DataFormat{:TXT}} , x:: AbstractArray{<:AbstractString} ; kw... ) = _join (x)
59
- maybe_encode (:: Type{DataFormat{:TXT}} , x:: AbstractString ; kw... ) = _ignore_crlf (x)
59
+ maybe_encode (:: Type{DataFormat{:TXT}} , x:: AbstractString ; kw... ) = _ignore_CR (x)
60
60
maybe_encode (:: Type{DataFormat{:TXT}} , x:: Number ; kw... ) = x # TODO : Change this to string(x) ?
61
61
62
62
function maybe_encode (
74
74
75
75
# SHA256
76
76
maybe_encode (:: Type{DataFormat{:SHA256}} , x; kw... ) = _sha256 (string (x))
77
- maybe_encode (:: Type{DataFormat{:SHA256}} , x:: AbstractString ) = _sha256 (_ignore_crlf (x))
77
+ maybe_encode (:: Type{DataFormat{:SHA256}} , x:: AbstractString ) = _sha256 (_ignore_CR (x))
78
78
maybe_encode (:: Type{DataFormat{:SHA256}} , x:: AbstractArray{<:AbstractString} ) = _sha256 (_join (x))
79
79
function maybe_encode (:: Type{DataFormat{:SHA256}} , img:: AbstractArray{<:Colorant} ; kw... )
80
80
# encode image into SHA256
@@ -84,8 +84,14 @@ function maybe_encode(::Type{DataFormat{:SHA256}}, img::AbstractArray{<:Colorant
84
84
return size_str * img_str
85
85
end
86
86
87
-
88
87
# Helpers
89
- _join (x:: AbstractArray{<:AbstractString} ) = mapreduce (_ignore_crlf, (x,y) -> x * " \n " * y, x )
88
+ _join (x:: AbstractArray{<:AbstractString} ) = _ignore_CR ( join (x, " \n " ) )
90
89
_sha256 (x) = bytes2hex (sha256 (x))
91
- _ignore_crlf (x:: AbstractString ) = replace (x, " \r " => " " )
90
+ """
91
+ _ignore_CR(x::AbstractString)
92
+
93
+ Ignore the CRLF(`\\ r\\ n`) and LF(`\\ n`) difference by removing `\\ r` from the given string.
94
+
95
+ CRLF format is widely used by Windows while LF format is mainly used by Linux.
96
+ """
97
+ _ignore_CR (x:: AbstractString ) = replace (x, " \r\n " => " \n " ) # issue #39
0 commit comments