chg: refactored global strippedTags() method to JS
This commit is contained in:
parent
7d07ac4f2d
commit
655f965084
2 changed files with 35 additions and 45 deletions
31
js/Global/stripTags.js
Normal file
31
js/Global/stripTags.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
var stripTags = function (str) {
|
||||||
|
if (str === null) return str;
|
||||||
|
|
||||||
|
var chars = String(str).split('');
|
||||||
|
var charCounter = 0;
|
||||||
|
var inTag = false;
|
||||||
|
|
||||||
|
for (var i = 0, len = str.length; i < len; i += 1) {
|
||||||
|
if (chars[i] === '<') inTag = true;
|
||||||
|
|
||||||
|
if (!inTag) {
|
||||||
|
if (i > charCounter) {
|
||||||
|
chars[charCounter] = chars[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
charCounter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chars[i] === '>') {
|
||||||
|
inTag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > charCounter) {
|
||||||
|
chars.length = charCounter;
|
||||||
|
return chars.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
String[] globalFuncs = {
|
String[] globalFuncs = {
|
||||||
"renderSkin", "renderSkinAsString", "getProperty",
|
"renderSkin", "renderSkinAsString", "getProperty",
|
||||||
"authenticate", "createSkin", "format", "encode",
|
"authenticate", "createSkin", "format", "encode",
|
||||||
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
"encodeXml", "encodeForm", "formatParagraphs",
|
||||||
"getXmlDocument", "getHtmlDocument", "seal",
|
"getXmlDocument", "getHtmlDocument", "seal",
|
||||||
"getDBConnection", "getURL", "write", "writeln",
|
"getDBConnection", "getURL", "write", "writeln",
|
||||||
"serialize", "deserialize", "defineLibraryScope",
|
"serialize", "deserialize", "defineLibraryScope",
|
||||||
|
@ -152,7 +152,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
Skin skin = engine.toSkin(skinobj, "global");
|
Skin skin = engine.toSkin(skinobj, "global");
|
||||||
|
|
||||||
if (skin != null) {
|
if (skin != null) {
|
||||||
skin.render(engine.reval, null,
|
skin.render(engine.reval, null,
|
||||||
(paramobj == Undefined.instance) ? null : paramobj);
|
(paramobj == Undefined.instance) ? null : paramobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,47 +568,6 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* (Try to) strip all HTML/XML style tags from the given string argument
|
|
||||||
*
|
|
||||||
* @param str a string
|
|
||||||
* @return the string with tags removed
|
|
||||||
*/
|
|
||||||
public String stripTags(String str) {
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
char[] c = str.toCharArray();
|
|
||||||
boolean inTag = false;
|
|
||||||
int i;
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < c.length; i++) {
|
|
||||||
if (c[i] == '<') {
|
|
||||||
inTag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inTag) {
|
|
||||||
if (i > j) {
|
|
||||||
c[j] = c[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c[i] == '>') {
|
|
||||||
inTag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > j) {
|
|
||||||
return new String(c, 0, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize a JavaScript object to a file.
|
* Serialize a JavaScript object to a file.
|
||||||
*/
|
*/
|
||||||
|
@ -658,10 +617,10 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set DONTENUM attrubutes on the given properties in this object.
|
* Set DONTENUM attrubutes on the given properties in this object.
|
||||||
* This is set on the JavaScript Object prototype.
|
* This is set on the JavaScript Object prototype.
|
||||||
*/
|
*/
|
||||||
public static Object dontEnum (Context cx, Scriptable thisObj,
|
public static Object dontEnum (Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj) {
|
Object[] args, Function funObj) {
|
||||||
if (!(thisObj instanceof ScriptableObject)) {
|
if (!(thisObj instanceof ScriptableObject)) {
|
||||||
throw new EvaluatorException("dontEnum() called on non-ScriptableObject");
|
throw new EvaluatorException("dontEnum() called on non-ScriptableObject");
|
||||||
|
|
Loading…
Add table
Reference in a new issue