01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: /**
09: * Can tell whether or not options are well-formed.
10: *
11: * @since 1.0
12: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
13: * @version $Id: ParserRules.java,v 1.14 2007/04/10 20:06:25 pholser Exp $
14: */
15: class ParserRules {
16: static final String HYPHEN = "-";
17: static final String DOUBLE_HYPHEN = "--";
18: static final String OPTION_TERMINATOR = DOUBLE_HYPHEN;
19: static final String RESERVED_FOR_EXTENSIONS = "W";
20:
21: protected ParserRules() {
22: throw new UnsupportedOperationException();
23: }
24:
25: static boolean isShortOptionToken(String argument) {
26: return argument.startsWith(HYPHEN) && !HYPHEN.equals(argument)
27: && !isLongOptionToken(argument);
28: }
29:
30: static boolean isLongOptionToken(String argument) {
31: return argument.startsWith(DOUBLE_HYPHEN)
32: && !isOptionTerminator(argument);
33: }
34:
35: static boolean isOptionTerminator(String argument) {
36: return OPTION_TERMINATOR.equals(argument);
37: }
38:
39: private static void checkLegalOptionCharacter(char option) {
40: if (!Character.isLetterOrDigit(option))
41: throw new IllegalOptionSpecificationException(String
42: .valueOf(option));
43: }
44:
45: static void checkLegalOption(String option) {
46: for (int i = 0; i < option.length(); ++i)
47: checkLegalOptionCharacter(option.charAt(i));
48: }
49: }
|