forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddSlashes.as
More file actions
24 lines (21 loc) · 696 Bytes
/
addSlashes.as
File metadata and controls
24 lines (21 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package utils.string
{
/**
* Returns the string with slashes prepended to all characters specified in the <code>chars</code> parameter
* @param str the string to return slashed
* @param chars the string of chars to slash
* @return
*/
public function addSlashes(str:String, chars:String = "\""):String
{
// return the unaltered string if str or chars are null or empty
if (!str || !chars)
return str;
// slash unsafe characters
chars = slashUnsafeChars(chars);
// build the regular expression that handles the slashing
var regex:RegExp = new RegExp("([" + chars + "])", "g");
// add the slashes to the specified characters
return str.replace(regex, "\\$1");
}
}