Up to Main Index Up to Journal for April, 2013 JOURNAL FOR SUNDAY 14TH APRIL, 2013 ______________________________________________________________________________ SUBJECT: Text folding fixed DATE: Sun Apr 14 21:41:25 BST 2013 I've just finished fixing the text folding function in WolfMUD and pushed out the changes to the public development branch. It now covers all of the corner cases I previously found plus a few found during the fixing. There are also new tests for the text package covering all of the corner cases found. Why did it take so long to fix? Well it's not a simple greedy algorithm that can just put as many words on a line as will fit. It also has to take into consideration zero width escape sequences for colour codes. It also only makes a single copy of the original string. All of the folding is done in-place on the copied string creating very little garbage to be cleaned by the up garbage collector. A typical greedy algorithm[1] would take the length of the line so far, add the length of the next word and see if the total is less than the width being wrapped to. It would then concatenate a space or line break onto the current string and then concatenate the new word onto the line. The concatenation can create a lot of garbage as strings are created and discarded. Now all I need to write is an unfold routine to unfold the initial descriptions read from the wrj files... -- Diddymus [1] See: https://en.wikipedia.org/wiki/Word_wrap Up to Main Index Up to Journal for April, 2013