1 16 package org.apache.cocoon.util; 17 18 25 public class StringUtils { 26 27 33 public static String [] split(String line) { 34 return split(line, " \t\n\r"); 35 } 36 37 44 public static String [] split(String line, String delimiter) { 45 return Tokenizer.tokenize(line, delimiter, false); 46 } 47 48 55 public static boolean isAlphaNumeric(char c) { 56 return c == '_' || 57 (c >= 'a' && c <= 'z') || 58 (c >= 'A' && c <= 'Z') || 59 (c >= '0' && c <= '9'); 60 } 61 62 70 public static int count(String str, char c) { 71 int index = 0; 72 char[] chars = str.toCharArray(); 73 for (int i = 0; i < chars.length; i++) { 74 if (chars[i] == c) index++; 75 } 76 return index; 77 } 78 79 87 public static int matchStrings(String a, String b) { 88 int i; 89 char[] ca = a.toCharArray(); 90 char[] cb = b.toCharArray(); 91 int len = ( ca.length < cb.length ) ? ca.length : cb.length; 92 93 for (i = 0; i < len; i++) { 94 if (ca[i] != cb[i]) break; 95 } 96 97 return i; 98 } 99 100 103 public static String replaceToken(String s) { 104 int startToken = s.indexOf("${"); 105 int endToken = s.indexOf("}",startToken); 106 String token = s.substring(startToken+2,endToken); 107 StringBuffer value = new StringBuffer (); 108 value.append(s.substring(0,startToken)); 109 value.append(System.getProperty(token)); 110 value.append(s.substring(endToken+1)); 111 return value.toString(); 112 } 113 } 114 | Popular Tags |