Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-78

StringUtils.chomp does not match Perl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.0
    • lang.*
    • None
    • Operating System: All
      Platform: All

    • 18077

    Description

      In version 1.0.1, the method chomp(String) returns a value that is inconsistent
      with Perl's function of the same name. Since Perl invented the function chomp,
      and since many developers will expect this method to behave the same, we should
      bring it in line with expectations.

      There are also a cluster of related methods (chopNewline, prechomp, etc.) that
      should be renamed/removed/deprecated to match expectations.

      Specifically:

      Perl:

      chop removes the final character, no matter what it is

      chomp removes the final character if and only if it's a newline
      (or, technically, the $INPUT_RECORD_SEPARATOR).

      Current StringUtils:

      chop removes the final character, no matter what it is, and glomming
      \r\n as if it were a single character

      chopNewline removes the final character if and only if it's a newline
      (glomming \r\n) – behaving like Perl chomp

      chomp removes the last newline and all succeeding characters
      (i.e. the last unterminated line)

      chompLast removes the last character if and only if it's a newline
      (glomming \r\n) – This is redundant with chopNewline, and matches
      Perl chomp

      getChomp - since Henri's chomp might delete more than just the
      separator, this returns the portion that got deleted

      Attachments

        Activity

          People

            Unassigned Unassigned
            alex@apache.org Alex Chaffee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: