1 28 29 30 package com.caucho.quercus.lib; 31 32 import com.caucho.quercus.env.LongValue; 33 import com.caucho.quercus.env.StringValue; 34 import com.caucho.quercus.env.Value; 35 import com.caucho.quercus.module.AbstractQuercusModule; 36 37 public class CtypeModule 38 extends AbstractQuercusModule 39 { 40 public String []getLoadedExtensions() 41 { 42 return new String [] { "ctype" }; 43 } 44 45 public static boolean ctype_alnum(Value value) 46 { 47 if (value instanceof LongValue) 48 return isalnum(value.toInt()); 49 else if (value instanceof StringValue) { 50 String string = value.toString(); 51 52 if (string.length() == 0) 53 return false; 54 55 for (int i = 0; i < string.length(); i++) { 56 if (! isalnum(string.charAt(i))) 57 return false; 58 } 59 60 return true; 61 } 62 else 63 return false; 64 } 65 66 public static boolean ctype_alpha(Value value) 67 { 68 if (value instanceof LongValue) 69 return isalpha(value.toInt()); 70 else if (value instanceof StringValue) { 71 String string = value.toString(); 72 73 if (string.length() == 0) 74 return false; 75 76 for (int i = 0; i < string.length(); i++) { 77 if (! isalpha(string.charAt(i))) 78 return false; 79 } 80 81 return true; 82 } 83 else 84 return false; 85 } 86 87 public static boolean ctype_cntrl(Value value) 88 { 89 if (value instanceof LongValue) 90 return iscntrl(value.toInt()); 91 else if (value instanceof StringValue) { 92 String string = value.toString(); 93 94 if (string.length() == 0) 95 return false; 96 97 for (int i = 0; i < string.length(); i++) { 98 if (! iscntrl(string.charAt(i))) 99 return false; 100 } 101 102 return true; 103 } 104 else 105 return false; 106 } 107 108 public static boolean ctype_digit(Value value) 109 { 110 if (value instanceof LongValue) 111 return isdigit(value.toInt()); 112 else if (value instanceof StringValue) { 113 String string = value.toString(); 114 115 if (string.length() == 0) 116 return false; 117 118 for (int i = 0; i < string.length(); i++) { 119 if (! isdigit(string.charAt(i))) 120 return false; 121 } 122 123 return true; 124 } 125 else 126 return false; 127 } 128 129 130 public static boolean ctype_graph(Value value) 131 { 132 if (value instanceof LongValue) 133 return isgraph(value.toInt()); 134 else if (value instanceof StringValue) { 135 String string = value.toString(); 136 137 if (string.length() == 0) 138 return false; 139 140 for (int i = 0; i < string.length(); i++) { 141 if (! isgraph(string.charAt(i))) 142 return false; 143 } 144 145 return true; 146 } 147 else 148 return false; 149 } 150 151 public static boolean ctype_lower(Value value) 152 { 153 if (value instanceof LongValue) 154 return islower(value.toInt()); 155 else if (value instanceof StringValue) { 156 String string = value.toString(); 157 158 if (string.length() == 0) 159 return false; 160 161 for (int i = 0; i < string.length(); i++) { 162 if (! islower(string.charAt(i))) 163 return false; 164 } 165 166 return true; 167 } 168 else 169 return false; 170 } 171 172 173 public static boolean ctype_print(Value value) 174 { 175 if (value instanceof LongValue) 176 return isprint(value.toInt()); 177 else if (value instanceof StringValue) { 178 String string = value.toString(); 179 180 if (string.length() == 0) 181 return false; 182 183 for (int i = 0; i < string.length(); i++) { 184 if (! isprint(string.charAt(i))) 185 return false; 186 } 187 188 return true; 189 } 190 else 191 return false; 192 } 193 194 public static boolean ctype_punct(Value value) 195 { 196 if (value instanceof LongValue) 197 return ispunct(value.toInt()); 198 else if (value instanceof StringValue) { 199 String string = value.toString(); 200 201 if (string.length() == 0) 202 return false; 203 204 for (int i = 0; i < string.length(); i++) { 205 if (! ispunct(string.charAt(i))) 206 return false; 207 } 208 209 return true; 210 } 211 else 212 return false; 213 } 214 215 public static boolean ctype_space(Value value) 216 { 217 if (value instanceof LongValue) 218 return isspace(value.toInt()); 219 else if (value instanceof StringValue) { 220 String string = value.toString(); 221 222 if (string.length() == 0) 223 return false; 224 225 for (int i = 0; i < string.length(); i++) { 226 if (! isspace(string.charAt(i))) 227 return false; 228 } 229 230 return true; 231 } 232 else 233 return false; 234 } 235 236 public static boolean ctype_upper(Value value) 237 { 238 if (value instanceof LongValue) 239 return isupper(value.toInt()); 240 else if (value instanceof StringValue) { 241 String string = value.toString(); 242 243 if (string.length() == 0) 244 return false; 245 246 for (int i = 0; i < string.length(); i++) { 247 if (! isupper(string.charAt(i))) 248 return false; 249 } 250 251 return true; 252 } 253 else 254 return false; 255 } 256 257 public static boolean ctype_xdigit(Value value) 258 { 259 if (value instanceof LongValue) 260 return isxdigit(value.toInt()); 261 else if (value instanceof StringValue) { 262 String string = value.toString(); 263 264 if (string.length() == 0) 265 return false; 266 267 for (int i = 0; i < string.length(); i++) { 268 if (! isxdigit(string.charAt(i))) 269 return false; 270 } 271 272 return true; 273 } 274 else 275 return false; 276 } 277 278 public static boolean isalnum(int ch) 279 { 280 return Character.isLetterOrDigit(ch); 281 } 282 283 public static boolean isalpha(int ch) 284 { 285 return Character.isLetter(ch); 286 } 287 288 public static boolean iscntrl(int ch) 289 { 290 return Character.isISOControl(ch); 291 } 292 293 public static boolean isdigit(int ch) 294 { 295 return Character.isDigit(ch); 296 } 297 298 public static boolean isgraph(int ch) 299 { 300 return isprint(ch) && !isspace(ch); 301 } 302 303 public static boolean islower(int ch) 304 { 305 return Character.isLowerCase(ch); 306 } 307 308 public static boolean isprint(int ch) 309 { 310 return Character.isValidCodePoint(ch) && !Character.isISOControl(ch); 311 } 312 313 public static boolean ispunct(int ch) 314 { 315 return isprint(ch) && !isspace(ch) && !isalnum(ch); 316 } 317 318 public static boolean isspace(int ch) 319 { 320 return Character.isSpaceChar(ch); 321 } 322 323 public static boolean isupper(int ch) 324 { 325 return Character.isUpperCase(ch); 326 } 327 328 public static boolean isxdigit(int ch) 329 { 330 return ((ch >= '0' && ch <= '9') 331 || (ch >= 'a' && ch <= 'f') 332 || (ch >= 'A' && ch <= 'F')); 333 } 334 } 335 | Popular Tags |