home *** CD-ROM | disk | FTP | other *** search
- // Lemon (HK) Ltd
- // last modified on 30 July 1999
-
- function wrap_text(buf,max){
- var buf_ = new Array();
- var len=buf.length;
- var pos=space=i=j=0;
- var h;
- var rslt = "";
- if (!max) max = 60;
-
- while (i < len) {
- ch = buf.charAt(i);
-
- if (ch == '\r' && buf.charAt(i+1) == '\n') {
- buf_[j++] = buf.substring(pos, i);
- pos = space = (i+=2);
- continue;
- }
- if (ch == '\n' || ch == '\r') {
- buf_[j++] = buf.substring(pos, i);
- pos = space = ++i;
- continue;
- }
-
- if (ch == ' ') space = i;
-
- if (i - pos >= max && space != pos) {
- buf_[j++] = buf.substring(pos, space);
- i = space;
- pos = space+1;
- }
- i++;
- }
- for (j=0; j<buf_.length; j++) rslt += buf_[j] + "\n";
- rslt += buf.substring(pos, i);
- return rslt;
- }
-