Windows standalone puzzle
Geoff Canyon
gcanyon at gmail.com
Wed Aug 28 03:54:20 EDT 2013
On Mon, Aug 19, 2013 at 9:43 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:
> function shorten tList
> repeat with n = 1 to the number of lines of tList
> put line n of tList into lineText
> if length(lineText) < 75 then next repeat
> put empty into tBefore
> put empty into tAfter
> if char 43 of line n of tList = space then
> put space into tBefore
> end if
> if char -25 of line n of tList = space then
> put space into tAfter
> end if
> put tBefore & "..." & tAfter into char 43 to -25 of of line n of
> tList
> -- 3 periods, not a numtochar(201)
> end repeat
> return tList
> end shorten
>
Just saw this because of wonky spam filters. You can get identical results
to the above (without the errors) with:
function shorten2 tList
repeat for each line L in tList
if length(L) < 75 then
put L & cr after R
else
put (char 1 to 42 of L) & char (2 - offset(" ",char 43 of L)) to
(-2 + offset(" ",char -25 of L)) of " ... " & (char -24 to -1 of L) & cr
after R
end if
end repeat
return R
end shorten2
That returns variable-length shortened lines, as does the original. If
there isn't a special reason for that, then this is even simpler, and has
the shortening parameters as variables. Just call it with 75 and 43 to get
similar to the original.
function trimLines tList, trimTo, elipseAfter
repeat for each line L in tList
if length(L) <= trimTo then put L & cr after R else put (char 1 to
elipseAfter of L) & "..." & (char (elipseAfter - trimTo + 3) to -1 of L) &
cr after R
end repeat
return R
end trimLines
Both of these scale roughly linearly. For menus it's not likely to be a
factor, but on 3500 lines the original takes about a second on my machine,
and each of these take about a hundredth of a second.
gc
More information about the use-livecode
mailing list