Source Code Cross Referenced for RETokenOneOf.java in  » Template-Engine » JDynamiTe » gnu » regexp » 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 » Template Engine » JDynamiTe » gnu.regexp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  gnu/regexp/RETokenOneOf.java
003:         *  Copyright (C) 1998 Wes Biggs
004:         *
005:         *  This library is free software; you can redistribute it and/or modify
006:         *  it under the terms of the GNU Library General Public License as published
007:         *  by the Free Software Foundation; either version 2 of the License, or
008:         *  (at your option) any later version.
009:         *
010:         *  This library is distributed in the hope that it will be useful,
011:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         *  GNU Library General Public License for more details.
014:         *
015:         *  You should have received a copy of the GNU Library General Public License
016:         *  along with this program; if not, write to the Free Software
017:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:         */
019:
020:        package gnu.regexp;
021:
022:        import java.util.Vector;
023:
024:        class RETokenOneOf extends REToken {
025:            private Vector options;
026:            private boolean negative;
027:
028:            // This constructor is used for convenience when we know the set beforehand,
029:            // e.g. \d --> new RETokenOneOf("0123456789",false, ..)
030:            //      \D --> new RETokenOneOf("0123456789",true, ..)
031:
032:            RETokenOneOf(int f_subIndex, String f_options, boolean f_negative,
033:                    boolean f_insens) {
034:                super (f_subIndex);
035:                options = new Vector();
036:                negative = f_negative;
037:                for (int i = 0; i < f_options.length(); i++)
038:                    options.addElement(new RETokenChar(f_subIndex, f_options
039:                            .charAt(i), f_insens));
040:            }
041:
042:            RETokenOneOf(int f_subIndex, Vector f_options, boolean f_negative) {
043:                super (f_subIndex);
044:                options = f_options;
045:                negative = f_negative;
046:            }
047:
048:            int getMinimumLength() {
049:                int min = Integer.MAX_VALUE;
050:                int x;
051:                for (int i = 0; i < options.size(); i++) {
052:                    if ((x = ((REToken) options.elementAt(i))
053:                            .getMinimumLength()) < min)
054:                        min = x;
055:                }
056:                return min;
057:            }
058:
059:            int[] match(CharIndexed input, int index, int eflags,
060:                    REMatch mymatch) {
061:                if (negative
062:                        && (input.charAt(index) == CharIndexed.OUT_OF_BOUNDS))
063:                    return null;
064:
065:                int[] newIndex;
066:                int[] possibles = new int[0];
067:                REToken tk;
068:                for (int i = 0; i < options.size(); i++) {
069:                    tk = (REToken) options.elementAt(i);
070:                    newIndex = tk.match(input, index, eflags, mymatch);
071:
072:                    // Voodoo.
073:                    if ((newIndex == null) && (tk instanceof  RE)
074:                            && (tk.m_subIndex > 0)) {
075:                        mymatch.reset(tk.m_subIndex + 1);
076:                    }
077:
078:                    if (newIndex != null) { // match was successful
079:                        if (negative)
080:                            return null;
081:                        // Add newIndex to list of possibilities.
082:
083:                        int[] temp = new int[possibles.length + newIndex.length];
084:                        System.arraycopy(possibles, 0, temp, 0,
085:                                possibles.length);
086:                        for (int j = 0; j < newIndex.length; j++)
087:                            temp[possibles.length + j] = newIndex[j];
088:                        possibles = temp;
089:                    }
090:                } // try next option
091:                // Now possibles is array of all possible matches.
092:                // Try next with each possibility.
093:
094:                int[] doables = new int[0];
095:                for (int i = 0; i < possibles.length; i++) {
096:                    newIndex = next(input, possibles[i], eflags, mymatch);
097:                    if (newIndex != null) {
098:                        int[] temp = new int[doables.length + newIndex.length];
099:                        System.arraycopy(doables, 0, temp, 0, doables.length);
100:                        for (int j = 0; j < newIndex.length; j++)
101:                            temp[doables.length + j] = newIndex[j];
102:                        doables = temp;
103:                    } else {
104:                        // Voodoo.
105:                        if (m_subIndex > 0) {
106:                            mymatch.reset(m_subIndex + 1);
107:                        }
108:                    }
109:
110:                }
111:
112:                if (doables.length > 0)
113:                    return (negative) ? null : doables;
114:                else
115:                    return (negative) ? next(input, index + 1, eflags, mymatch)
116:                            : null;
117:
118:                // index+1 works for [^abc] lists, not for generic lookahead (--> index)
119:            }
120:
121:            void dump(StringBuffer os) {
122:                os.append(negative ? "[^" : "(?:");
123:                for (int i = 0; i < options.size(); i++) {
124:                    if (!negative && (i > 0))
125:                        os.append('|');
126:                    ((REToken) options.elementAt(i)).dumpAll(os);
127:                }
128:                os.append(negative ? ']' : ')');
129:            }
130:
131:            // Overrides REToken.chain
132:            boolean chain(REToken f_next) {
133:                super .chain(f_next);
134:                for (int i = 0; i < options.size(); i++)
135:                    ((REToken) options.elementAt(i)).setUncle(f_next);
136:                return true;
137:            }
138:
139:            /*
140:            void setUncle(REToken f_next) {
141:              for (int i = 0; i < options.size(); i++)
142:                ((REToken) options.elementAt(i)).setUncle(f_next);
143:            }
144:             */
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.