Source Code Cross Referenced for StringExaminer.java in  » Net » j2ssh » com » sshtools » daemon » util » 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 » Net » j2ssh » com.sshtools.daemon.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  SSHTools - Java SSH2 API
003:         *
004:         *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
005:         *
006:         *  Contributions made by:
007:         *
008:         *  Brett Smith
009:         *  Richard Pernavas
010:         *  Erwin Bolwidt
011:         *
012:         *  This program is free software; you can redistribute it and/or
013:         *  modify it under the terms of the GNU General Public License
014:         *  as published by the Free Software Foundation; either version 2
015:         *  of the License, or (at your option) any later version.
016:         *
017:         *  This program is distributed in the hope that it will be useful,
018:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:         *  GNU General Public License for more details.
021:         *
022:         *  You should have received a copy of the GNU General Public License
023:         *  along with this program; if not, write to the Free Software
024:         *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
025:         */
026:        // ===========================================================================
027:        // CONTENT  : CLASS StringExaminer
028:        // AUTHOR   : Manfred Duchrow
029:        // VERSION  : 1.0 - 29/09/2002
030:        // HISTORY  :
031:        //  29/09/2002  duma  CREATED
032:        //
033:        // Copyright (c) 2002, by Manfred Duchrow. All rights reserved.
034:        // ===========================================================================
035:        package com.sshtools.daemon.util;
036:
037:        // ===========================================================================
038:        // IMPORTS
039:        // ===========================================================================
040:
041:        /**
042:         * As a subclass of StringScanner this class allows more advanced navigation
043:         * over the underlying string.    <br>
044:         * That includes moving to positions of specific substrings etc.
045:         *
046:         * @author Manfred Duchrow
047:         * @version $Id: StringExaminer.java,v 1.7 2003/09/11 15:37:07 martianx Exp $
048:         */
049:        public class StringExaminer extends StringScanner {
050:            // =========================================================================
051:            // CONSTANTS
052:            // =========================================================================
053:            // =========================================================================
054:            // INSTANCE VARIABLES
055:            // =========================================================================
056:            private boolean ignoreCase = false;
057:
058:            // =========================================================================
059:            // CLASS METHODS
060:            // =========================================================================
061:            // =========================================================================
062:            // CONSTRUCTORS
063:            // =========================================================================
064:
065:            /**
066:             * Initialize the new instance with the string to examine.   <br>
067:             * The string will be treated case-sensitive.
068:             *
069:             * @param stringToExamine The string that should be examined
070:             */
071:            public StringExaminer(String stringToExamine) {
072:                this (stringToExamine, false);
073:            }
074:
075:            // StringExaminer()
076:            // -------------------------------------------------------------------------
077:
078:            /**
079:             * Initialize the new instance with the string to examine.
080:             *
081:             * @param stringToExamine The string that should be examined
082:             * @param ignoreCase Specified whether or not treating the string case
083:             *        insensitive
084:             */
085:            public StringExaminer(String stringToExamine, boolean ignoreCase) {
086:                super (stringToExamine);
087:                this .ignoreCase(ignoreCase);
088:            }
089:
090:            // StringExaminer()
091:
092:            /**
093:             *
094:             *
095:             * @return
096:             */
097:            protected boolean ignoreCase() {
098:                return ignoreCase;
099:            }
100:
101:            /**
102:             *
103:             *
104:             * @param newValue
105:             */
106:            protected void ignoreCase(boolean newValue) {
107:                ignoreCase = newValue;
108:            }
109:
110:            // -------------------------------------------------------------------------
111:            // =========================================================================
112:            // PUBLIC INSTANCE METHODS
113:            // =========================================================================
114:
115:            /**
116:             * Increments the position pointer up to the last character that matched
117:             * the character sequence in the given matchString. Returns true, if the
118:             * matchString was found, otherwise false.
119:             *
120:             * <p>
121:             * If the matchString was found, the next invocation of method nextChar()
122:             * returns the first character after that matchString.
123:             * </p>
124:             *
125:             * @param matchString The string to look up
126:             *
127:             * @return
128:             */
129:            public boolean skipAfter(String matchString) {
130:                char ch = '-';
131:                char matchChar = ' ';
132:                boolean found = false;
133:                int index = 0;
134:
135:                if ((matchString == null) || (matchString.length() == 0)) {
136:                    return false;
137:                }
138:
139:                ch = this .nextChar();
140:
141:                while ((endNotReached(ch)) && (!found)) {
142:                    matchChar = matchString.charAt(index);
143:
144:                    if (this .charsAreEqual(ch, matchChar)) {
145:                        index++;
146:
147:                        if (index >= matchString.length()) { // whole matchString checked ?
148:                            found = true;
149:                        } else {
150:                            ch = this .nextChar();
151:                        }
152:                    } else {
153:                        if (index == 0) {
154:                            ch = this .nextChar();
155:                        } else {
156:                            index = 0;
157:                        }
158:                    }
159:                }
160:
161:                return found;
162:            }
163:
164:            // skipAfter()
165:            // -------------------------------------------------------------------------
166:
167:            /**
168:             * Increments the position pointer up to the first character before the
169:             * character sequence in the given matchString. Returns true, if the
170:             * matchString was found, otherwise false.
171:             *
172:             * <p>
173:             * If the matchString was found, the next invocation of method nextChar()
174:             * returns the first character of that matchString from the position where
175:             * it was found inside the examined string.
176:             * </p>
177:             *
178:             * @param matchString The string to look up
179:             *
180:             * @return
181:             */
182:            public boolean skipBefore(String matchString) {
183:                boolean found;
184:                found = this .skipAfter(matchString);
185:
186:                if (found) {
187:                    this .skip(0 - matchString.length());
188:                }
189:
190:                return found;
191:            }
192:
193:            // skipBefore()
194:            // -------------------------------------------------------------------------
195:
196:            /**
197:             * Returns the a string containing all characters from the current position
198:             * up to the end of the examined string.   <br>
199:             * The character position of the examiner is not changed by this method.
200:             *
201:             * @return
202:             */
203:            public String peekUpToEnd() {
204:                return this .upToEnd(true);
205:            }
206:
207:            // peekUpToEnd()
208:            // -------------------------------------------------------------------------
209:
210:            /**
211:             * Returns the a string containing all characters from the current position
212:             * up to the end of the examined string.   <br>
213:             * The character position is put to the end by this method. That means the
214:             * next invocation of nextChar() returns END_REACHED.
215:             *
216:             * @return
217:             */
218:            public String upToEnd() {
219:                return this .upToEnd(false);
220:            }
221:
222:            // upToEnd()
223:
224:            /**
225:             *
226:             *
227:             * @param char1
228:             * @param char2
229:             *
230:             * @return
231:             */
232:            protected boolean charsAreEqual(char char1, char char2) {
233:                return (this .ignoreCase()) ? (Character.toUpperCase(char1) == Character
234:                        .toUpperCase(char2))
235:                        : (char1 == char2);
236:            }
237:
238:            // charsAreEqual()
239:            // -------------------------------------------------------------------------
240:
241:            /**
242:             * Returns the a string containing all characters from the current position
243:             * up to the end of the examined string.   <br>
244:             * Depending on the peek flag the character position of the examiner  is
245:             * unchanged (true) after calling this method or points behind the strings
246:             * last character.
247:             *
248:             * @param peek
249:             *
250:             * @return
251:             */
252:            protected String upToEnd(boolean peek) {
253:                char result = '-';
254:                int lastPosition = 0;
255:                StringBuffer buffer = new StringBuffer(100);
256:                lastPosition = this .getPosition();
257:                result = this .nextChar();
258:
259:                while (endNotReached(result)) {
260:                    buffer.append(result);
261:                    result = this .nextChar();
262:                }
263:
264:                if (peek) {
265:                    this .setPosition(lastPosition);
266:                }
267:
268:                return buffer.toString();
269:            }
270:
271:            // upToEnd()
272:            // -------------------------------------------------------------------------
273:        }
274:
275:        // class StringExaminer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.