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

[PATCH] StringUtil enhancement

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0
    • lang.*
    • None
    • Operating System: other
      Platform: Other

    • 13367

    Description

      Could you please add two methods to StringUtils. They are very simple but I
      find them very usefull in day to day programming (isn't "Commons-Lang" a
      collection of simple utilities for some very simple but very common cases )

      1. String trimNull(String str) to return trimmed str or null if str == null or
      str.trim() is blank. Very often I want to treat blank as null (actually more
      often than null as "")
      2. String join(String str1, String str2, String delim). This should join str1
      and 2 and put delimiter in between only if both are not null (blank?) if one or
      both are null (blank) delimiter should not be inserted

      Please see examles below

      public static String trimNull(String value)

      { if (value == null) return null; else if (value.length() > 0) value = value.trim(); if (value.length() > 0) return value; else return null; }

      public static String join(String st1, String st2, String sep) {
      boolean b1, b2;
      if (st1 != null)

      { st1 = st1.trim(); b1 = (st1.length() > 0); }

      else b1 = false;

      if (st2 != null)

      { st2 = st2.trim(); b2 = (st2.length() > 0); }

      else b2 = false;

      if (b1)
      if (b2) return st1 + ((sep == null) ? st2 : sep + st2);
      else return st1;
      else
      if (b2) return st2;
      else return "";
      }

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--CompareToBuilder.patch-1.9.java
          4 kB
          ggregory@seagullsw.com
        2. ASF.LICENSE.NOT.GRANTED--other-patch.txt
          1 kB
          Arun Thomas
        3. ASF.LICENSE.NOT.GRANTED--otherTest-patch.txt
          3 kB
          Arun Thomas
        4. ASF.LICENSE.NOT.GRANTED--trim-patch.txt
          2 kB
          Arun Thomas

        Activity

          People

            Unassigned Unassigned
            roytmana@peacetech.com Alex Roytman
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: