Permalink
Browse files

html stripping messages from server

  • Loading branch information...
1 parent 3711f6a commit 14a505159f8e3e835a325e67d1f24bf3132d7d9b @orta orta committed Apr 1, 2012
Showing with 28 additions and 1 deletion.
  1. +28 −1 Puttio/Utils/V1PutIOAPIClient.m
@@ -132,7 +132,7 @@ - (void)getMessages:(void(^)(id userInfoObject))onComplete {
if (messages) {
for (NSDictionary *messageDict in messages) {
Message *message = [[Message alloc] init];
- message.message = [messageDict objectForKey:@"title"];
+ message.message = [self flattenHTML:[messageDict objectForKey:@"title"] trimWhiteSpace:YES];
[returnedMessages addObject:message];
}
}
@@ -151,4 +151,31 @@ - (BOOL)ready {
return (self.apiKey && self.apiSecret);
}
+- (NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim {
+
+ NSScanner *theScanner;
+ NSString *text = nil;
+
+ theScanner = [NSScanner scannerWithString:html];
+
+ while ([theScanner isAtEnd] == NO) {
+
+ // find start of tag
+ [theScanner scanUpToString:@"<" intoString:NULL] ;
+ // find end of tag
+ [theScanner scanUpToString:@">" intoString:&text] ;
+
+ // replace the found tag with a space
+ //(you can filter multi-spaces out later if you wish)
+ html = [html stringByReplacingOccurrencesOfString:
+ [ NSString stringWithFormat:@"%@>", text]
+ withString:@" "];
+
+ } // while //
+
+ // trim off whitespace
+ return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
+
+}
+
@end

0 comments on commit 14a5051

Please sign in to comment.