1 19 package edu.umd.cs.findbugs.ml; 20 21 import java.util.Collection ; 22 import java.util.HashSet ; 23 import java.util.Locale ; 24 import java.util.Set ; 25 26 31 public class SplitCamelCaseIdentifier { 32 private String ident; 33 34 39 public SplitCamelCaseIdentifier(String ident) { 40 this.ident = ident; 41 } 42 43 48 public Collection <String > split() { 49 String s = ident; 50 Set <String > result = new HashSet <String >(); 51 52 while (s.length() > 0) { 53 StringBuffer buf = new StringBuffer (); 54 55 char first = s.charAt(0); 56 buf.append(first); 57 int i = 1; 58 59 if (s.length() > 1) { 60 boolean camelWord; 61 if (Character.isLowerCase(first)) { 62 camelWord = true; 63 } else { 64 char next = s.charAt(i++); 65 buf.append(next); 66 camelWord = Character.isLowerCase(next); 67 } 68 69 while (i < s.length()) { 70 char c = s.charAt(i); 71 if (Character.isUpperCase(c)) { 72 if (camelWord) 73 break; 74 } else if (!camelWord) { 75 break; 76 } 77 buf.append(c); 78 ++i; 79 } 80 81 if (!camelWord && i < s.length()) { 82 buf.deleteCharAt(buf.length() - 1); 83 --i; 84 } 85 } 86 87 result.add(buf.toString().toLowerCase(Locale.US)); 88 s = s.substring(i); 89 } 90 91 return result; 92 } 93 } 94 | Popular Tags |