Browse files

Add support for String.IsNullOrWhiteSpace

Add method to CoreLib.
Add method to CoreScript.
Add tests in TestString.htm
  • Loading branch information...
1 parent b0cf099 commit df6b43b62f5443c6a755119a17215f346e2bdcc9 @martinnormark martinnormark committed Sep 7, 2012
Showing with 18 additions and 0 deletions.
  1. +4 −0 src/Core/CoreLib/String.cs
  2. +4 −0 src/Core/CoreScript/Extensions/String.js
  3. +10 −0 tests/CoreLib/TestString.htm
View
4 src/Core/CoreLib/String.cs
@@ -232,6 +232,10 @@ public sealed class String {
return false;
}
+ public static bool IsNullOrWhiteSpace(string s) {
+ return false;
+ }
+
public int LastIndexOf(Char ch) {
return 0;
}
View
4 src/Core/CoreScript/Extensions/String.js
@@ -138,6 +138,10 @@ String.isNullOrEmpty = function#? DEBUG String$isNullOrEmpty##(s) {
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) {
var length = this.length;
if (!length) {
View
10 tests/CoreLib/TestString.htm
@@ -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>');
});
+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>
</html>

0 comments on commit df6b43b

Please sign in to comment.