Permalink
Browse files

Added NSStringAddtions based on Three20

  • Loading branch information...
1 parent 8d5927e commit 727a164503e72e9576b0c8ada536168229efab79 @jk committed Oct 29, 2009
Showing with 55 additions and 0 deletions.
  1. +25 −0 NSStringAdditions.h
  2. +30 −0 NSStringAdditions.m
View
25 NSStringAdditions.h
@@ -0,0 +1,25 @@
+//
+// NSStringAdditions.h
+// JobStairs
+//
+// Created by Jens Kohl on 29.10.09.
+// Copyright 2009 Philipps-Universität Marburg. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSString (JKAdditions)
+
+/**
+ * @brief If there are any whitespaces in the string, this method returns YES
+ * @see Three20
+ */
+- (BOOL)isWhitespace;
+/**
+ * @brief Returns YES if the string is empty or if it only consists of whitespaces
+ * @see Three20
+ */
+- (BOOL)isEmptyOrWhitespace;
+
+@end
View
30 NSStringAdditions.m
@@ -0,0 +1,30 @@
+//
+// NSStringAdditions.m
+// JobStairs
+//
+// Created by Jens Kohl on 29.10.09.
+// Copyright 2009 Philipps-Universität Marburg. All rights reserved.
+//
+
+#import "NSStringAdditions.h"
+
+
+@implementation NSString (JKAdditions)
+
+- (BOOL)isWhitespace {
+ NSCharacterSet* whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
+ for (NSInteger i = 0; i < self.length; ++i) {
+ unichar c = [self characterAtIndex:i];
+ if (![whitespace characterIsMember:c]) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (BOOL)isEmptyOrWhitespace {
+ return !self.length ||
+ ![self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length;
+}
+
+@end

0 comments on commit 727a164

Please sign in to comment.