twitter-text-objc — An Objective-C implementation of Twitter's text processing library
Twitter released a version of their twitter-text library for Objective-C today. It makes extracting entities from strings really easy.
Here’s the header:
+ (NSArray*)extractEntities:(NSString*)text;
+ (NSArray*)extractURLs:(NSString*)text;
+ (NSArray*)extractHashtags:(NSString*)text checkingURLOverlap:(BOOL)checkingURLOverlap;
+ (NSArray*)extractMentionedScreenNames:(NSString*)text;
+ (NSArray*)extractMentionsOrLists:(NSString*)text;
+ (TwitterTextEntity*)extractReplyScreenName:(NSString*)text;
+ (int)tweetLength:(NSString*)text;
Extracting the URLs from a string is super simple:
NSArray *URLs = [TwitterText extractURLs:@"4 new HTTP status codes http://tools.ietf.org/html/rfc6585"];
TwitterTextEntity *entity = [URLs objectAtIndex:0];
NSLog(@"Entity range: %@", NSStringFromNSRange(entity.range));
// Entity range: {24, 34}
The source is on GitHub. There’s a Ruby, JavaScript, and Java version of this library as well.
Discussion
Sign in or Join to comment or subscribe