Here you can find the source of camelCaseToHuman(String input)
Parameter | Description |
---|---|
input | a parameter |
public static String camelCaseToHuman(String input)
//package com.java2s; /****************************************************************************** * Copyright (c) 2008-2013, Linagora//from ww w. j a v a 2s.c om * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Linagora - initial API and implementation *******************************************************************************/ public class Main { /** * Turns a CamelCase String to a more human friendly string * See TestStringUtils for specification. * @param input * @return */ public static String camelCaseToHuman(String input) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char currentChar = input.charAt(i); if (i == 0) { builder.append(Character.toUpperCase(currentChar)); } else if (Character.isLowerCase(currentChar)) { builder.append(currentChar); } else if (Character.isUpperCase(currentChar)) { char previousChar = input.charAt(i - 1); if (Character.isUpperCase(previousChar)) { // most probably an acronym builder.append(currentChar); if (i < input.length() - 1) { char nextChar = input.charAt(i + 1); if (!Character.isUpperCase(nextChar)) { // current is last letter of acronym if (builder.charAt(builder.length() - 1) != ' ') { builder.append(' '); } } } } else if (!Character.isUpperCase(previousChar)) { if (builder.charAt(builder.length() - 1) != ' ') { builder.append(' '); } if (i == input.length() - 1) { builder.append(currentChar); } else { char nextChar = input.charAt(i + 1); if (Character.isUpperCase(nextChar)) { // most probably an acronym builder.append(currentChar); } else { builder.append(Character.toLowerCase(currentChar)); } } } } else if (Character.isDigit(currentChar)) { char previousChar = input.charAt(i - 1); if (!Character.isDigit(previousChar)) { // first digit of a sequence if (builder.charAt(builder.length() - 1) != ' ') { builder.append(' '); } } builder.append(currentChar); if (i < input.length() - 1) { char nextChar = input.charAt(i + 1); if (!Character.isDigit(nextChar)) { // current is last digit of the sequence if (builder.charAt(builder.length() - 1) != ' ') { builder.append(' '); } } } } else { builder.append(currentChar); } } return builder.toString(); } }