Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

edu.virtualschool.jwaa.StringUtil Class Reference

List of all members.

Detailed Description

A grabbag of string utilties I've needed at various times. Some of these can and should be deleted. Copyright 2002 by Brad Cox: <bcox@virtualschool.edu>

Definition at line 16 of file StringUtil.java.

Static Public Member Functions

final RE newRE (String s)
final String replicate (int replications, String s)
final String stripNonAlphabetics (String v)
final String stripNonDigits (Object vv)
final String join (char delimiter, List args)
final String join (char delimiter, Object[] strings)
final String alignLeft (int width, String s)
final String[] split (char delimiter, String string)
String toJavaString (int m, String s)
String replace (Object pattern, Object replacement, Object source)
final String asButton (String op, Object value)
final String asField (String op, Object value, int width)
final String className (Class c)
final String toString (Object o, Validatable[] args)

Static Package Attributes

final Logger logger = Logger.getLogger(StringUtil.class.getName())


Member Function Documentation

final String edu.virtualschool.jwaa.StringUtil.asButton String  op,
Object  value
[static]
 

Compose a submit button with the specified op and value

Deprecated:
: Do not use
Parameters:
op: the field name
value: the field value
Returns:
String

Definition at line 202 of file StringUtil.java.

00203   {
00204     return "<input name=\""+op+"\" value=\""+value+ "\" type=\"submit\">";
00205   }

final String edu.virtualschool.jwaa.StringUtil.asField String  op,
Object  value,
int  width
[static]
 

Compose an <input> field with the specified op, width, and value

Deprecated:
: Do not use
Parameters:
op: the field name
value: the field value
width: the field width
Returns:
String

Definition at line 214 of file StringUtil.java.

00215   {
00216     return "<input name=\""+op+"\" value=\""+value+ "\" size=\""+width+"\">";
00217   }

final String edu.virtualschool.jwaa.StringUtil.join char  delimiter,
List  args
[static]
 

Join the strings with the provided delimiter string

Definition at line 79 of file StringUtil.java.

00080   {
00081     return join(delimiter, args.toArray());
00082   }

final RE edu.virtualschool.jwaa.StringUtil.newRE String  s  )  [static]
 

Convenience method to help subclasses build regular expressions as class initializers without screwing around with REexception. in class initializers. This class catches all REexceptions, logs them, and contiues returning null. Caveat emptor.

Parameters:
s: the regular expression
Returns:
RE

Definition at line 27 of file StringUtil.java.

00028   {
00029     try { return new RE(s); }
00030     catch (REException e)
00031     {
00032       logger.error("REException in\n"+" \""+s+"\"\n", e);
00033       return null;
00034     }
00035   }

String edu.virtualschool.jwaa.StringUtil.replace Object  pattern,
Object  replacement,
Object  source
[static]
 

Replace the first occurrence of the RE pattern in source string.

Parameters:
pattern: the RE to match
replacement: the string to replace it with
source: the source string to be modified
Returns:
Returns the source string if the patter does not occur, otherwise the source modified by replacing the first occurrence of the pattern with the replacement string
Exceptions:
Fault: if the pattern or replacement couldn't be compiled by the regular expression package.

Definition at line 179 of file StringUtil.java.

00180   {
00181     try
00182     {
00183       RE re = new RE(pattern.toString());
00184       return re.substitute(source.toString(), replacement.toString());
00185     }
00186     catch (Exception e) 
00187     {
00188       logger.error("StringUtil.replace: Invalid RE\n"+
00189         " pattern:"+pattern+"\n"+
00190         " replacement:"+replacement+"\n"+
00191         " source:"+source, e);
00192       return source.toString();
00193     }
00194   }

final String edu.virtualschool.jwaa.StringUtil.stripNonAlphabetics String  v  )  [static]
 

Converts a name to the base of an interfier by stripping everything but alphabetics and truncating long ids to a maximum length of 32 chars.

Deprecated:
Fall 2001 in favor of using email addresses to identify accounts.

Definition at line 50 of file StringUtil.java.

00051   {
00052     if (v == null) return null;
00053     StringBuffer buffer = new StringBuffer(v.length());
00054     for (int i = 0; i < v.length(); i++)
00055     {
00056       char c = v.charAt(i);
00057       if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
00058         buffer.append(c);
00059     }
00060     return buffer.toString();
00061   }

String edu.virtualschool.jwaa.StringUtil.toJavaString int  m,
String  s
[static]
 

Wrap the input to m bytes/line and return the result as a concatenated Java string initializer.

Parameters:
s: the input string
m: the line length.
Returns:
String wrapped to m bytes/line

Definition at line 155 of file StringUtil.java.

00156   {
00157     if (s == null) s = "";
00158     int l = s.length();
00159     StringBuffer b = new StringBuffer(s.length() + 2*(l/m)+1);
00160     for (int i = 0; i < l; i += m)
00161     {
00162       int j = i+m;
00163       if (j > l) j = l;
00164       b.append("\"" + s.substring(i, j) + "\"+\n");
00165     }
00166     return b + "\"\"";
00167   }


The documentation for this class was generated from the following file: