Added parseURLs().
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4484 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -145,6 +145,31 @@ public class StringUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locate URLs in a string, return an array in which even elements
|
||||||
|
* are plain text, odd elements are urls (as Strings). Any even element
|
||||||
|
* may be an empty string.
|
||||||
|
*/
|
||||||
|
public static function parseURLs (s :String) :Array
|
||||||
|
{
|
||||||
|
var array :Array = [];
|
||||||
|
while (true) {
|
||||||
|
var result :Object = URL_REGEXP.exec(s);
|
||||||
|
if (result == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var index :int = int(result.index);
|
||||||
|
var url :String = String(result[0]);
|
||||||
|
array.push(s.substring(0, index), url);
|
||||||
|
s = s.substring(index + url.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// just the string is left
|
||||||
|
array.push(s);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a string from the supplied bytes that is the hex encoded
|
* Generates a string from the supplied bytes that is the hex encoded
|
||||||
* representation of those byts. Returns the empty String for a
|
* representation of those byts. Returns the empty String for a
|
||||||
@@ -188,5 +213,9 @@ public class StringUtil
|
|||||||
/** Hexidecimal digits. */
|
/** Hexidecimal digits. */
|
||||||
protected static const HEX :Array = [ "0", "1", "2", "3", "4",
|
protected static const HEX :Array = [ "0", "1", "2", "3", "4",
|
||||||
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
|
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
|
||||||
|
|
||||||
|
/** A regular expression that finds URLs. */
|
||||||
|
protected static const URL_REGEXP :RegExp =
|
||||||
|
new RegExp("(http|https|ftp)://\\S+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user