Some fixups and enhancements.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4294 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -4,6 +4,22 @@ import mx.utils.*;
|
||||
|
||||
public class StringUtil
|
||||
{
|
||||
/**
|
||||
* Get a reasonable hash code for the specified String.
|
||||
*/
|
||||
public static function hashCode (str :String) :int
|
||||
{
|
||||
var code :int = 0;
|
||||
if (str != null) {
|
||||
// sample at most 8 chars
|
||||
var lastChar :int = Math.min(8, str.length);
|
||||
for (var ii :int = 0; ii < lastChar; ii++) {
|
||||
code = code * 31 + str.charCodeAt(ii);
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
public static function isBlank (str :String) :Boolean
|
||||
{
|
||||
return (str == null) || (str.search("\\S") == -1);
|
||||
@@ -15,7 +31,7 @@ public class StringUtil
|
||||
public static function endsWith (str :String, substr :String) :Boolean
|
||||
{
|
||||
var startDex :int = str.length - substr.length;
|
||||
return (startDex >= 0) && (str.indexOf(substr, startDex) > 0);
|
||||
return (startDex >= 0) && (str.indexOf(substr, startDex) >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user