addSuffixIfNot static method

String addSuffixIfNot(
  1. String? str,
  2. String suffix
)

如果给定字符串不是以 suffix 结尾的,在尾部补充 suffix

@param str 字符串 @param suffix 后缀 @return 补充后的字符串

Implementation

static String addSuffixIfNot(String? str, String suffix) {
  if (isEmpty(str) || isEmpty(suffix)) {
    return str ?? '';
  }

  if (!str!.endsWith(suffix)) {
    return str + suffix;
  }
  return str;
}