count property

int get count

统计字符串长度

Implementation

int get count {
  String text = this?.trim() ?? "";
  int len = text.length;
  int _count = 0;
  for (int i = 0; i < len; i++) {
    var c = text.substring(i, i + 1);
    if (RegExp("[\u4e00-\u9fa5]").hasMatch(c)) {
      _count += 2;
    } else {
      _count++;
    }
  }
  return _count;
}