Jonny Borges
Committed by GitHub

Merge pull request #980 from eduardoflorence/improve-capitalize

Utils: capitalize cannot convert space to null
@@ -518,17 +518,16 @@ class GetUtils { @@ -518,17 +518,16 @@ class GetUtils {
518 /// Capitalize each word inside string 518 /// Capitalize each word inside string
519 /// Example: your name => Your Name, your name => Your name 519 /// Example: your name => Your Name, your name => Your name
520 static String capitalize(String value) { 520 static String capitalize(String value) {
521 - if (isNullOrBlank(value)) return null; 521 + if (isNull(value)) return null;
  522 + if (isBlank(value)) return value;
522 return value.split(' ').map(capitalizeFirst).join(' '); 523 return value.split(' ').map(capitalizeFirst).join(' ');
523 } 524 }
524 525
525 /// Uppercase first letter inside string and let the others lowercase 526 /// Uppercase first letter inside string and let the others lowercase
526 /// Example: your name => Your name 527 /// Example: your name => Your name
527 static String capitalizeFirst(String s) { 528 static String capitalizeFirst(String s) {
528 - if (isNullOrBlank(s)) {  
529 - return null;  
530 - }  
531 - 529 + if (isNull(s)) return null;
  530 + if (isBlank(s)) return s;
532 return s[0].toUpperCase() + s.substring(1).toLowerCase(); 531 return s[0].toUpperCase() + s.substring(1).toLowerCase();
533 } 532 }
534 533
@@ -679,14 +679,17 @@ void main() { @@ -679,14 +679,17 @@ void main() {
679 expect('foo bar'.capitalize, 'Foo Bar'); 679 expect('foo bar'.capitalize, 'Foo Bar');
680 expect('FoO bAr'.capitalize, 'Foo Bar'); 680 expect('FoO bAr'.capitalize, 'Foo Bar');
681 expect('FOO BAR'.capitalize, 'Foo Bar'); 681 expect('FOO BAR'.capitalize, 'Foo Bar');
682 - expect(''.capitalize, null); 682 + expect(null.capitalize, null);
  683 + expect(''.capitalize, '');
  684 + expect('foo bar '.capitalize, 'Foo Bar ');
683 }); 685 });
684 686
685 test('var.capitalizeFirst', () { 687 test('var.capitalizeFirst', () {
686 expect('foo bar'.capitalizeFirst, 'Foo bar'); 688 expect('foo bar'.capitalizeFirst, 'Foo bar');
687 expect('FoO bAr'.capitalizeFirst, 'Foo bar'); 689 expect('FoO bAr'.capitalizeFirst, 'Foo bar');
688 expect('FOO BAR'.capitalizeFirst, 'Foo bar'); 690 expect('FOO BAR'.capitalizeFirst, 'Foo bar');
689 - expect(''.capitalizeFirst, null); 691 + expect(null.capitalizeFirst, null);
  692 + expect(''.capitalizeFirst, '');
690 }); 693 });
691 694
692 test('var.removeAllWhitespace', () { 695 test('var.removeAllWhitespace', () {