Skip to content

Commit

Permalink
## 1.4.2
Browse files Browse the repository at this point in the history
* fix camelName error
  • Loading branch information
zmtzawqlp committed Nov 28, 2022
1 parent 80de531 commit 2c1b1ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Flutter/json_to_dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.2

* fix camelName error

## 1.4.1

Expand Down
21 changes: 15 additions & 6 deletions Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ String camelName(String name, {bool firstCharLowerCase = true}) {
if (name.isNullOrEmpty) {
return '';
}

for (final String symbol in symbolSet) {
name = name.replaceAll(symbol, '_');
}

final List<String> camels = name.split('_');
for (final String camel in camels) {
if (result.length == 0 && firstCharLowerCase) {
result.write(camel.toLowerCase());
if (camels.length == 1) {
if (firstCharLowerCase) {
return name.substring(0, 1).toLowerCase() + name.substring(1);
} else {
if (!name.isNullOrEmpty) {
result.write(camel.substring(0, 1).toUpperCase());
result.write(camel.substring(1).toLowerCase());
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
} else {
for (final String camel in camels) {
if (result.length == 0 && firstCharLowerCase) {
result.write(camel.toLowerCase());
} else {
if (!name.isNullOrEmpty) {
result.write(camel.substring(0, 1).toUpperCase());
result.write(camel.substring(1).toLowerCase());
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Flutter/json_to_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: The tool to convert json to dart code.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.4.1
version: 1.4.2

environment:
sdk: '>=2.17.0 <3.0.0'
Expand Down

0 comments on commit 2c1b1ed

Please sign in to comment.