Clojure

clojure.string/trim uses different defn of whitespace as triml, trimr

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

clojure.string/triml and trimr use Character/isWhitespace to determine whether a character is whitespace, but trim uses some other definition of white space character. For example:

user=> (use 'clojure.string)
nil
user=> (def s " \u2002 foo")
#'user/s
user=> (trim s)
"? foo"
user=> (triml s)
"foo"

The attached patch changes trim to use Character/isWhitespace. I suppose other possibilities are to change triml and trimr to use trim's notion of whitespace, whatever that is, or to just leave these functions inconsistent with each other. It does seem that it would be a nice property that (trim s) is equal to (triml (trimr s)) for all strings.

The patch also changes triml to only call .length on s once.

Activity

Hide
Stuart Halloway added a comment -

Question for Rich: do we want to be consistent across the different trim fns (per this patch) or consistent with Java, which uses one definition of whitespace in Character/isWhitespace, and a different definition in String/trim?

Show
Stuart Halloway added a comment - Question for Rich: do we want to be consistent across the different trim fns (per this patch) or consistent with Java, which uses one definition of whitespace in Character/isWhitespace, and a different definition in String/trim?
Hide
Stuart Halloway added a comment -

Question for Andy: why the (int ...) forms, when Clojure only works with primitive longs?

Show
Stuart Halloway added a comment - Question for Andy: why the (int ...) forms, when Clojure only works with primitive longs?
Hide
Andy Fingerhut added a comment -

Answer for Stuart: Looks like I was preserving the (int ...) form that was in triml before, perhaps somewhat mindlessly. Depending on Rich's answer, I can update the patch if desired.

Show
Andy Fingerhut added a comment - Answer for Stuart: Looks like I was preserving the (int ...) form that was in triml before, perhaps somewhat mindlessly. Depending on Rich's answer, I can update the patch if desired.
Hide
Aaron Bedra added a comment -

Bump on the discussion. This ticket seems blocked until we make a decision.

Show
Aaron Bedra added a comment - Bump on the discussion. This ticket seems blocked until we make a decision.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: