Class UOption


  • public class UOption
    extends java.lang.Object
    A command-line option. A UOption specifies the name of an option and whether or not it takes an argument. It is a mutable object that later contains the option argument, if any, and a boolean flag stating whether the option was seen or not. The static method parseArgs() takes an array of command-line arguments and an array of UOptions and parses the command-line arguments. This deliberately resembles the icu4c file uoption.[ch].
    • Field Detail

      • longName

        public java.lang.String longName
      • value

        public java.lang.String value
      • context

        public java.lang.Object context
      • shortName

        public char shortName
      • hasArg

        public int hasArg
      • doesOccur

        public boolean doesOccur
    • Constructor Detail

      • UOption

        private UOption​(java.lang.String aLongName,
                        char aShortName,
                        int hasArgument)
        Constructor.
    • Method Detail

      • create

        public static UOption create​(java.lang.String aLongName,
                                     char aShortName,
                                     int hasArgument)
        Create a UOption with the given attributes.
      • DEF

        public static UOption DEF​(java.lang.String aLongName,
                                  char aShortName,
                                  int hasArgument)
        Create a UOption with the given attributes. Synonym for create(), for C compatibility.
      • HELP_H

        public static UOption HELP_H()
      • HELP_QUESTION_MARK

        public static UOption HELP_QUESTION_MARK()
      • VERBOSE

        public static UOption VERBOSE()
      • QUIET

        public static UOption QUIET()
      • VERSION

        public static UOption VERSION()
      • COPYRIGHT

        public static UOption COPYRIGHT()
      • DESTDIR

        public static UOption DESTDIR()
      • SOURCEDIR

        public static UOption SOURCEDIR()
      • ENCODING

        public static UOption ENCODING()
      • ICUDATADIR

        public static UOption ICUDATADIR()
      • PACKAGE_NAME

        public static UOption PACKAGE_NAME()
      • BUNDLE_NAME

        public static UOption BUNDLE_NAME()
      • parseArgs

        public static int parseArgs​(java.lang.String[] argv,
                                    int start,
                                    UOption[] options)
        Java Command line argument parser. This function takes the argv[] command line and a description of the program's options in form of an array of UOption structures. Each UOption defines a long and a short name (a string and a character) for options like "--foo" and "-f". Each option is marked with whether it does not take an argument, requires one, or optionally takes one. The argument may follow in the same argv[] entry for short options, or it may always follow in the next argv[] entry. An argument is in the next argv[] entry for both long and short name options, except it is taken from directly behind the short name in its own argv[] entry if there are characters following the option letter. An argument in its own argv[] entry must not begin with a '-' unless it is only the '-' itself. There is no restriction of the argument format if it is part of the short name options's argv[] entry. The argument is stored in the value field of the corresponding UOption entry, and the doesOccur field is set to 1 if the option is found at all. Short name options without arguments can be collapsed into a single argv[] entry. After an option letter takes an argument, following letters will be taken as its argument. If the same option is found several times, then the last argument value will be stored in the value field. For each option, a function can be called. This could be used for options that occur multiple times and all arguments are to be collected. All options are removed from the argv[] array itself. If the parser is successful, then it returns the number of remaining non-option strings. (Unlike C, the Java argv[] array does NOT contain the program name in argv[0].) An option "--" ends option processing; everything after this remains in the argv[] array. An option string "-" alone is treated as a non-option. If an option is not recognized or an argument missing, then the parser returns with the negative index of the argv[] entry where the error was detected.
        Parameters:
        argv - this parameter is modified
        start - the first argument in argv[] to examine. Must be 0..argv.length-1. Arguments from 0..start-1 are ignored.
        options - this parameter is modified
        Returns:
        the number of unprocessed arguments in argv[], including arguments 0..start-1.
      • setDefault

        public UOption setDefault​(java.lang.String s)
        Allows the default to be set in an option list.
        Parameters:
        s -
        Returns:
        this
      • parseArgs

        public static int parseArgs​(java.lang.String[] argv,
                                    UOption[] options)
        Convenient method.
      • syntaxError

        private static void syntaxError​(java.lang.String message)
        Throw an exception indicating a syntax error.