Hacker News new | comments | show | ask | jobs | submit login

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



Edit: Here is an example:

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

    http://en.wikipedia.org/wiki/Quartz_Compositor#Quartz_Extrem...




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: