From: <chr...@us...> - 2006-04-17 23:55:45
|
Revision: 94 Author: christianhujer Date: 2006-04-17 16:55:39 -0700 (Mon, 17 Apr 2006) ViewCVS: http://svn.sourceforge.net/japi/?rev=94&view=rev Log Message: ----------- Added Grep example. Added Paths: ----------- trunk/src/doc/guide/io/src/GrepJAPI.java Added: trunk/src/doc/guide/io/src/GrepJAPI.java =================================================================== --- trunk/src/doc/guide/io/src/GrepJAPI.java (rev 0) +++ trunk/src/doc/guide/io/src/GrepJAPI.java 2006-04-17 23:55:39 UTC (rev 94) @@ -0,0 +1,43 @@ +import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import net.sf.japi.io.args.ArgParser; +import net.sf.japi.io.args.Command; +import net.sf.japi.io.ARGV; + +/** Implementation of Grep using JAPI. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class GrepJAPI implements Command { + + /** Main program. + * @param args command line arguments + */ + public static void main(final String... args) { + final GrepJAPI grepJAPI = new GrepJAPI(); + ArgParser.parse(grepJAPI, args); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"InstanceMethodNamingConvention"}) + public void run(final List<String> args) { + final String regex = args.remove(0); + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(""); + for (final String line : new ARGV(args.toArray(new String[args.size()]))) { + if (matcher.reset(line).find()) { + System.out.println(line); + } + } + } + + @StopOption @Option({"h", "help"}) + public void help() { + System.out.println("help"); + } + + @StopOption @Option({"V", "version"}) + public void version() { + System.out.println("The version."); + } +} // class GrepJAPI Property changes on: trunk/src/doc/guide/io/src/GrepJAPI.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |