¿TIENES ALGUNA DUDA? PONTE EN CONTACTO AHORA MISMO CON NUESTROS ESPECIALISTAS CONTACTANOS AHORA!
/**
* Wraps a chunk of text at a given character count.
* Note that this function needs to be renamed if you are going to use it on a CF MX 6.1 server since 6.1 now has a native wrap() function (that serves a different purpose).
*
* @param str The string to format. (Required)
* @param maxline Length of each line, defaults to 40. (Optional)
* @param br The newline string. Defaults to <br>. (Optional)
* @param breaklongwords Boolean to break words longer than maxline. Defaults to true. (Optional)
* @return Returns a string.
* @author Dave Pomerance (dpomerance@mos.org)
* @version 2, August 19, 2003
*/
var maxline = arguments.length;
var br = " ";
var breaklongwords = 1;
var filetype = "pc";
var eol = chr(13) & chr(10);
var lineofstr = "";
var returnstr = "";
var pos = "";
//check optional args
if(ArrayLen(arguments) eq 2) {
maxline = arguments[2];
}
else if(ArrayLen(arguments) eq 3) {
maxline = arguments[2];
br = arguments[3];
}
else if(ArrayLen(arguments) eq 4) {
maxline = arguments[2];
br = arguments[3];
breaklongwords = arguments[4];
}
// determine file type
if (find(chr(10), str)) {
if (find(chr(13), str)) {
filetype = "pc";
eol = chr(13) & chr(10);
} else {
filetype = "unix";
eol = chr(10);
}
} else if (find(chr(13), str)) {
filetype = "mac";
eol = chr(13);
}
// add space due to CF "feature" of ignoring list elements of length 0
str = replace(str, eol, " #chr(13)#", "ALL") & " ";
for (i=1; i lte listlen(str, chr(13)); i=i+1) {
lineofstr = listgetat(str, i, chr(13));
if (lineofstr eq " ") {
returnstr = returnstr & br;
lineofstr = "";
} else {
// remove the space
lineofstr = left(lineofstr, len(lineofstr)-1);
}
while (len(lineofstr) gt 0) {
// determine wrap point
if (len(lineofstr) lte maxline) pos = len(lineofstr);
else {
pos = maxline - find(" ", reverse(left(lineofstr, maxline))) + 1;
if (pos gt maxline) {
if (breaklongwords) pos = maxline;
else {
pos = find(" ", lineofstr, 1);
if (pos eq 0) pos = len(lineofstr);
}
}
}
// add line to returnstr
returnstr = returnstr & left(lineofstr, pos) & br;
// remove line from lineofstr
lineofstr = removechars(lineofstr, 1, pos);
}
}