Skip to content

Commit

Permalink
Merge pull request #42 from freemansoft/fixHandleNegativeNames
Browse files Browse the repository at this point in the history
restore names when negative sign is in between words
  • Loading branch information
freemansoft committed Jul 1, 2024
2 parents 022b3ff + 9e031f3 commit 8255c44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/extensions/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const negativeNumberPreface = 'Negative';
extension StringExtension on String {
String get alphanumeric {
// Match '-' only if it is followed by a digit and replace with negativeNumberPreface
final patternNegative = RegExp(r'-(?=\d)');
final patternNegative = RegExp(r'^(-)(?=\d)');
// Match all non alphanumeric characters (excluding negativeNumberPreface replacements) and replace them with a space
final patternNonAlphanumeric = RegExp(r'[^a-zA-Z0-9]');

Expand Down
13 changes: 13 additions & 0 deletions test/extensions/strings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,18 @@ void main() {
test('extension alphanumeric negative numbers', () {
final test = '-4';
expect(test.alphanumeric, 'Negative4');
final test2 = '-4-grey';
expect(test2.alphanumeric, 'Negative4Grey');
final test3 = '--4';
expect(test3.alphanumeric, '4');
final test4 = '-grey-4';
expect(test4.alphanumeric, 'Grey4');
});

test('extension alphanumeric with minus sign', () {
final test = 'White-4';
expect(test.alphanumeric, 'White4');
final test2 = 'White-4-dog';
expect(test2.alphanumeric, 'White4Dog');
});
}

0 comments on commit 8255c44

Please sign in to comment.