|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.xml.tree.lib;
import org.netbeans.modules.xml.tree.settings.TreeEditSettings;
/**
*
* @author Libor Kramolis
* @version 0.1
*/
public final class StringUtil {
/**
*/
public static String printableValue (String value) {
if (value == null)
return ""; // NOI18N
int ch;
int len;
int prefLen = TreeEditSettings.getDefault().getPrintableValueLength();
if ( prefLen == 0 ) {
len = value.length();
} else {
len = Math.min (value.length(), prefLen);
}
StringBuffer sb = new StringBuffer (2 * len);
for (int i = 0; i < len; i++) {
ch = value.charAt (i);
if ('\r' == ch) {
sb.append("\\r"); // NOI18N
} else if ('\n' == ch) {
sb.append("\\n"); // NOI18N
} else if ('\t' == ch) {
sb.append("\\t"); // NOI18N
} else if ('\b' == ch) {
sb.append("\\b"); // NOI18N
} else if ('\f' == ch) {
sb.append("\\f"); // NOI18N
// } else if ('"' == ch) {
// sb.append("\\\""); // NOI18N
// } else if ('\\' == ch) {
// sb.append("\\\\"); // NOI18N
} else {
sb.append ((char)ch);
}
}
if (value.length() > len)
sb.append ("..."); // NOI18N
return sb.toString();
}
public static boolean isWS(char ch) {
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r';
}
/**
* @param nest list of characters that symetrically delimit some inner token that
* can contain stop delimiter. e.g. <!ENTITY sdsd "sd>">
*/
public static int skipDelimited(String text, int pos, char del1, char del2, String nest) {
char ch = text.charAt(pos);
if ( ch != del1) return -1;
do {
pos++;
ch = text.charAt(pos);
if (nest.indexOf(ch) >= 0) {
pos = skipDelimited(text, pos, ch, ch, "");
ch = text.charAt(pos);
}
} while (ch != del2);
return pos + 1;
}
public static int skipDelimited(String text, int pos, String del1, String del2) {
if (text.startsWith(del1, pos)) {
int match = text.indexOf(del2, pos + del1.length());
if (match == -1) return -1;
return match + del2.length();
} else {
return -1;
}
}
public static int skipWS(String text, int pos) {
if (isWS(text.charAt(pos))) {
return pos + 1;
} else {
return -1;
}
}
/**
* @param args the command line arguments
*/
public static void main (String args[]) {
String idtd = " ]>"; // NOI18N
int pos = 0;
int now = 0;
int last = -1;
System.err.println("SkipWs" + skipWS(" k", pos));
System.err.println("SkipDelinitedchar" + skipDelimited("< ' > '>", 0, '<', '>' ,"\"'"));
System.err.println("SkipDelinitedchar" + skipDelimited("", 0, ""));
while (idtd.substring(pos).startsWith("]>") == false && last != pos) { // NOI18N
last = pos;
for (now = 0; now != -1; now = skipWS(idtd, pos)) pos = now;
for (now = 0; now != -1; now = skipDelimited(idtd, pos, "")) { // NOI18N
pos = now;
for (now = 0; now != -1; now = skipWS(idtd, pos)) pos = now;
}
for (now = 0; now != -1; now = skipDelimited(idtd, pos, '<', '>' , "\"'")) pos = now; // NOI18N
// while(skipWS(idtd, pos));
// while(skipDelimited(idtd, pos, "")) { while(skipWS(idtd, pos));};
// skipDelimited(idtd, pos, '%', ';' , "");
}
}
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.