fromString static method

CaseStyle? fromString(
  1. String? value
)

Transforms a String to a CaseStyle

Implementation

static CaseStyle? fromString(String? value) {
  if (value == null || value == none || value == unmodified) {
    return null;
  } else {
    switch (value) {
      case 'camelCase':
        return camelCase;
      case 'pascalCase':
        return pascalCase;
      case 'snakeCase':
        return snakeCase;
      case 'paramCase':
        return paramCase;
      case 'lowerCase':
        return lowerCase;
      case 'upperCase':
        return upperCase;
    }
    if (value.startsWith('custom')) {
      var match = customCase.firstMatch(value);
      if (match == null || match.groupCount != 2) {
        throw FormatException("Cannot parse custom caseStyle expression '$value'");
      }

      TextTransform? head;
      TextTransform? tail;
      String separator;

      var transforms = match.group(1)!;
      if (transforms.length == 1) {
        tail = TextTransformParser.parse(transforms);
      } else if (transforms.length == 2) {
        head = TextTransformParser.parse(transforms[0]);
        tail = TextTransformParser.parse(transforms[1]);
      }

      separator = match.group(2)!;

      return CaseStyle(head: head, tail: tail, separator: separator);
    }
  }
  return null;
}