Add NSString category for HTML related methods

Also remove macros scattered throughout the code and use category consistently
This commit is contained in:
iska committed 2015-03-02 22:36:03 +01:00
1 parent c37ad24751
commit cb9570c9e1
6 files changed
+96 -38

No files matched your search

+4 -18
View File
@@ -7,19 +7,7 @@
//
#import "HTMLCharacterToken.h"
NS_INLINE BOOL isHtmlWhitespace(char c)
{
return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r';
}
NS_INLINE size_t LeadingWhitespaceLength(NSString *string)
{
const char *str = string.UTF8String;
size_t idx = 0;
while (isHtmlWhitespace(*str)) { str++; idx++; }
return idx;
}
#import "NSString+HTMLKit.h"
@interface HTMLCharacterToken ()
{
@@ -48,14 +36,12 @@ NS_INLINE size_t LeadingWhitespaceLength(NSString *string)
- (BOOL)isWhitespaceToken
{
#warning Cache Character Set
NSCharacterSet *set = [[NSCharacterSet characterSetWithCharactersInString:@" \t\n\f"] invertedSet];
return [_characters rangeOfCharacterFromSet:set].location == NSNotFound;
return [_characters isHTMLWhitespaceString];
}
- (HTMLCharacterToken *)tokenByRetainingLeadingWhitespace
{
size_t index = LeadingWhitespaceLength(_characters);
NSUInteger index = _characters.leadingWhitespaceLength;
if (index > 0) {
NSString *leading = [_characters substringToIndex:index];
return [[HTMLCharacterToken alloc] initWithString:leading];
@@ -65,7 +51,7 @@ NS_INLINE size_t LeadingWhitespaceLength(NSString *string)
- (HTMLCharacterToken *)tokenByTrimmingLeadingWhitespace
{
size_t index = LeadingWhitespaceLength(_characters);
NSUInteger index = _characters.leadingWhitespaceLength;
if (index < _characters.length) {
NSString *remaining = [_characters substringFromIndex:index];
return [[HTMLCharacterToken alloc] initWithString:remaining];