From: Mike S. <ms...@us...> - 2008-01-31 16:28:34
|
Update of /cvsroot/wonder/Wonder/Common/Frameworks/ERExtensions/Sources/er/extensions In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv6595/Sources/er/extensions Modified Files: ERXStringUtilities.java Log Message: this is retarded that this method isn't on StringBuffer already. Index: ERXStringUtilities.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Common/Frameworks/ERExtensions/Sources/er/extensions/ERXStringUtilities.java,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** ERXStringUtilities.java 24 Jan 2008 05:11:35 -0000 1.74 --- ERXStringUtilities.java 31 Jan 2008 16:28:24 -0000 1.75 *************** *** 1650,1652 **** --- 1650,1684 ---- return "{\n" + result + "}\n"; } + + /** + * It's ridiculous that StringBuffer doesn't have a .regionMatches like String. This is + * stolen from String and reimplemnted on top of StringBuffer. It's slightly slower than + * String's because we have to call charAt instead of just accessing the underlying array, + * but so be it. + * + * @param str the StringBuffer to compare a region of + * @param toffset the starting offset of the subregion in this string. + * @param other the string argument. + * @param ooffset the starting offset of the subregion in the string argument. + * @param len the number of characters to compare. + * @return <code>true</code> if the specified subregion of this string + * exactly matches the specified subregion of the string argument; + * <code>false</code> otherwise. + */ + public static boolean regionMatches(StringBuffer str, int toffset, String other, int ooffset, int len) { + int to = toffset; + int po = ooffset; + // Note: toffset, ooffset, or len might be near -1>>>1. + int count = str.length(); + int otherCount = other.length(); + if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len) || (ooffset > (long)otherCount - len)) { + return false; + } + while (len-- > 0) { + if (str.charAt(to++) != other.charAt(po++)) { + return false; + } + } + return true; + } } |