modify method

String modify({
  1. CaseFormat? format,
  2. CaseType? type,
  3. String modifier = '',
})

Implementation

String modify({
  CaseFormat? format,
  CaseType? type,
  String modifier = '',
}) {
  if (isValid && format != null) {
    final isSentence = format == CaseFormat.sentence;
    var list = use.split(format.value);
    var result = '';
    if (list.isNotEmpty) {
      for (int index = 0; index < list.length; index++) {
        final item = list[index];
        final target = item.isNotEmpty ? item.characters.first : '';
        final characters = item.characters.toList();
        if (characters.isNotEmpty) {
          var v = type != null
              ? type == CaseType.uppercase
                  ? target.toUpperCase()
                  : target.toLowerCase()
              : target;
          characters.removeAt(0);
          characters.insert(0, v);
          String value = '';
          for (String c in characters) {
            value = "$value$c";
          }

          if (index == list.length - 1) {
            result = '$result$value';
          } else {
            if (isSentence) {
              result = '$result$value. $modifier';
            } else {
              result = '$result$value $modifier';
            }
          }
        }
      }
    }
    return result;
  } else {
    return use;
  }
}