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:
@@ -1,7 +1,11 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Contains methods that should be in Array, but aren't.
|
||||
* Contains methods that should be in Array, but aren't. Additionally
|
||||
* contains methods that understand the interfaces in this package.
|
||||
* So, for example, removeFirst() understands Equalable and will remove
|
||||
* an element that is equals() to the specified element, rather than just
|
||||
* ===.
|
||||
*/
|
||||
public class ArrayUtil
|
||||
{
|
||||
@@ -24,6 +28,18 @@ public class ArrayUtil
|
||||
});
|
||||
}
|
||||
|
||||
public static function indexOf (arr :Array, element :Object) :int
|
||||
{
|
||||
if (arr != null) {
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
if (Util.equals(arr[ii], element)) {
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1; // never found
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first instance of the specified element from the array.
|
||||
*/
|
||||
|
||||
@@ -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