Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow chop to take an empty string #31312

Merged
merged 1 commit into from
Mar 11, 2019

Conversation

bicycle1885
Copy link
Member

@bicycle1885 bicycle1885 commented Mar 10, 2019

The following behavior contradicts the docstring of chop. So, I fixed the behavior in this pull request.

julia> chop("")
ERROR: BoundsError: attempt to access ""
  at index [1]
Stacktrace:
 [1] nextind(::String, ::Int64, ::Int64) at ./strings/basic.jl:521
 [2] #chop#328(::Int64, ::Int64, ::typeof(chop), ::String) at ./strings/util.jl:99
 [3] chop(::String) at ./strings/util.jl:99
 [4] top-level scope at REPL[1]:1

help?> chop
search: chop chomp readchomp chown chmod Cshort eachrow eachcol

  chop(s::AbstractString; head::Integer = 0, tail::Integer = 1)

  Remove the first head and the last tail characters from s. The
  call chop(s) removes the last character from s. If it is
  requested to remove more characters than length(s) then an empty
  string is returned.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> a = "March"
  "March"

  julia> chop(a)
  "Marc"

  julia> chop(a, head = 1, tail = 2)
  "ar"

  julia> chop(a, head = 5, tail = 5)
  ""

@JeffBezanson JeffBezanson added the strings "Strings!" label Mar 11, 2019
@StefanKarpinski
Copy link
Member

Obviously needs to be fixed but I worry that this may just be bandaiding the real problem, namely that nextind("", 1, 0) should probably work. cc @bkamins; I believe this was tightened from my original.

@StefanKarpinski StefanKarpinski merged commit 023c8e4 into JuliaLang:master Mar 11, 2019
@StefanKarpinski
Copy link
Member

Have merged this as the simplest most conservative fix that can and should be backported.

@bicycle1885 bicycle1885 deleted the fix-chop branch March 11, 2019 22:39
eulerkochy added a commit to eulerkochy/julia that referenced this pull request Mar 15, 2019
KristofferC pushed a commit that referenced this pull request Apr 15, 2019
@KristofferC KristofferC mentioned this pull request Apr 15, 2019
39 tasks
KristofferC pushed a commit that referenced this pull request Apr 17, 2019
@KristofferC KristofferC mentioned this pull request Apr 19, 2019
39 tasks
nalimilan added a commit to JuliaData/CategoricalArrays.jl that referenced this pull request Apr 19, 2019
Since JuliaLang/julia#31312, chop("") returns "" instead of throwing.
nalimilan added a commit to JuliaData/CategoricalArrays.jl that referenced this pull request Apr 19, 2019
Since JuliaLang/julia#31312, chop("") returns "" instead of throwing.
KristofferC pushed a commit that referenced this pull request Apr 20, 2019
@KristofferC KristofferC added the bugfix This change fixes an existing bug label May 16, 2019
KristofferC pushed a commit that referenced this pull request Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants