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

new StringUtils.replaceChars behaves differently from old CharSetUtils.translate

    XMLWordPrintableJSON

Details

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

    • 25454

    Description

      The CharSetUtils.translate(String str, String searchChars, String replaceChars)
      method from Lang 1.0.1 is marked deprecated, pointing me at
      StringUtils.replaceChars(String str, String searchChars, String replaceChars)
      from Lang 2.0. The routines are coded quite differently, and in fact yield
      different outputs at times. StringUtils.replaceChars() does not translate some
      strings properly.

      String original="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
      String trans="nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM567891234";
      System.out.println(CharSetUtils.translate("d216.102oren", original, trans));
      System.out.println(StringUtils.replaceChars("d216.102oren", original, trans));

      Running this fragment gets me this:
      q651.506bera
      d141.401beea

      The first one is correct.

      Attachments

        Activity

          People

            Unassigned Unassigned
            loren@siebert.org Loren Siebert
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: