Source Code Cross Referenced for StringScanner.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 StringScanner
028:        // AUTHOR   : Manfred Duchrow
029:        // VERSION  : 1.1 - 29/09/2002
030:        // HISTORY  :
031:        //  11/07/2001  duma  CREATED
032:        //	29/09/2002	duma	added		-> endReached(), endNotReached()
033:        //
034:        // Copyright (c) 2001-2002, by Manfred Duchrow. All rights reserved.
035:        // ===========================================================================
036:        package com.sshtools.daemon.util;
037:
038:        // ===========================================================================
039:        // IMPORTS
040:        // ===========================================================================
041:
042:        /**
043:         * Simple scanner that allows to navigate over the characters of a string.
044:         *
045:         * @author Manfred Duchrow
046:         * @version 1.1
047:         */
048:        public class StringScanner {
049:            // =========================================================================
050:            // CONSTANTS
051:            // =========================================================================
052:
053:            /**  */
054:            public static final char END_REACHED = (char) -1;
055:
056:            // =========================================================================
057:            // INSTANCE VARIABLES
058:            // =========================================================================
059:
060:            /**  */
061:            protected int length = 0;
062:
063:            /**  */
064:            protected int position = 0;
065:
066:            /**  */
067:            protected int pos_marker = 0;
068:
069:            /**  */
070:            protected char[] buffer = null;
071:
072:            // -------------------------------------------------------------------------
073:            // =========================================================================
074:            // CONSTRUCTORS
075:            // =========================================================================
076:
077:            /**
078:             * Initialize the new instance with the string that should be scanned.
079:             *
080:             * @param stringToScan
081:             */
082:            public StringScanner(String stringToScan) {
083:                super ();
084:                length = stringToScan.length();
085:                buffer = new char[length];
086:                stringToScan.getChars(0, length, buffer, 0);
087:            }
088:
089:            // StringScanner()
090:            // =========================================================================
091:            // PUBLIC CLASS METHODS
092:            // =========================================================================
093:
094:            /**
095:             * Returns true, if the given character indicates that the end of the
096:             * scanned string is reached.
097:             *
098:             * @param character
099:             *
100:             * @return
101:             */
102:            public boolean endReached(char character) {
103:                return (character == END_REACHED);
104:            }
105:
106:            // endReached()
107:            // -------------------------------------------------------------------------
108:
109:            /**
110:             * Returns true, if the given character does <b>not</b> indicate that the
111:             * end of the scanned string si reached.
112:             *
113:             * @param character
114:             *
115:             * @return
116:             */
117:            public boolean endNotReached(char character) {
118:                return (!endReached(character));
119:            }
120:
121:            // endNotReached()
122:            // =========================================================================
123:            // PUBLIC INSTANCE METHODS
124:            // =========================================================================
125:
126:            /**
127:             * Returns the string the scanner was initialized with
128:             *
129:             * @return
130:             */
131:            public String toString() {
132:                return new String(buffer);
133:            }
134:
135:            // toString()
136:            // -------------------------------------------------------------------------
137:
138:            /**
139:             * Moves the position pointer count characters. positive values move
140:             * forwards, negative backwards. The position never becomes negative !
141:             *
142:             * @param count
143:             */
144:            public void skip(int count) {
145:                position += count;
146:
147:                if (position < 0) {
148:                    position = 0;
149:                }
150:            }
151:
152:            // skip()
153:            // -------------------------------------------------------------------------
154:
155:            /**
156:             * Returns the character at the current position without changing the
157:             * position, that is subsequent calls to this method return always the
158:             * same character.
159:             *
160:             * @return
161:             */
162:            public char peek() {
163:                return ((position < length()) ? buffer[position] : END_REACHED);
164:            }
165:
166:            // skip()
167:            // -------------------------------------------------------------------------
168:
169:            /**
170:             * Returns the character at the current position and increments the
171:             * position afterwards by 1.
172:             *
173:             * @return
174:             */
175:            public char nextChar() {
176:                char next = this .peek();
177:
178:                if (endNotReached(next)) {
179:                    this .skip(1);
180:                }
181:
182:                return next;
183:            }
184:
185:            // nextChar()
186:            // -------------------------------------------------------------------------
187:
188:            /**
189:             * Returns true, if the scanner has reached the end and a further
190:             * invocation  of nextChar() would return the END_REACHED character.
191:             *
192:             * @return
193:             */
194:            public boolean atEnd() {
195:                return (endReached(this .peek()));
196:            }
197:
198:            // atEnd()
199:            // -------------------------------------------------------------------------
200:
201:            /**
202:             * Returns true, if the scanner has not yet reached the end.
203:             *
204:             * @return
205:             */
206:            public boolean hasNext() {
207:                return !this .atEnd();
208:            }
209:
210:            // hasNext()
211:            // -------------------------------------------------------------------------
212:
213:            /**
214:             * Returns the next character that is no whitespace and leaves the position
215:             * pointer one character after the returned one.
216:             *
217:             * @return
218:             */
219:            public char nextNoneWhitespaceChar() {
220:                char next = this .nextChar();
221:
222:                while ((endNotReached(next)) && (Character.isWhitespace(next))) {
223:                    next = this .nextChar();
224:                }
225:
226:                return next;
227:            }
228:
229:            // nextNoneWhitespaceChar()
230:            // -------------------------------------------------------------------------
231:
232:            /**
233:             * Returns the current position in the string
234:             *
235:             * @return
236:             */
237:            public int getPosition() {
238:                return position;
239:            }
240:
241:            // getPosition()
242:            // -------------------------------------------------------------------------
243:
244:            /**
245:             * Remembers the current position for later use with restorePosition()
246:             */
247:            public void markPosition() {
248:                pos_marker = position;
249:            }
250:
251:            // markPosition()
252:            // -------------------------------------------------------------------------
253:
254:            /**
255:             * Restores the position to the value of the latest markPosition() call
256:             */
257:            public void restorePosition() {
258:                this .setPosition(pos_marker);
259:            }
260:
261:            // restorePosition()
262:
263:            /**
264:             *
265:             *
266:             * @return
267:             */
268:            protected int length() {
269:                return length;
270:            }
271:
272:            // length()
273:            // -------------------------------------------------------------------------
274:            protected void setPosition(int pos) {
275:                if ((pos >= 0) && (pos <= this .length())) {
276:                    position = pos;
277:                }
278:            }
279:
280:            // setPosition()
281:            // -------------------------------------------------------------------------
282:        }
283:
284:        // class StringScanner
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.