| The output of 'ellipsize is longer than the limit you give it: arc> (ellipsize "abcdef" 4)
"abcd..."
If you actually want the returned string to be no more than the length you pass to it, you must subtract 3 from the length you want: arc> (ellipsize "abcdef" 1)
"a..."
However, by subtracting three from the desired maximum string length, we introduce a different bug. When the input string's length is equal to the desired length, or one or two shorter than it, the string is ellipsized: arc> (ellipsize "abc" 1) ;; We want the output to have a maximum length
;; of 4, so we subtract three from the
;; 'limit argument
"a..."
Note that the ellipsized string was actually longer than the input string!Code to fix this: (def my-ellipsize (str (o limit 80))
(if (<= (len str)
limit)
str
(+ (cut str 0
(max 0 ;; So we never call 'cut with a negative argument
(- limit 3)))
"...")))
We don't need to subtract three from the 'limit argument to 'my-ellipsize: arc> (my-ellipsize "abcdef" 4)
"a..."
And the only strings that will be ellipsized are strings that are longer than 'limit: arc> (my-ellipsize "abc" 4)
"abc"
However, it looks like pg wants 'ellipsize to display 'limit characters of the input ( http://arclanguage.org/item?id=2519 ). That seems ... odd to me. I can't imagine wanting to limit the displayed input length to a certain number, while still being ok with having longer strings than that length. But it's not my language. |