File tree 3 files changed +19
-11
lines changed
3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -58,21 +58,20 @@ startswith(a::Vector{UInt8}, b::Vector{UInt8}) =
58
58
59
59
# TODO : fast endswith
60
60
61
-
62
61
"""
63
62
chop(s::AbstractString)
64
63
65
64
Remove the last character from `s`.
66
65
67
66
```jldoctest
68
- julia> a = string( "March")
67
+ julia> a = "March"
69
68
"March"
70
69
71
70
julia> chop(a)
72
71
"Marc"
73
72
```
74
73
"""
75
- chop (s:: AbstractString ) = s[ 1 : end - 1 ]
74
+ chop (s:: AbstractString ) = SubString (s, 1 , endof (s) - 1 )
76
75
77
76
"""
78
77
chomp(s::AbstractString)
@@ -81,14 +80,21 @@ Remove a single trailing newline from a string.
81
80
"""
82
81
function chomp (s:: AbstractString )
83
82
i = endof (s)
84
- if (i < 1 || s[i] != ' \n ' ) return s end
83
+ if (i < 1 || s[i] != ' \n ' ) return SubString (s, 1 , i) end
85
84
j = prevind (s,i)
86
- if (j < 1 || s[j] != ' \r ' ) return s[1 : i- 1 ] end
87
- return s[1 : j- 1 ]
85
+ if (j < 1 || s[j] != ' \r ' ) return SubString (s, 1 , i- 1 ) end
86
+ return SubString (s, 1 , j- 1 )
87
+ end
88
+ function chomp (s:: String )
89
+ i = endof (s)
90
+ if i < 1 || s. data[i] != 0x0a
91
+ SubString (s, 1 , i)
92
+ elseif i < 2 || s. data[i- 1 ] != 0x0d
93
+ SubString (s, 1 , i- 1 )
94
+ else
95
+ SubString (s, 1 , i- 2 )
96
+ end
88
97
end
89
- chomp (s:: String ) =
90
- (endof (s) < 1 || s. data[end ] != 0x0a ) ? s :
91
- (endof (s) < 2 || s. data[end - 1 ] != 0x0d ) ? s[1 : end - 1 ] : s[1 : end - 2 ]
92
98
93
99
# NOTE: use with caution -- breaks the immutable string convention!
94
100
function chomp! (s:: String )
Original file line number Diff line number Diff line change 450
450
451
451
.. doctest ::
452
452
453
- julia> a = string( "March")
453
+ julia> a = "March"
454
454
"March"
455
455
456
456
julia> chop(a)
Original file line number Diff line number Diff line change 210
210
211
211
# chomp/chop
212
212
@test chomp (" foo\n " ) == " foo"
213
- @test chop (" foob" ) == " foo"
213
+ @test chop (" fooε" ) == " foo"
214
+ @test isa (chomp (" foo" ), SubString)
215
+ @test isa (chop (" foo" ), SubString)
214
216
215
217
# bytes2hex and hex2bytes
216
218
hex_str = " d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"
You can’t perform that action at this time.
0 commit comments