Subj : fried brain
To : All
From : X V Lxxix
Date : Fri May 09 2008 10:54 am
Can anyone take a look at this and tell me why, when given a string and a
specified width for word wrapping, it sometimes trims the string way too
short, or 3 or 4 characters too long? I've been frying my brain with this and
I just can't get it straightened out:
this.FitMsg=function(text)
{
var msg=text;
if(console.strlen(msg)>=this.width) {
while(console.strlen(msg)>=this.width) {
var test_index=this.width;
while(console.strlen(text.substring(0,test_index))
<this.width)
{
if(msg.charAt(test_index)==" " ||
msg.charAt(test_index+1)==" ") break;
else if(msg.charAt(test_index)=="\1") {
test_index++;
}
test_index++;
}
var push=this.RemoveSpaces(msg.substring
(0,test_index));
if(push.lastIndexOf(" ")>(this.width/2)) {
test_index=push.lastIndexOf(" ");
push=this.RemoveSpaces(push.substring
(0,test_index));
}
this.messages.push(push);
this.log.Log("adding text to msg buffer: " + push);
msg=this.RemoveSpaces(msg.slice(test_index));
}
this.messages.push(this.RemoveSpaces(msg));
}
else this.messages.push(text);
while(this.messages.length>this.height)
this.message_history=this.messages.shift();
this.needs_update=true;
}
this.RemoveSpaces=function(text)
{
while(text.indexOf(" ")==0) text=text.slice(1);
return truncsp(text);
}
this is an excerpt from a larger piece of code, so some of the variables used
in the functions are declared elsewhere.
---
� Synchronet � Vertrauen � Home of Synchronet � telnet://vert.synchro.net