1 61 package org.apache.commons.cli; 62 63 68 public class OptionValidator { 69 70 85 static void validateOption(String opt) 86 throws IllegalArgumentException 87 { 88 if (opt == null) 90 { 91 return; 92 } 93 94 else if (opt.length() == 1) 96 { 97 char ch = opt.charAt(0); 98 99 if (!isValidOpt(ch)) 100 { 101 throw new IllegalArgumentException ("illegal option value '" + ch 102 + "'"); 103 } 104 } 105 106 else 108 { 109 char[] chars = opt.toCharArray(); 110 111 for (int i = 0; i < chars.length; i++) 112 { 113 if (!isValidChar(chars[i])) 114 { 115 throw new IllegalArgumentException ( 116 "opt contains illegal character value '" + chars[i] 117 + "'"); 118 } 119 } 120 } 121 } 122 123 130 private static boolean isValidOpt(char c) 131 { 132 return (isValidChar(c) || (c == ' ') || (c == '?') || c == '@'); 133 } 134 135 141 private static boolean isValidChar(char c) 142 { 143 return Character.isJavaIdentifierPart(c); 144 } 145 } | Popular Tags |