Source Code Cross Referenced for WildcardPattern.java in  » Scripting » jruby » jregex » 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 » jruby » jregex 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2001, Sergey A. Samokhodkin
003:         * All rights reserved.
004:         * 
005:         * Redistribution and use in source and binary forms, with or without modification, 
006:         * are permitted provided that the following conditions are met:
007:         * 
008:         * - Redistributions of source code must retain the above copyright notice, 
009:         * this list of conditions and the following disclaimer. 
010:         * - Redistributions in binary form 
011:         * must reproduce the above copyright notice, this list of conditions and the following 
012:         * disclaimer in the documentation and/or other materials provided with the distribution.
013:         * - Neither the name of jregex nor the names of its contributors may be used 
014:         * to endorse or promote products derived from this software without specific prior 
015:         * written permission. 
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
018:         * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
019:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
020:         * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
021:         * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
022:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
023:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
024:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
025:         * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026:         * 
027:         * @version 1.2_01
028:         */package jregex;
029:
030:        /**
031:         * A Pattern subclass that accepts a simplified pattern syntax:
032:         * <li><code>?<code> - matches any single character;
033:         * <li><code>*<code> - matches any number of any characters;
034:         * <li>all the rest      - matches itself.
035:         * Each wildcard takes a capturing group withing a pattern.
036:         * 
037:         * @see        Pattern
038:         */
039:
040:        public class WildcardPattern extends Pattern {
041:            //a wildcard class, see WildcardPattern(String,String,int)
042:            public static final String WORD_CHAR = "\\w";
043:
044:            //a wildcard class, see WildcardPattern(String,String,int)
045:            public static final String ANY_CHAR = ".";
046:
047:            private static final String defaultSpecials = "[]().{}+|^$\\";
048:            private static final String defaultWcClass = ANY_CHAR;
049:
050:            protected static String convertSpecials(String s, String wcClass,
051:                    String specials) {
052:                int len = s.length();
053:                StringBuffer sb = new StringBuffer();
054:                for (int i = 0; i < len; i++) {
055:                    char c = s.charAt(i);
056:                    switch (c) {
057:                    case '*':
058:                        sb.append("(");
059:                        sb.append(wcClass);
060:                        sb.append("*)");
061:                        break;
062:                    case '?':
063:                        sb.append("(");
064:                        sb.append(wcClass);
065:                        sb.append(")");
066:                        break;
067:                    default:
068:                        if (specials.indexOf(c) >= 0)
069:                            sb.append('\\');
070:                        sb.append(c);
071:                    }
072:                }
073:                return sb.toString();
074:            }
075:
076:            private String str;
077:
078:            /**
079:             * @param  wc    The pattern
080:             */
081:            public WildcardPattern(String wc) {
082:                this (wc, true);
083:            }
084:
085:            /**
086:             * @param  wc    The pattern
087:             * @param  icase If true, the pattern is case-insensitive.
088:             */
089:            public WildcardPattern(String wc, boolean icase) {
090:                this (wc, icase ? DEFAULT | IGNORE_CASE : DEFAULT);
091:            }
092:
093:            /**
094:             * @param  wc    The pattern
095:             * @param  flags The bitwise OR of any of REFlags.* . The only meaningful
096:             * flags are REFlags.IGNORE_CASE and REFlags.DOTALL (the latter allows 
097:             * the wildcards to match the EOL characters).
098:             */
099:            public WildcardPattern(String wc, int flags) {
100:                compile(wc, defaultWcClass, defaultSpecials, flags);
101:            }
102:
103:            /**
104:             * @param  wc       The pattern
105:             * @param  wcClass  The wildcard class, could be any of WORD_CHAR or ANY_CHAR
106:             * @param  flags    The bitwise OR of any of REFlags.* . The only meaningful
107:             * flags are REFlags.IGNORE_CASE and REFlags.DOTALL (the latter allows 
108:             * the wildcards to match the EOL characters).
109:             */
110:            public WildcardPattern(String wc, String wcClass, int flags) {
111:                compile(wc, wcClass, defaultSpecials, flags);
112:            }
113:
114:            protected WildcardPattern() {
115:            }
116:
117:            protected void compile(String wc, String wcClass, String specials,
118:                    int flags) {
119:                String converted = convertSpecials(wc, wcClass, specials);
120:                try {
121:                    compile(converted, flags);
122:                } catch (PatternSyntaxException e) {
123:                    //something unexpected
124:                    throw new Error(e.getMessage() + "; original expr: " + wc
125:                            + ", converted: " + converted);
126:                }
127:                str = wc;
128:            }
129:
130:            public String toString() {
131:                return str;
132:            }
133:
134:            /*
135:            public static void main(String[] args){
136:               Pattern p=new WildcardPattern("*.???");
137:               Matcher m=p.matcher("abc.def");
138:               //System.out.println(p.toString_d());
139:               while(m.proceed()){
140:                  System.out.println(m);
141:                  System.out.println("groups: "+m.groupv());
142:               }
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.