headerize function

String headerize(
  1. String str
)

Implementation

String headerize(String str) {
  Map<String, String> exceptions = <String, String>{
    'Call-Id': 'Call-ID',
    'Cseq': 'CSeq',
    'Www-Authenticate': 'WWW-Authenticate'
  };

  List<String> names = str.toLowerCase().replaceAll('_', '-').split('-');
  String hname = '';
  int parts = names.length;
  int part;

  for (part = 0; part < parts; part++) {
    if (part != 0) {
      hname += '-';
    }
    hname +=
        String.fromCharCodes(<int>[names[part].codeUnitAt(0)]).toUpperCase() +
            names[part].substring(1);
  }
  if (exceptions[hname] != null) {
    hname = exceptions[hname]!;
  }

  return hname;
}