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