All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockito.internal.util.Decamelizer Maven / Gradle / Ivy

There is a newer version: 2.0.2-beta
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Decamelizer {

private static final Pattern CAPS = Pattern.compile("([A-Z\\d][^A-Z\\d]*)");
    
    public static String decamelizeMatcher(String className) {
        if (className.length() == 0) {
            return "";
        }
        
        String decamelized = decamelizeClassName(className);
        
        if (decamelized.length() == 0) {
            return "<" + className + ">";
        }
        
        return "<" + decamelized + ">";
    }

    private static String decamelizeClassName(String className) {
        Matcher match = CAPS.matcher(className);
        StringBuilder deCameled = new StringBuilder();
        while(match.find()) {
            if (deCameled.length() == 0) {
                deCameled.append(match.group());
            } else {
                deCameled.append(" ");
                deCameled.append(match.group().toLowerCase());
            }
        }
        return deCameled.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy