-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from odroe/26-lowercase-keywords
26 lowercase keywords
- Loading branch information
Showing
10 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:orm/src/runtime/language_keyword.dart'; | ||
|
||
/// Fix a dart class name. | ||
/// | ||
/// Example: | ||
/// a -> A | ||
/// _a -> $A | ||
/// a_ -> A_ | ||
String dartClassnameFixer(String name) { | ||
final String fixed = languageKeywordEncode(name); | ||
|
||
return _charToUpperCase(fixed, 0); | ||
} | ||
|
||
String _charToUpperCase(String name, int index) { | ||
if (name.length == 1) return name.toUpperCase(); | ||
|
||
if (RegExp(r'[a-zA-Z]').hasMatch(name[index])) { | ||
return name[index].toUpperCase() + name.substring(index + 1); | ||
} else if ((index + 1) >= name.length) { | ||
return name; | ||
} | ||
|
||
return name[index] + _charToUpperCase(name, index + 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:test/expect.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
import '../../../../bin/src/generator/utils/dart_style.dart'; | ||
|
||
void main() { | ||
test('test single char', () { | ||
expect(dartClassnameFixer('a'), 'A'); | ||
}); | ||
|
||
test('test single char with underscore', () { | ||
expect(dartClassnameFixer('_a'), r'$A'); | ||
}); | ||
|
||
test('test single char with underscore', () { | ||
expect(dartClassnameFixer('a_'), r'A_'); | ||
}); | ||
|
||
test('test multiple char', () { | ||
expect(dartClassnameFixer('abc'), r'Abc'); | ||
}); | ||
|
||
test('test multiple char with underscore', () { | ||
expect(dartClassnameFixer('_abc'), r'$Abc'); | ||
}); | ||
|
||
test('test multiple char with underscore', () { | ||
expect(dartClassnameFixer('abc_'), r'Abc_'); | ||
}); | ||
|
||
test('test multiple char with underscore', () { | ||
expect(dartClassnameFixer('_abc_'), r'$Abc_'); | ||
}); | ||
} |
File renamed without changes.