Skip to content

Commit

Permalink
trim right when truncating
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Feb 3, 2025
1 parent ab177ee commit 187a84e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/string_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ String? stringTruncate(String? text, int len, {bool? ellipsis}) {
if (text != null) {
var existingLen = text.length;
if (existingLen > len) {
return '${text.substring(0, len)}${(ellipsis ?? false) ? '…' : ''}';
return '${text.substring(0, len).trimRight()}${(ellipsis ?? false) ? '…' : ''}';
}
}
return text;
Expand Down
1 change: 1 addition & 0 deletions test/string_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void main() {
expect('123'.truncate(2), '12');
expect('123'.truncate(2, ellipsis: true), '12…');
expect('123'.truncate(3, ellipsis: true), '123');
expect('12\r\n'.truncate(3, ellipsis: true), '12…');
expect('123'.truncate(4), '123');
});
test('stringsCompareWithLastInt', () {
Expand Down

0 comments on commit 187a84e

Please sign in to comment.