Browse Source

fix _toDartName

pull/201/head
Nikolas Rimikis 2 years ago
parent
commit
929dab205e
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 36
      packages/dynamite/lib/src/openapi_builder.dart

36
packages/dynamite/lib/src/openapi_builder.dart

@ -975,37 +975,27 @@ class OpenAPIBuilder implements Builder {
String _clientName(final String tag) => '${_toDartName(tag, uppercaseFirstCharacter: true)}Client';
String _toDartName(
final String input, {
final String name, {
final bool uppercaseFirstCharacter = false,
}) {
final result = StringBuffer();
final parts = input.split('');
for (var i = 0; i < parts.length; i++) {
var char = parts[i];
final prevChar = i > 0 ? parts[i - 1] : null;
var result = '';
var upperCase = uppercaseFirstCharacter;
var firstCharacter = !uppercaseFirstCharacter;
for (final char in name.split('')) {
if (_isNonAlphaNumericString(char)) {
continue;
}
if (prevChar != null && _isNonAlphaNumericString(prevChar)) {
char = char.toUpperCase();
}
if (i == 0) {
if (uppercaseFirstCharacter) {
char = char.toUpperCase();
} else {
char = char.toLowerCase();
}
upperCase = true;
} else {
result += firstCharacter ? char.toLowerCase() : (upperCase ? char.toUpperCase() : char);
upperCase = false;
firstCharacter = false;
}
result.write(char);
}
final out = result.toString();
if (_dartKeywords.contains(out) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(out)) {
return '\$$out';
if (_dartKeywords.contains(result) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(result)) {
return '\$$result';
}
return out;
return result;
}
final _dartKeywords = [

Loading…
Cancel
Save