createCaseFirst function

Function createCaseFirst(
  1. String methodName
)

Implementation

Function createCaseFirst(String methodName) {
  return (String string) {
    List<String> strSymbols = hasUnicode(string) ? stringToArray(string) : [];

    String chr = strSymbols.isNotEmpty ? strSymbols[0] : string[0];

    var trailing = strSymbols.isNotEmpty
        ? castSlice(strSymbols, 1).join('')
        : string.substring(1);

    if (methodName == 'toUpperCase') {
      return chr.toUpperCase() + trailing;
    } else if (methodName == 'toLowerCase') {
      return chr.toLowerCase() + trailing;
    }
  };
}