开发者

What should I call the operation that limits a string's length?

This is a language-agnostic question - unless you count English as a language.

I've got this list of items which can have very long names.

For aesthetic purposes, these names must be made shorter in some cases, adding dots (...) to indicate that the name is longer. So for example, if article.na开发者_如何学运维me returns this:

lorem ipsum dolor sit amet

I'd like to get this other output.

lorem ipsum dolor ...

I can program this quite easily. My question is: how should I call that shortening operation? I mean the name, not the implementation. Is there a standard English name for it?


Use 'ellipsize'

UserlandFrontier calls such a method ellipsize:

http://docserver.userland.com/string/ellipsize

So does Android:

http://developer.android.com/reference/android/text/TextUtils.html

and many others (see google)


I'm not a huge fan of creating new words for function names. I'd be inclined to use actual words and call the function TruncateWithEllipsis or something abundantly clear.


Truncation, or soft truncation (because of the ellipsis)

I would call the function truncate, and that seems to be the consensus.

CPAN: http://metacpan.org/pod/String::Truncate
MooTools: https://mootools.lighthouseapp.com/projects/2706/tickets/670-new-addition-stringtruncate-method
Prototype: http://www.prototypejs.org/api/string/truncate
Smarty: http://www.smarty.net/manual/en/language.modifier.truncate.php
Jinja: http://jinja.pocoo.org/docs/templates/#truncate


truncate: To shorten something as if by cutting off part of it.

Source


Although less explicit than Thomas' TruncateWithEllipsis, I might name it abbreviate because I may want to abbreviate things differently in the future, or depending on context, or what the thing I'm abbreviating is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜