Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added NSStringAddtions based on Three20

  • Loading branch information...
commit 727a164503e72e9576b0c8ada536168229efab79 1 parent 8d5927e
Jens Kohl authored October 29, 2009
25  NSStringAdditions.h
... ...
@@ -0,0 +1,25 @@
  1
+//
  2
+//  NSStringAdditions.h
  3
+//  JobStairs
  4
+//
  5
+//  Created by Jens Kohl on 29.10.09.
  6
+//  Copyright 2009 Philipps-Universität Marburg. All rights reserved.
  7
+//
  8
+
  9
+#import <Foundation/Foundation.h>
  10
+
  11
+
  12
+@interface NSString (JKAdditions)
  13
+
  14
+/**
  15
+ * @brief If there are any whitespaces in the string, this method returns YES
  16
+ * @see Three20
  17
+ */
  18
+- (BOOL)isWhitespace;
  19
+/**
  20
+ * @brief Returns YES if the string is empty or if it only consists of whitespaces
  21
+ * @see Three20
  22
+ */
  23
+- (BOOL)isEmptyOrWhitespace;
  24
+
  25
+@end
30  NSStringAdditions.m
... ...
@@ -0,0 +1,30 @@
  1
+//
  2
+//  NSStringAdditions.m
  3
+//  JobStairs
  4
+//
  5
+//  Created by Jens Kohl on 29.10.09.
  6
+//  Copyright 2009 Philipps-Universität Marburg. All rights reserved.
  7
+//
  8
+
  9
+#import "NSStringAdditions.h"
  10
+
  11
+
  12
+@implementation NSString (JKAdditions)
  13
+
  14
+- (BOOL)isWhitespace {
  15
+	NSCharacterSet* whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
  16
+	for (NSInteger i = 0; i < self.length; ++i) {
  17
+		unichar c = [self characterAtIndex:i];
  18
+		if (![whitespace characterIsMember:c]) {
  19
+			return NO;
  20
+		}
  21
+	}
  22
+	return YES;
  23
+}
  24
+
  25
+- (BOOL)isEmptyOrWhitespace {
  26
+	return !self.length || 
  27
+	![self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length;
  28
+}
  29
+
  30
+@end

0 notes on commit 727a164

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