Moved import-style modules back into repository-style modules.

This commit is contained in:
Daniel Ruthardt 2017-10-07 10:32:41 +02:00 committed by Tobi Schäfer
parent 8e973d1a1a
commit 9f213ab7b9
7 changed files with 182 additions and 129 deletions

View file

@ -1,41 +0,0 @@
var encode = function (str, buffer, encodeNewline) {
str = String(str);
if (str === null || !str.length) return str;
if (!buffer) buffer = [];
if (typeof encodeNewline === 'undefined') encodeNewline = true;
for (var i = 0, len = str.length; i < len; i += 1) {
var char = str.charAt(i);
switch (char) {
case '<':
buffer.push('&lt;');
break;
case '>':
buffer.push('&gt;');
break;
case '&':
buffer.push('&amp;');
break;
case '"':
buffer.push('&quot;');
break;
case '\n':
if (encodeNewline) {
buffer.push("<br class='helma-format' />");
}
buffer.push('\n');
break;
default:
buffer.push(char);
}
}
return buffer.join('');
};

View file

@ -1,10 +0,0 @@
// import 'encode';
var encodeForm = function(str, buffer) {
str = String(str);
if (str === null || !str.length) return str;
if (!buffer) buffer = [];
return encode(str, buffer, false);
};

View file

@ -1,46 +0,0 @@
var encodeXml = function(str, buffer) {
str = String(str);
if (str === null || !str.length) return str;
if (!buffer) buffer = [];
for (var i = 0, len = str.length; i < len; i += 1) {
var char = str.charAt(i);
switch (char) {
case '<':
buffer.push('&lt;');
break;
case '>':
buffer.push('&gt;');
break;
case '&':
buffer.push('&amp;');
break;
case '"':
buffer.push('&quot;');
break;
case '\'':
buffer.push('&#39;');
break;
default:
var charCode = str.charCodeAt(i);
if (charCode < 0x20) {
// sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD.
// The trick is an adaption of java.lang.Character.isSpace().
if (((((1 << 0x9) | (1 << 0xA) | (1 << 0xD)) >> charCode) & 1) !== 0) {
buffer.push(char);
}
} else {
buffer.push(char);
}
}
}
return buffer.join('');
}

View file

@ -1,31 +0,0 @@
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;
};

View file

@ -17,7 +17,7 @@
/**
* @fileoverview Adds useful global macros.
* <br /><br />
* To use this optional module, its repository needs to be added to the
* To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/core/Global.js')
*/
@ -77,3 +77,180 @@ var skin_macro = function(param, name) {
return;
}
/**
* Encodes a string for HTML output and inserts linebreak tags.
*
* Performs the following string manipulations:
* All line breaks (i.e. line feeds) are replaced with <br/> tags.
* All special characters are being replaced with their equivalent HTML entity.
* Existing markup tags are being encoded.
*
* @param {string} text
* The string to encode for HTML output.
* @param {boolean} [encodeNewLine = true]
* If or if not to encode line breaks (i.e. line feeds).
* @return {string}
* The encoded string.
*/
function encode(text, encodeNewLine) {
text = String(text);
if (text === null || !text.length) return text;
var buffer = [];
if (typeof encodeNewline === 'undefined') encodeNewline = true;
for (var i = 0, len = text.length; i < len; i += 1) {
var char = text.charAt(i);
switch (char) {
case '<':
buffer.push('&lt;');
break;
case '>':
buffer.push('&gt;');
break;
case '&':
buffer.push('&amp;');
break;
case '"':
buffer.push('&quot;');
break;
case '\n':
if (encodeNewline) {
buffer.push("<br/>");
}
buffer.push('\n');
break;
default:
buffer.push(char);
}
}
return buffer.join('');
}
/**
* Encodes a string for XML output.
*
* Performs the following string manipulations:
* All special characters are being replaced with their equivalent HTML entity.
* Existing tags, single and double quotes, as well as ampersands are being encoded.
* Some invalid XML characters below '0x20' are removed
*
* @param {string} text
* The string to encode for XML output.
* @return {string}
* The string encoded for XML output.
*/
function encodeXml(text) {
text = String(text);
if (text === null || !text.length) return text;
var buffer = [];
for (var i = 0, len = text.length; i < len; i += 1) {
var char = text.charAt(i);
switch (char) {
case '<':
buffer.push('&lt;');
break;
case '>':
buffer.push('&gt;');
break;
case '&':
buffer.push('&amp;');
break;
case '"':
buffer.push('&quot;');
break;
case '\'':
buffer.push('&#39;');
break;
default:
var charCode = str.charCodeAt(i);
if (charCode < 0x20) {
// sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD.
// The trick is an adaption of java.lang.Character.isSpace().
if (((((1 << 0x9) | (1 << 0xA) | (1 << 0xD)) >> charCode) & 1) !== 0) {
buffer.push(char);
}
} else {
buffer.push(char);
}
}
}
return buffer.join('');
}
/**
* Encodes a string for HTML output, leaving linebreaks untouched.
*
* Performs the following string manipulations:
* Unlike encode, leaves linebreaks untouched. This is what you usually want to do for encoding form content (esp.
* with text input values).
* All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.
* Existing markup tags are being encoded.
*
* @param {string} text
* The string to format for HTML output.
* @return {string}
* The string formatted for HTML output.
*/
var encodeForm = function(text) {
text = String(text);
if (text === null || !text.length) return text;
return encode(str, false);
};
/**
* Removes any markup tags contained in the passed string, and returns the modified string.
*
* @param {string} markup
* The text that is to be stripped of tags.
* @return {string}
* The text with the tags stripped out.
*/
var stripTags = function (markup) {
if (markup === null) return markup;
var chars = String(markup).split('');
var charCounter = 0;
var inTag = false;
for (var i = 0, len = markup.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 markup;
};

View file

@ -21,6 +21,8 @@
* application, for example by calling app.addRepository('modules/core/Object.js')
*/
app.addRepository('modules/core/Global.js');
/**
* Copies the properties of this object into a clone.
* @external

View file

@ -42,6 +42,8 @@ String.URLPATTERN = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\
* application, for example by calling app.addRepository('modules/core/String.js')
*/
app.addRepository('modules/core/Global.js');
/**
* checks if a date format pattern is correct
* @external