当前位置: 首页>>代码示例>>C++>>正文


C++ ParserResult::apply方法代码示例

本文整理汇总了C++中ParserResult::apply方法的典型用法代码示例。如果您正苦于以下问题:C++ ParserResult::apply方法的具体用法?C++ ParserResult::apply怎么用?C++ ParserResult::apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserResult的用法示例。


在下文中一共展示了ParserResult::apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
                     .doc("Skip files whose base name matches any of the file-name globs read from @v{file} "
                          "(using wildcard matching as described under @s{exclude})."));
    selection.insert(Switch("", 'I')
                     .intrinsicValue(BIN_SKIP, opt.binaryFile)
                     .doc("Process a binary file as if it did not contain matching data; this is equivalent "
                          "to the \"@s{binary-files}=without-match\" option."));
    selection.insert(Switch("include")
                     .argument("glob", anyParser(opt.includeGlob))
                     .doc("Search only files whose base names match @v{glob} (using wildcard matching as "
                          "described under @s{exclude})."));
    selection.insert(Switch("recursive", 'R')
                     .shortName('r')
                     .intrinsicValue(ACTION_RECURSE, opt.directoryAction)
                     .doc("Read all files under each directory, recursively; this is equivalent to the "
                          "\"@s{d} recurse\" option."));

    SwitchGroup misc("Other Options");
    misc.switchOrder(INSERTION_ORDER);
    misc.insert(Switch("line-buffered")
                .intrinsicValue(true, opt.lineBuffered)
                .doc("Use line buffering on output.  This can cause a performance penalty."));
    misc.insert(Switch("mmap")
                .intrinsicValue(true, opt.useMmap)
                .doc("If possible, use the @man{mmap}{2} system call to read input, instead of the default "
                     "@man{read}{2} system call.  In some situations, @s{mmap} yields better performance.  "
                     "However, @s{mmap} can cause undefined behavior (including core dumps) if an input "
                     "file shrinks while @prop{programName} is operating, or if an I/O error occurs."));
    misc.insert(Switch("binary", 'U')
                .intrinsicValue(true, opt.openAsBinary)
                .doc("Treat the file(s) as binary.  By default, under MS-DOS and MS-Windows, "
                     "@prop{programName} guesses the file type by looking at the contents of the first 32kB "
                     "read from the file.  If @prop{programName} decides the file is a text file, it strips "
                     "the CR characters from the original file contents (to make regular expressions with "
                     "\"^\" and \"$\" work correctly).  Specifying @s{U} overrules this guesswork, causing all "
                     "files to be read and passed to the matching mechanism verbatim; if the file is a text file "
                     "with CR/LF pairs at the end of each line, this will cause some regular expressions to "
                     "fail.  This option has no effect on platforms other than MS-DOS and MS-Windows."));
    misc.insert(Switch("null-data", 'Z')
                .intrinsicValue(true, opt.nulTerminatedLines)
                .doc("Treat the input as a set of lines, each terminated by a zero byte (the ASCII NUL character) "
                     "instead of a newline.  Like the @s{Z} or @s{null} option, this option can be used with "
                     "commands like \"sort -z\" to process arbitrary file names."));


    // Build the parser
    Parser parser;
    parser
        .with(generic)
        .with(matcher)
        .with(control)
        .with(output)
        .with(prefix)
        .with(context)
        .with(selection)
        .with(misc);

    // Add some top-level documentation.
    parser
        .programName("demoGrep")                        // override the real command name
        .purpose("print lines matching a pattern")
        .version(VERSION_STRING)
        .doc("Synopsis",
             "@b{@prop{programName}} [@v{options}] @v{pattern} [@v{file}...]\n\n"
             "@b{@prop{programName}} [@v{options}] [@s{e} @v{pattern} | @s{f} @v{file}] [@v{file}...]")
        .doc("Description",
             "@prop{programName} searches the named input @v{file}s (or standard input if no files are named, or if "
             "a single hyphen-minus (\"-\") is given as the file name) for lines containing a match to the given "
             "@v{pattern}.  By default, @prop{programName} prints the matching lines."
             "\n\n"
             "In addition, three variant programs egrep, fgrep, and rgrep are available.  egrep is the same as "
             "\"@prop{programName} @s{E}\"; fgrep is the same as \"@prop{programName} @s{F}\"; rgrep is the same as "
             "\"@prop{programName} @s{r}\".  Direct invocation as either \"egrep\" or \"fgrep\" is deprecated, but "
             "is provided to allow historical applications that rely on them to run unmodified.")
        .doc("Regular Expressions",
             "A regular expression is a pattern that describes a set of strings.  Regular expressions are "
             "constructed analogously to arithmetic expressions, by using various operators to combine smaller "
             "expressions."
             "\n\n"
             "@prop{programName} understands three different versions of regular expression syntax: \"basic,\" "
             "\"extended\" and \"perl.\"  In @prop{programName}, there is no difference in available functionality "
             "between basic and extended syntaxes.  In other implementations, basic regular expressions are less "
             "powerful.  The following description applies to extended regular expressions; differences for basic "
             "regular expressions are summarized afterwards.  Perl regular expressions give additional functionality, "
             "and are documented in @man{pcresyntax}{3} and @man{pcrepattern}{3}, but may not be available on every "
             "system."
             "\n\n"
             "The fundamental building blocks are the regular expressions that match a single character.  Most "
             "characters, including all letters and digits, are regular expressions that  match  themselves.   Any "
             "meta-character with special meaning may be quoted by preceding it with a backslash."
             "\n\n"
             "The period \".\" matches any single character.");


    // Parse the command-line
    ParserResult cmdline = parser.parse(argc, argv);

    // Apply the parser results, causing values to be saved and actions to be executed.
    cmdline.apply();

}
开发者ID:matzke1,项目名称:sawyer,代码行数:101,代码来源:grepExample.C


注:本文中的ParserResult::apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。