-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/remove_first_or_null
- Loading branch information
Showing
9 changed files
with
288 additions
and
6 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,16 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
extension StringReplaceFirstCharExtension on String { | ||
/// Returns a copy of this string having its first character replaced with the result of the specified transform, | ||
/// or the original string if it's empty. | ||
/// transform - function that takes the first character and returns the result of the transform applied to the character. | ||
@pragma('vm:prefer-inline') | ||
@pragma('dart2js:tryInline') | ||
@experimental | ||
String replaceFirstChar(String Function(String) transform) { | ||
if (isNotEmpty) { | ||
return transform(this[0]).toString() + substring(1); | ||
} | ||
return this; | ||
} | ||
} |
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
File renamed without changes.
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,41 @@ | ||
import "package:kt_dart/kt.dart"; | ||
import "package:test/test.dart"; | ||
|
||
void main() { | ||
group("replaceFirstChar", () { | ||
group("uppercase", () { | ||
test("empty string", () { | ||
const String phrase = ""; | ||
final result = phrase.replaceFirstChar((it) => it.toUpperCase()); | ||
expect(result, ''); | ||
}); | ||
test("length 1", () { | ||
const String phrase = "a"; | ||
final result = phrase.replaceFirstChar((it) => it.toUpperCase()); | ||
expect(result, 'A'); | ||
}); | ||
test("length 2", () { | ||
const String phrase = "ab"; | ||
final result = phrase.replaceFirstChar((it) => it.toUpperCase()); | ||
expect(result, 'Ab'); | ||
}); | ||
}); | ||
group("lowercase", () { | ||
test("empty string", () { | ||
const String phrase = ""; | ||
final result = phrase.replaceFirstChar((it) => it.toLowerCase()); | ||
expect(result, ''); | ||
}); | ||
test("length 1", () { | ||
const String phrase = "A"; | ||
final result = phrase.replaceFirstChar((it) => it.toLowerCase()); | ||
expect(result, 'a'); | ||
}); | ||
test("length 2", () { | ||
const String phrase = "AB"; | ||
final result = phrase.replaceFirstChar((it) => it.toLowerCase()); | ||
expect(result, 'aB'); | ||
}); | ||
}); | ||
}); | ||
} |