zlacker

[return to "Please tell us what features you'd like in news.ycombinator"]
1. jonhoh+3V37[view] [source] 2010-09-12 14:52:29
>>pg+(OP)
Truncated URLs may be longer than the original URL if they were just left alone.

The URL truncator will append three periods (not a &helip; character) to the end of a URL. In some cases (say for a URL of 62 characters), the last character will be removed and replaced with three periods. This increases the total size of the URL text to 64 characters.

The algorithm appears to be

    def truncate(word, postfix = '...')
      if ((word + postfix).length > 64)
        word = word[0, 64 - postfix.length] + postfix
      end
      word
    end
There doesn't seem to be a need to add the postfix length to the check. This should suffice:

    def truncate(word, postfix = '…')
      if (word.length > 64)
        word = word[0, 64 - postfix.length] + postfix
      end
      word
    end
◧◩
2. jonhoh+6V37[view] [source] 2010-09-12 14:53:53
>>jonhoh+3V37
Edit: Here is an example:

    http://en.wikipedia.org/wiki/Quartz_Compositor#Quartz_Extreme
becomes

    http://en.wikipedia.org/wiki/Quartz_Compositor#Quartz_Extrem...
[go to top]