[m-rev.] for review: add string.word_wrap/2

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Mar 30 09:49:27 AEST 2005




On Mon, 28 Mar 2005, Ian MacLarty wrote:

> > > > > +	% Wrapped is Str with newlines inserted between words so that at most
> > > > > +	% N characters appear on a line and each line contains as many
> > > > > +	% whole words as possible.  If any one word exceeds N characters in
> > > > > +	% length then it will be broken over two (or more) lines.
> > > > I think that you should be able to insert a hyphen between the two parts
> > > > of the word in this case.  (Perhaps, make this an optional argument).
> > >
> > > I don't think this'll be particularly useful since words that are longer than
> > > a line typically aren't real words anyway.
> >
> > That rather depends on how large the line width is.  What if the user
> > sets it to say 16 (which is sensible in some contexts, e.g a small text
> > window) but still smaller than some real words.
> >
> > > > > +		string.length(Str) =< N
> > > > It may be worth keeping track of the length of the strings as you go,
> > > > rather than recomputing it all the time.
> > > >
> > >
> > > I doubt it, since it won't be very often that a word needs to be broken up over
> > > multiple lines (with english text and a sensible line width at least).
> >
> > Again, the notion of sensible line width is application dependent.  Since
> > you are putting this in the standard library, as opposed to the debugger,
> > I think that it should be as general as possible.
> >
>
> Alright then, here is the new version of word_wrap with an optional word
> seperator argument:
>
> Index: library/string.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/string.m,v
> retrieving revision 1.230
> diff -u -r1.230 string.m
> --- library/string.m	28 Feb 2005 03:39:38 -0000	1.230
> +++ library/string.m	27 Mar 2005 16:02:19 -0000
> +
> +	% word_wrap(Str, N) = Wrapped.
> +	% Wrapped is Str with newlines inserted between words so that at most
> +	% N characters appear on a line and each line contains as many
> +	% whole words as possible.  If any one word exceeds N characters in
> +	% length then it will be broken over two (or more) lines.
> + 	% Sequences of whitespace characters are replaced by a single space.
> +	%
> +:- func string__word_wrap(string, int) = string.
> +
> +	% word_wrap(Str, N, WordSeperator) = Wrapped.
> +	% word_wrap/3 is like word_wrap/2, except that words that need to be
> +	% broken up over multiple lines have WordSeperator inserted between
> +	% each piece.  If the length of WordSeperator is greater that or equal
> +	% to N, then no seperator is used.
> +	%
> +:- func string__word_wrap(string, int, string) = string.
> +
>  %-----------------------------------------------------------------------------%
>

That's fine.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list