1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 23 public class CamelUtil { 24 25 35 public static String getCamelCase(String s) { 36 StringBuffer result = new StringBuffer (); 37 if (s.length() > 0) { 38 int index = 0; 39 while (index != -1) { 40 result.append(s.charAt(index)); 41 index = getNextCamelIndex(s, index + 1); 42 } 43 } 44 return result.toString().toLowerCase(); 45 } 46 47 58 public static int[][] getCamelCaseIndices(String s, int start, int length) { 59 List result = new ArrayList (); 60 int index = 0; 61 while (start > 0) { 62 index = getNextCamelIndex(s, index + 1); 63 start--; 64 } 65 while (length > 0) { 66 result.add(new int[] { index, index }); 67 index = getNextCamelIndex(s, index + 1); 68 length--; 69 } 70 return (int[][]) result.toArray(new int[result.size()][]); 71 } 72 73 80 public static int getNextCamelIndex(String s, int index) { 81 char c; 82 while (index < s.length() 83 && !(isSeparatorForCamelCase(c = s.charAt(index))) 84 && Character.isLowerCase(c)) { 85 index++; 86 } 87 while (index < s.length() && isSeparatorForCamelCase(c = s.charAt(index))) { 88 index++; 89 } 90 if (index >= s.length()) { 91 index = -1; 92 } 93 return index; 94 } 95 96 103 public static boolean isSeparatorForCamelCase(char c) { 104 return !Character.isLetterOrDigit(c); 105 } 106 107 } 108 | Popular Tags |