[javascript]代码库
/* globals angular: false */
angular.module(window.appModule).filter('cut', function () {
return function (value, wordwise, max, tail) {
if (!value) return '';
if(!wordwise){
return value;
}
max = parseInt(max, 10);
if (!max) return value;
str_cut = new String();
for(var i = 0,str_length = 0;i<value.length;i++)
{
var a = value.charAt(i);
str_length++;
if(escape(a).length > 4)
{
//中文字符的长度经编码之后大于4
str_length++;
}
str_cut = str_cut.concat(a);
if(str_length>=max)
{
return str_cut+ (tail || ' …');
}
}
return value
};
});