From: Dan K. <da...@ku...> - 2001-11-09 01:33:22
|
Below are the diffs for adding a '-strictlength <boolean>' flag to the ::textutil::adjust command as discussed in my previous email. Diffs for all modified files (textutil.n, adjust.tcl, and adjust.test) are included. I discovered what I believe to be a bug in the current implementation of the 'plain' justification when applied to $text2 from the .test file. I added test adjust-2.6 (which works now, but didn't work with CVS HEAD to test for the error condition. I am not used to not having CVS access, so this is my first patch/diffs that I am submitting. Let me know if you need anything else, or if I can do something to make this easier. I diffed against the CVS HEAD (actually against downloads of the CVS HEAD files). Let me know if you have any questions. Thanks, --Dan diff -w textutil2.n textutil.n 111a112,117 > .TP > \fI-strictlength boolean\fR > if set to \fIfalse\fR, a line can exceed the specified '-length' if > a single word is longer than '-length'. If set to \fItrue\fR, words > that are longer than '-length' are split so that no line exceeds > the specified '-length'. Default to \fIfalse\fR. ********************************************************************* diff -w adjust2.tcl adjust.tcl 8a9 > variable StrictLength 0 41a43 > variable StrictLength 0 74a77,82 > -strictlength { > if { ![ string is boolean -strict $value ] } then { > error "expected boolean but got \"$value\"" > } > set StrictLength [ string is true $value ] > } 76c84 < error "bad option \"$option\": must be -full, -justify or -length" --- > error "bad option \"$option\": must be -full, -justify, -length, or -strictlength" 85a94 > variable StrictLength 94a104,145 > > if { $StrictLength } then { > > # Limit the length of a line to $Length. If any single > # word is long than $Length, then split the word into multiple > # words. > > set i 0 > foreach tmpWord $ltext { > if { [ string length $tmpWord ] > $Length } then { > > # Since the word is longer than the line length, > # remove the word from the list of words. Then > # we will insert several words that are less than > # or equal to the line length in place of this word. > > set ltext [ lreplace $ltext $i $i ] > incr i -1 > set j 0 > > # Insert a series of shorter words in place of the > # one word that was too long. > > while { $j < [ string length $tmpWord ] } { > > # Calculate the end of the string range for this word. > > if { [ expr { [string length $tmpWord ] - $j } ] > $Length } then { > set end [ expr { $j + $Length - 1} ] > } else { > set end [ string length $tmpWord ] > } > > set ltext [ linsert $ltext [ expr {$i + 1} ] [ string range $tmpWord $j $end ] ] > incr i > incr j [ expr { $end - $j + 1 } ] > } > } > incr i > } > } > 226a278 > incr i 228c280 < set i -1 --- > set i 0 230d281 < incr i *********************************************************************** diff -w adjust2.test adjust.test 30a31,44 > set text2 "Hello, world! > This is the end, my friend. > > You're just another brick in the wall. > Michele, ma belle, sont des mots qui vont trs bien ensembles, > trs bien ensembles. > > ThisIsSimilarToTextOnlyThisStringHasOneReallyLongWordInIt > > Smoke on the water, and fire in the sky. > Oh Lord, don't let me be misunderstood. > > Cause tramp like us, baby we were born to run." > 166a181,231 > test adjust-2.6 {adjust multi lines with plain justification and long word} { > ::textutil::adjust $text2 -justify plain -length 31 -strictlength 1 > } \ > "Hello, world! This is the end, > my friend. You're just another > brick in the wall. Michele, ma > belle, sont des mots qui vont > tris bien ensembles, tris bien > ensembles. > ThisIsSimilarToTextOnlyThisStri > ngHasOneReallyLongWordInIt > Smoke on the water, and fire in > the sky. Oh Lord, don't let me > be misunderstood. Cause tramp > like us, baby we were born to > run." > > test adjust-2.7 {adjust multi lines with plain justification and strictlength} { > ::textutil::adjust $text2 -justify plain -length 31 -strictlength 1 > } \ > "Hello, world! This is the end, > my friend. You're just another > brick in the wall. Michele, ma > belle, sont des mots qui vont > tris bien ensembles, tris bien > ensembles. > ThisIsSimilarToTextOnlyThisStri > ngHasOneReallyLongWordInIt > Smoke on the water, and fire in > the sky. Oh Lord, don't let me > be misunderstood. Cause tramp > like us, baby we were born to > run." > > test adjust-2.8 {adjust multi lines with left justification and strictlength} { > ::textutil::adjust $text2 -justify left -length 31 -strictlength 1 > } \ > "Hello, world! This is the end, > my friend. You're just another > brick in the wall. Michele, ma > belle, sont des mots qui vont > tris bien ensembles, tris bien > ensembles. > ThisIsSimilarToTextOnlyThisStri > ngHasOneReallyLongWordInIt > Smoke on the water, and fire in > the sky. Oh Lord, don't let me > be misunderstood. Cause tramp > like us, baby we were born to > run." > 170a236 > unset text2 |