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

Adding to StringUtils truncate method and test cases

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.5
    • lang.*

    Description

      Adding the following methods from StringUtils:

      • public static String truncate(final String str, final int maxWidth)
      • public static String truncate(final String str, int offset, final int maxWidth)

      For example

      StringUtils.truncate("abcdefg", 4) = "abcd"
      StringUtils.truncate("abcdefg", 6) = "abcdef"
      StringUtils.truncate("abcdefg", 7) = "abcdefg"
      StringUtils.truncate("abcdefg", 8) = "abcdefg"
      
      StringUtils.truncate("abcdefghijklmno", -1, 10) = "abcdefghij"
      StringUtils.truncate("abcdefghijklmno", 0, 10) = "abcdefghij"
      StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = "abcdefghij"
      StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, Integer.MAX_VALUE) = "abcdefghijklmno"
      StringUtils.truncate("abcdefghijklmno", 0, Integer.MAX_VALUE) = "abcdefghijklmno"
      StringUtils.truncate("abcdefghijklmno", 1, 10) = "bcdefghijk"
      StringUtils.truncate("abcdefghijklmno", 2, 10) = "cdefghijkl"
      StringUtils.truncate("abcdefghijklmno", 3, 10) = "defghijklm"
      StringUtils.truncate("abcdefghijklmno", 4, 10) = "efghijklmn"
      StringUtils.truncate("abcdefghijklmno", 5, 10) = "fghijklmno"
      StringUtils.truncate("abcdefghijklmno", 5, 5) = "fghij"
      StringUtils.truncate("abcdefghijklmno", 5, 3) = "fgh"
      StringUtils.truncate("abcdefghijklmno", 10, 3) = "klm"
      StringUtils.truncate("abcdefghijklmno", 10, Integer.MAX_VALUE) = "klmno"
      StringUtils.truncate("abcdefghijklmno", 13, 1) = "n"
      StringUtils.truncate("abcdefghijklmno", 13, Integer.MAX_VALUE) = "no"
      StringUtils.truncate("abcdefghijklmno", 14, 1) = "o"
      StringUtils.truncate("abcdefghijklmno", 14, Integer.MAX_VALUE) = "o"
      

      See: https://github.com/apache/commons-lang/pull/137

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            thiagoh1 Thiago Andrade
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: