1/* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6package org.mockito.internal.util; 7 8import java.util.regex.Matcher; 9import java.util.regex.Pattern; 10 11//TODO SF move to matchers.text 12public class Decamelizer { 13 14private static final Pattern CAPS = Pattern.compile("([A-Z\\d][^A-Z\\d]*)"); 15 16 public static String decamelizeMatcher(String className) { 17 if (className.length() == 0) { 18 return "<custom argument matcher>"; 19 } 20 21 String decamelized = decamelizeClassName(className); 22 23 if (decamelized.length() == 0) { 24 return "<" + className + ">"; 25 } 26 27 return "<" + decamelized + ">"; 28 } 29 30 private static String decamelizeClassName(String className) { 31 Matcher match = CAPS.matcher(className); 32 StringBuilder deCameled = new StringBuilder(); 33 while(match.find()) { 34 if (deCameled.length() == 0) { 35 deCameled.append(match.group()); 36 } else { 37 deCameled.append(" "); 38 deCameled.append(match.group().toLowerCase()); 39 } 40 } 41 return deCameled.toString(); 42 } 43} 44