Source Code Cross Referenced for RegexpCmd.java in  » Scripting » jacl » tcl » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * RegexpCmd.java --
003:         *
004:         * 	This file contains the Jacl implementation of the built-in Tcl
005:         *	"regexp" command. 
006:         *
007:         * Copyright (c) 1997-1999 Sun Microsystems, Inc.
008:         *
009:         * See the file "license.terms" for information on usage and
010:         * redistribution of this file, and for a DISCLAIMER OF ALL
011:         * WARRANTIES.
012:         * 
013:         * RCS: @(#) $Id: RegexpCmd.java,v 1.3 2000/02/23 22:07:23 mo Exp $
014:         */
015:
016:        package tcl.lang;
017:
018:        import sunlabs.brazil.util.regexp.Regexp;
019:
020:        /**
021:         * This class implements the built-in "regexp" command in Tcl.
022:         */
023:
024:        class RegexpCmd implements  Command {
025:
026:            static final private String validOpts[] = { "-indices", "-nocase",
027:                    "--" };
028:            static final private int OPT_INDICES = 0;
029:            static final private int OPT_NOCASE = 1;
030:            static final private int OPT_LAST = 2;
031:
032:            /*
033:             *-----------------------------------------------------------------------------
034:             *
035:             * init --
036:             *
037:             *	This procedure is invoked to connect the regexp and regsub commands to
038:             *	the CmdProc method of the RegexpCmd and RegsubCmd classes,
039:             *	respectively.  Avoid the AutoloadStub class because regexp and regsub
040:             *	need a stub with a switch to check for the existence of the tcl.regexp
041:             *	package.
042:             *
043:             * Results:
044:             *	None.
045:             *
046:             * Side effects:
047:             *	The regexp and regsub s]commands are now connected to the CmdProc
048:             *	method of the RegexpCmd and RegsubCmd classes, respectively.
049:             *
050:             *-----------------------------------------------------------------------------
051:             */
052:
053:            static void init(Interp interp) // Current interpreter. 
054:            {
055:                interp.createCommand("regexp", new tcl.lang.RegexpCmd());
056:                interp.createCommand("regsub", new tcl.lang.RegsubCmd());
057:            }
058:
059:            /*
060:             *-----------------------------------------------------------------------------
061:             *
062:             * cmdProc --
063:             *
064:             *	This procedure is invoked to process the "regexp" Tcl command.
065:             *	See the user documentation for details on what it does.
066:             *
067:             * Results:
068:             *	A standard Tcl result.
069:             *
070:             * Side effects:
071:             *	See the user documentation.
072:             *
073:             *-----------------------------------------------------------------------------
074:             */
075:
076:            public void cmdProc(Interp interp, // Current interpreter. 
077:                    TclObject argv[]) // Arguments to "regexp" command.
078:                    throws TclException {
079:                boolean nocase = false;
080:                boolean indices = false;
081:
082:                try {
083:                    int i = 1;
084:                    opts: while (argv[i].toString().startsWith("-")) {
085:                        int index = TclIndex.get(interp, argv[i], validOpts,
086:                                "switch", 0);
087:                        i++;
088:                        switch (index) {
089:                        case OPT_INDICES: {
090:                            indices = true;
091:                            break;
092:                        }
093:                        case OPT_NOCASE: {
094:                            nocase = true;
095:                            break;
096:                        }
097:                        case OPT_LAST: {
098:                            break opts;
099:                        }
100:                        }
101:                    }
102:
103:                    TclObject exp = argv[i++];
104:                    String string = argv[i++].toString();
105:
106:                    int matches = argv.length - i;
107:
108:                    Regexp r = TclRegexp.compile(interp, exp, nocase);
109:
110:                    int[] args = new int[matches * 2];
111:                    boolean matched = r.match(string, args);
112:                    if (matched) {
113:                        for (int match = 0; i < argv.length; i++) {
114:                            TclObject obj;
115:
116:                            int start = args[match++];
117:                            int end = args[match++];
118:                            if (indices) {
119:                                if (end >= 0) {
120:                                    end--;
121:                                }
122:                                obj = TclList.newInstance();
123:                                TclList.append(interp, obj, TclInteger
124:                                        .newInstance(start));
125:                                TclList.append(interp, obj, TclInteger
126:                                        .newInstance(end));
127:                            } else {
128:                                String range = (start >= 0) ? string.substring(
129:                                        start, end) : "";
130:                                obj = TclString.newInstance(range);
131:                            }
132:                            try {
133:                                interp.setVar(argv[i].toString(), obj, 0);
134:                            } catch (TclException e) {
135:                                throw new TclException(interp,
136:                                        "couldn't set variable \"" + argv[i]
137:                                                + "\"");
138:                            }
139:                        }
140:                    }
141:                    interp.setResult(matched);
142:                } catch (IndexOutOfBoundsException e) {
143:                    throw new TclNumArgsException(interp, 1, argv,
144:                            "?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?");
145:                }
146:            }
147:
148:        } // end RegexpCmd
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.