Skip to content

Commit

Permalink
Add support for String.IsNullOrWhiteSpace
Browse files Browse the repository at this point in the history
Add method to CoreLib.
Add method to CoreScript.
Add tests in TestString.htm
  • Loading branch information
martinnormark committed Sep 7, 2012
1 parent b0cf099 commit df6b43b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Core/CoreLib/String.cs
Expand Up @@ -232,6 +232,10 @@ public sealed class String {
return false; return false;
} }


public static bool IsNullOrWhiteSpace(string s) {
return false;
}

public int LastIndexOf(Char ch) { public int LastIndexOf(Char ch) {
return 0; return 0;
} }
Expand Down
4 changes: 4 additions & 0 deletions src/Core/CoreScript/Extensions/String.js
Expand Up @@ -138,6 +138,10 @@ String.isNullOrEmpty = function#? DEBUG String$isNullOrEmpty##(s) {
return !s || !s.length; return !s || !s.length;
} }


String.isNullOrWhiteSpace = function#? DEBUG String$isNullOrWhiteSpace##(s) {
return String.isNullOrEmpty(s) || s.trim() === "";
}

String.prototype.lastIndexOfAny = function#? DEBUG String$lastIndexOfAny##(chars, startIndex, count) { String.prototype.lastIndexOfAny = function#? DEBUG String$lastIndexOfAny##(chars, startIndex, count) {
var length = this.length; var length = this.length;
if (!length) { if (!length) {
Expand Down
10 changes: 10 additions & 0 deletions tests/CoreLib/TestString.htm
Expand Up @@ -85,5 +85,15 @@ <h2 id="qunit-userAgent"></h2>
QUnit.equal('&lt;h1&gt;a &quot;aaa&quot; &amp; a &quot;bbb&quot;&lt;/h1&gt;'.htmlDecode(), '<h1>a "aaa" & a "bbb"</h1>'); QUnit.equal('&lt;h1&gt;a &quot;aaa&quot; &amp; a &quot;bbb&quot;&lt;/h1&gt;'.htmlDecode(), '<h1>a "aaa" & a "bbb"</h1>');
}); });


test('isNullOrWhiteSpace', function () {
QUnit.equal(String.isNullOrWhiteSpace(null), true, 'null should be true');
QUnit.equal(String.isNullOrWhiteSpace(undefined), true, 'undefined should be true');
QUnit.equal(String.isNullOrWhiteSpace(), true, 'no param, should be true');
QUnit.equal(String.isNullOrWhiteSpace(""), true, 'empty string, should be true');
QUnit.equal(String.isNullOrWhiteSpace(" "), true, 'white space, should be true');
QUnit.equal(String.isNullOrWhiteSpace(" "), true, 'triple white space, should be true');
QUnit.equal(String.isNullOrWhiteSpace("aaa"), false, 'aaa, should be false');
});

</script> </script>
</html> </html>

0 comments on commit df6b43b

Please sign in to comment.