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

StringUtils/WordUtils camelize - underscore functionality

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: lang.*
    • Labels:
      None

      Description

      I recently came across a problem which I expected to be solved already by StringUtils or Word Utils.
      Some input like "MY_TINY_PROPERTY" needed to be converted to a bean name "myTinyProperty".
      The code I wrote for that (far from perfect) looks like this:

      private String toCamelCase(String value, boolean startWithLowerCase) {
      String[] strings = StringUtils.split(value.toLowerCase(), "_");
      for (int i = startWithLowerCase ? 1 : 0; i < strings.length; i++)

      { strings[i] = StringUtils.capitalize(strings[i]); }

      return StringUtils.join(strings);
      }

      The way back would be a bit more complicated.

      If there is consensus that such a function could be useful, I am willing to create a patch. However I can see reasons for not creating such a functionality (especially with the way back) because requirements might differ. What is the commons approach here. Implement something for the 80% case?

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              fabianlange Fabian Lange
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: