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

org.objectweb.cjdbc.common.util.Strings Class Reference

List of all members.

Static Public Member Functions

String replace (String sourceString, String replace, String with)
String replaceCasePreserving (String sourceString, String replace, String with)

Detailed Description

This class provides utilities for Strings manipulation.

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 33 of file Strings.java.


Member Function Documentation

String org.objectweb.cjdbc.common.util.Strings.replace String  sourceString,
String  replace,
String  with
[static]
 

Replaces all occurrences of a String within another String.

Parameters:
sourceString source String
replace text pattern to replace
with replacement text
Returns:
the text with any replacements processed, null if null String input

Definition at line 45 of file Strings.java.

00046   {
00047     if (sourceString == null || replace == null || with == null
00048         || "".equals(replace))
00049     {
00050       return sourceString;
00051     }
00052 
00053     StringBuffer buf = new StringBuffer(sourceString.length());
00054     int start = 0, end = 0;
00055     while ((end = sourceString.indexOf(replace, start)) != -1)
00056     {
00057       buf.append(sourceString.substring(start, end)).append(with);
00058       start = end + replace.length();
00059     }
00060     buf.append(sourceString.substring(start));
00061     return buf.toString();
00062   }

String org.objectweb.cjdbc.common.util.Strings.replaceCasePreserving String  sourceString,
String  replace,
String  with
[static]
 

Replaces all occurrences of a String within another String. The String to be replaced will be replaced ignoring cases, all other cases are preserved in the returned string

Parameters:
sourceString source String
replace text to replace, case insensitive
with replacement text
Returns:
the text with any replacements processed, null if null String input

Definition at line 75 of file Strings.java.

00077   {
00078     if (sourceString == null || replace == null || with == null)
00079     {
00080       return sourceString;
00081     }
00082     String lower = sourceString.toLowerCase();
00083     int shift = 0;
00084     int idx = lower.indexOf(replace);
00085     int length = replace.length();
00086     StringBuffer resultString = new StringBuffer(sourceString);
00087     do
00088     {
00089       resultString = resultString.replace(idx + shift, idx + shift + length,
00090           with);
00091       shift += with.length() - length;
00092       idx = lower.indexOf(with, idx + length);
00093     }
00094     while (idx > 0);
00095 
00096     return resultString.toString();
00097   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:14 2005 for C-JDBC by  doxygen 1.3.9.1