Java String Underscore underScoreBreakToCaseBreak (final String s)

Here you can find the source of underScoreBreakToCaseBreak (final String s)

Description

under Score Break To Case Break

License

Apache License

Declaration

public static String underScoreBreakToCaseBreak (final String s)
    

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file

import java.util.Arrays;

public class Main {
    public static String underScoreBreakToCaseBreak(final String s) {
        // Logical name is the physical name converted to mixed case, eg ACTUAL_DATA to
        // ActualData.
        final StringBuilder sb = new StringBuilder();

        final char[] chars = s.toCharArray();

        boolean nextShouldBeUpperCase = true;
        for (final char c : chars) {
            if (c == '_') {
                // Separator. Cause a case break.
                nextShouldBeUpperCase = true;
            } else if (c == '$' || !Character.isJavaIdentifierPart(c)) {
                // Translate illegal computer language characters to '_' and cause a case
                // break.
                sb.append('_');
                nextShouldBeUpperCase = true;
            } else if (nextShouldBeUpperCase) {
                sb.append(Character.toUpperCase(c));
                nextShouldBeUpperCase = false;
            } else {
                sb.append(Character.toLowerCase(c));
            }//from   w  w w  .j  ava  2s .co  m
        }

        return sb.toString();
    }

    /** Varargs wrapper */
    public static String toString(final Object... objects) {
        return Arrays.toString(objects);
    }
}

Related

  1. underscore(String phase)
  2. underscore(String str)
  3. underscore(String word)
  4. underscoreAllWhitespace(String str)
  5. underscoreAndLowercase(String s)
  6. underscoreCase(String s)
  7. underScoreCase2CamelCase(String str)
  8. underscored(String string)
  9. underscoredToCamel(String string)