Talk:Word wrap

Revision as of 10:24, 21 August 2013 by rosettacode>Paddy3118 (→‎handling long words: too much for this task.)

Run BASIC

Hmm. I definitely think the task requirements should be changed, just not sure how yet. Not sure I want to disallow external programs, but a solution doesn't meet my intent if the wrapped text is never returned to the main program. —Sonia 20:56, 28 March 2012 (UTC)

After sleeping on it, maybe it's okay. I did say simple, and the solution does after all, show the wrapped text pasted back into RC as output. —Sonia 00:33, 30 March 2012 (UTC)

more options

I think it would be nice to add some options:

--justification-- (aligning the left AND right margins.
--left ragged edge-- as if the text is meant to be read from right to left (also called right justification).
--sentences-- add extra blanks for end-of-sentences.
--centering-- centered justification.
--margins-- support the use of margins.
--indentation-- also, support negative indentations.
--paragraphs-- whenever a blank line, or (say), when the ¶ (paragraph) symbol is detected.
--columnar output-- support multiple (newspaper) columns (with/without a separator border). -- Gerard Schildberger 03:52, 31 March 2012 (UTC)
Thanks for the ideas! Some of these I had thought of, but I wanted to leave the basic task as simple as possible, letting people either code a very simple algorithm or show an equivalent even simpler method. Your ideas might make interesting extra credit or even separate tasks. Of course, It's a wiki...you can make any changes you feel strongly about; I just liked the least squares metric described in the WP article and though an alternative algorithm would make interesting extra credit and that adding that would be plenty for a single task. —Sonia 17:29, 1 April 2012 (UTC)

There are two tasks relating to word wrapping

Some languages provide an inbuilt facility for word wrap within the width of the screen (whereas wrap to a particular column width involves a bulkier overhead). We also need a wordwrap task to demonstrate the simpler scenario of wrapping to screen width. This would give us two tasks: Wordwrap/Screen Width and Wordwrap/Custom Width.

Markhobley 19:25, 5 February 2013 (UTC)

handling long words

This subject came up in a REXX newsgroup some time ago (regarding the formatting of text).

What does a word-wrapper program do when encountering a word longer than the working margins?
Several choices:

  • truncate the word
  • truncate the word (with footnote or some such indicator)
  • show as-is
  • hyphenate the word
  • other

My REXX program (version 1) doesn't truncate long words, but instead, show the word in its entirety (with possible wrapping), thereby preserving the text content.   Other programs are not so kind (some even loop forever), but I suppose this situation is beyond the intent of the task.
By the way, REXX has the feature that if you display a line wider than the terminal (or window), it will break up the line and show the full text. -- Gerard Schildberger (talk) 21:05, 20 August 2013 (UTC)

Hi Gerard, there is also the option of using a smaller font that you get in some spreadsheets, but what I'd go for if I was reading an ebook for example, would be intelligent hyphenation - for example by not splitting mid-syllab-
le. --Paddy3118 (talk) 04:40, 21 August 2013 (UTC)
Wouldn't proper (correct) hyphenation be way beyond the scope of this task (and wiki)? --Walterpachl (talk) 06:42, 21 August 2013 (UTC)
Oh yes. I just took the question as asking "in a perfect world ...". --Paddy3118 (talk) 10:24, 21 August 2013 (UTC)

REXX Timings

I created a file containing one line of about 1000000 characters containing words of 1 to 90 characters, randomly distributed such as

'A nnnnnnnnnnnnnn ooooooooooooooo nnnnnnnnnnnnnn cccc...'

Timing of the 3 versions show on Windows XP using ooRexx:

    width 10  72  1000
version 0 29  27    19 seconds 
version 1 30  28    19 seconds 
version 2 16  10     3 seconds

versions 0 and 1 adapted as usual: @->a, $->d, = -> =""

version 0 has a minor flaw: The output has a leading blank. Otherwise outputs are identical. --Walterpachl (talk) 09:55, 21 August 2013 (UTC)

Return to "Word wrap" page.