Java String Camel Case To camelCaseIt(String mappingName, String separator)

Here you can find the source of camelCaseIt(String mappingName, String separator)

Description

camel Case It

License

Open Source License

Declaration

private static String camelCaseIt(String mappingName, String separator) 

Method Source Code

//package com.java2s;
/*//from w  ww .  ja va 2  s .  c  om
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
 * Version 1.1  with a permitted attribution clause; you may not  use this
 * file except in compliance with the License. You  may  obtain  a copy of
 * the License at http://www.openbravo.com/legal/license.html 
 * Software distributed under the License  is  distributed  on  an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific  language  governing  rights  and  limitations
 * under the License. 
 * The Original Code is Openbravo ERP. 
 * The Initial Developer of the Original Code is Openbravo SLU 
 * All portions are Copyright (C) 2008-2011 Openbravo SLU 
 * All Rights Reserved. 
 * Contributor(s):  ______________________________________.
 ************************************************************************
 */

public class Main {
    private static String camelCaseIt(String mappingName, String separator) {
        String localMappingName = mappingName;
        // strip _ at the end
        while (localMappingName.endsWith(separator)) {
            localMappingName = localMappingName.substring(0, localMappingName.length() - 1);
        }
        // strip _ at the beginning
        while (localMappingName.startsWith(separator)) {
            localMappingName = localMappingName.substring(1);
        }

        // "CamelCasing"
        int pos = localMappingName.indexOf(separator);
        while (pos != -1) {
            final String leftPart = localMappingName.substring(0, pos);
            final String camelLetter = String.valueOf(localMappingName.charAt(pos + 1)).toUpperCase();
            final String rightPart = localMappingName.substring(pos + 2);
            localMappingName = leftPart + camelLetter + rightPart;
            pos = localMappingName.indexOf(separator);
        }
        return localMappingName;
    }
}

Related

  1. camel2underline(String hump)
  2. camel2underline(String s)
  3. camelCase2Delimiter(String name, char delimiter)
  4. camelCaseMatch(String word, String abbr)
  5. camelCaseNameToConstant(String camelCaseName)
  6. camelCaseOrSpaceToDashed(String s)
  7. camelCasePrefix(String strPrefix)