Skip to content
Browse files

Merge pull request #230 from martinnormark/master

Add support for String.IsNullOrWhiteSpace
  • Loading branch information...
2 parents b0cf099 + 248cd0f commit 10c071f036e1ac7f6acd883103ae97174b89db44 @nikhilk committed Sep 7, 2012
Showing with 27 additions and 0 deletions.
  1. +4 −0 src/Core/CoreLib/String.cs
  2. +4 −0 src/Core/CoreScript/Extensions/String.js
  3. +19 −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
19 tests/CoreLib/TestString.htm
@@ -85,5 +85,24 @@ <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('isNullOrEmpty', function () {
+ QUnit.equal(String.isNullOrEmpty(null), true, 'null should be true');
+ QUnit.equal(String.isNullOrEmpty(undefined), true, 'undefined should be true');
+ QUnit.equal(String.isNullOrEmpty(), true, 'no param, should be true');
+ QUnit.equal(String.isNullOrEmpty(""), true, 'empty string, should be true');
+ QUnit.equal(String.isNullOrEmpty(" "), false, 'white space, should be false');
+ QUnit.equal(String.isNullOrEmpty("aaa"), false, 'aaa, should be false');
+});
+
+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 10c071f

Please sign in to comment.
Something went wrong with that request. Please try again.