From 7cbfdb9c7876e06349160a45526fcd6f616d0e43 Mon Sep 17 00:00:00 2001 From: iska Date: Tue, 26 Mar 2019 23:23:08 +0100 Subject: [PATCH 1/5] Introduce prefix for category methods to prevent collisions See: https://github.com/iabudiab/HTMLKit/issues/35 --- HTMLKit.xcodeproj/project.pbxproj | 30 ++++++++++++++ Sources/CSSAttributeSelector.m | 2 +- Sources/CSSNthExpressionParser.m | 4 +- Sources/CSSSelectorParser.m | 2 +- Sources/CSSStructuralPseudoSelectors.m | 2 +- Sources/CSSTypeSelector.m | 2 +- Sources/HTMLCharacterToken.m | 8 ++-- Sources/HTMLDocumentType.m | 2 +- Sources/HTMLElement.m | 2 +- Sources/HTMLInputStreamReader.m | 2 +- Sources/HTMLParser.m | 8 ++-- Sources/HTMLQuircksMode.m | 21 ++++++++++ Sources/HTMLText.m | 2 +- Sources/NSCharacterSet+HTMLKit.m | 6 +-- Sources/NSString+HTMLKit.m | 31 ++------------- Sources/NSString+Private.m | 38 ++++++++++++++++++ Sources/include/HTMLElementTypes.h | 2 +- Sources/include/HTMLQuirksMode.h | 12 +----- Sources/include/NSCharacterSet+HTMLKit.h | 7 ++-- Sources/include/NSString+HTMLKit.h | 25 +----------- Sources/include/NSString+Private.h | 41 ++++++++++++++++++++ Sources/include/module.modulemap | 1 + Tests/HTMLKitTests/HTMLStringCategoryTests.m | 39 ++++++++++--------- 23 files changed, 183 insertions(+), 106 deletions(-) create mode 100644 Sources/HTMLQuircksMode.m create mode 100644 Sources/NSString+Private.m create mode 100644 Sources/include/NSString+Private.h diff --git a/HTMLKit.xcodeproj/project.pbxproj b/HTMLKit.xcodeproj/project.pbxproj index 02250de..c6c146c 100644 --- a/HTMLKit.xcodeproj/project.pbxproj +++ b/HTMLKit.xcodeproj/project.pbxproj @@ -58,6 +58,18 @@ 625A14B019C7829400AD0C32 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 625A14AF19C7829400AD0C32 /* Cocoa.framework */; }; 625A14C519C7829400AD0C32 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 625A14C419C7829400AD0C32 /* XCTest.framework */; }; 625A14C919C7829400AD0C32 /* HTMLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 625A14AC19C7829400AD0C32 /* HTMLKit.framework */; }; + 625A67C9224AC62C00C6D57D /* NSString+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625A67C7224AC62C00C6D57D /* NSString+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 625A67CA224AC62C00C6D57D /* NSString+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625A67C7224AC62C00C6D57D /* NSString+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 625A67CB224AC62C00C6D57D /* NSString+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625A67C7224AC62C00C6D57D /* NSString+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 625A67CC224AC62C00C6D57D /* NSString+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625A67C7224AC62C00C6D57D /* NSString+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 625A67CD224AC62C00C6D57D /* NSString+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67C8224AC62C00C6D57D /* NSString+Private.m */; }; + 625A67CE224AC62C00C6D57D /* NSString+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67C8224AC62C00C6D57D /* NSString+Private.m */; }; + 625A67CF224AC62C00C6D57D /* NSString+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67C8224AC62C00C6D57D /* NSString+Private.m */; }; + 625A67D0224AC62C00C6D57D /* NSString+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67C8224AC62C00C6D57D /* NSString+Private.m */; }; + 625A67D2224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */; }; + 625A67D3224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */; }; + 625A67D4224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */; }; + 625A67D5224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */; }; 625D0F031C2717DE00D7BEB0 /* HTMLNode+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625D0F011C2717DE00D7BEB0 /* HTMLNode+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 625D0F041C2717DE00D7BEB0 /* HTMLNode+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625D0F011C2717DE00D7BEB0 /* HTMLNode+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 625EE4571CBAA41D00F2CC8E /* HTMLKitTestObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */; }; @@ -692,6 +704,9 @@ 625A14DF19C7834100AD0C32 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 625A150619C78ABA00AD0C32 /* HTMLInputStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLInputStreamReader.h; path = include/HTMLInputStreamReader.h; sourceTree = ""; }; 625A150719C78ABA00AD0C32 /* HTMLInputStreamReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLInputStreamReader.m; sourceTree = ""; }; + 625A67C7224AC62C00C6D57D /* NSString+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSString+Private.h"; path = "include/NSString+Private.h"; sourceTree = ""; }; + 625A67C8224AC62C00C6D57D /* NSString+Private.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Private.m"; sourceTree = ""; }; + 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTMLQuircksMode.m; sourceTree = ""; }; 625D0F011C2717DE00D7BEB0 /* HTMLNode+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "HTMLNode+Private.h"; path = "include/HTMLNode+Private.h"; sourceTree = ""; }; 625EE4551CBAA41D00F2CC8E /* HTMLKitTestObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLKitTestObserver.h; path = HTMLKitTests/HTMLKitTestObserver.h; sourceTree = ""; }; 625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HTMLKitTestObserver.m; path = HTMLKitTests/HTMLKitTestObserver.m; sourceTree = ""; }; @@ -872,6 +887,7 @@ 6238C9841AB8D6330006512E /* HTMLKitDOMExceptions.m */, 628B7CE61A080E1000602C87 /* HTMLNamespaces.h */, 623719431AA12EE8002E03C8 /* HTMLQuirksMode.h */, + 625A67D1224ADC7700C6D57D /* HTMLQuircksMode.m */, 625D0F071C2717E400D7BEB0 /* Private */, ); name = DOM; @@ -1055,6 +1071,8 @@ 628E16ED1ADAE73700B15A06 /* Categories */ = { isa = PBXGroup; children = ( + 625A67C7224AC62C00C6D57D /* NSString+Private.h */, + 625A67C8224AC62C00C6D57D /* NSString+Private.m */, 6235CE991AA509430026937B /* NSString+HTMLKit.h */, 6235CE9A1AA509430026937B /* NSString+HTMLKit.m */, 624B28C21B04190D0048D328 /* NSCharacterSet+HTMLKit.h */, @@ -1189,6 +1207,7 @@ 62ECBEEA1C0B69FD00AF847B /* HTMLCommentToken.h in Headers */, 62ECBEEB1C0B69FD00AF847B /* HTMLDOCTYPEToken.h in Headers */, 626BE1E21DF3819500C49514 /* HTMLDOMUtils.h in Headers */, + 625A67C9224AC62C00C6D57D /* NSString+Private.h in Headers */, 62ECBEEC1C0B69FD00AF847B /* HTMLParseErrorToken.h in Headers */, 62ECBEED1C0B69FD00AF847B /* HTMLTagToken.h in Headers */, 62ECBEEE1C0B69FD00AF847B /* HTMLEOFToken.h in Headers */, @@ -1262,6 +1281,7 @@ 62857C841D398917008DC254 /* HTMLParser.h in Headers */, 62857CDB1D3989CE008DC254 /* CSSAttributeSelector.h in Headers */, 62857C791D398907008DC254 /* HTMLEOFToken.h in Headers */, + 625A67CC224AC62C00C6D57D /* NSString+Private.h in Headers */, 626BE1E51DF3819500C49514 /* HTMLDOMUtils.h in Headers */, 62857CC41D3989A9008DC254 /* CSSSelectors.h in Headers */, 62857C731D398907008DC254 /* HTMLToken.h in Headers */, @@ -1335,6 +1355,7 @@ 62857D4E1D39A40A008DC254 /* HTMLTokenizerCharacters.h in Headers */, 62857D4D1D39A40A008DC254 /* HTMLTokenizerStates.h in Headers */, 62857D501D39A411008DC254 /* HTMLTokens.h in Headers */, + 625A67CB224AC62C00C6D57D /* NSString+Private.h in Headers */, 626BE1E41DF3819500C49514 /* HTMLDOMUtils.h in Headers */, 62857D7B1D39A452008DC254 /* HTMLNamespaces.h in Headers */, 62857D581D39A416008DC254 /* HTMLParser.h in Headers */, @@ -1408,6 +1429,7 @@ 62ECBFAF1C0B6D3B00AF847B /* HTMLNodeIterator.h in Headers */, 62ECBFB01C0B6D3C00AF847B /* HTMLTreeWalker.h in Headers */, 62ECBFB21C0B6D3C00AF847B /* HTMLNodeFilter.h in Headers */, + 625A67CA224AC62C00C6D57D /* NSString+Private.h in Headers */, 62567F511C0CB5750025D458 /* HTMLDOMTokenList.h in Headers */, 62ECBFB31C0B6D3C00AF847B /* HTMLKitDOMExceptions.h in Headers */, 62ECBFB41C0B6D3D00AF847B /* HTMLNamespaces.h in Headers */, @@ -1730,6 +1752,7 @@ 62ECBF2A1C0B6B7900AF847B /* HTMLNode.m in Sources */, 62ECBF2B1C0B6B7900AF847B /* HTMLDocument.m in Sources */, 62ECBF2C1C0B6B7900AF847B /* HTMLDocumentType.m in Sources */, + 625A67D2224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */, 62ECBF2D1C0B6B7900AF847B /* HTMLDocumentFragment.m in Sources */, 62ECBF2E1C0B6B7900AF847B /* HTMLElement.m in Sources */, 62ECBF2F1C0B6B7900AF847B /* HTMLComment.m in Sources */, @@ -1748,6 +1771,7 @@ 62ECBF3C1C0B6B7900AF847B /* CSSInputStream.m in Sources */, 62ECBF3D1C0B6B7900AF847B /* CSSSelectorParser.m in Sources */, 62ECBF3E1C0B6B7900AF847B /* CSSNthExpressionParser.m in Sources */, + 625A67CD224AC62C00C6D57D /* NSString+Private.m in Sources */, 62ECBF3F1C0B6B7900AF847B /* CSSSelector.m in Sources */, 62ECBF401C0B6B7900AF847B /* CSSSelectorBlock.m in Sources */, 62ECBF411C0B6B7900AF847B /* CSSTypeSelector.m in Sources */, @@ -1820,6 +1844,7 @@ 62857C811D398912008DC254 /* HTMLParseErrorToken.m in Sources */, 62857CD21D3989B8008DC254 /* CSSCombinatorSelector.m in Sources */, 62857CB91D398992008DC254 /* HTMLNodeIterator.m in Sources */, + 625A67D5224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */, 62857CCF1D3989B8008DC254 /* CSSPseudoClassSelector.m in Sources */, 62857C7A1D398912008DC254 /* HTMLInputStreamReader.m in Sources */, 62857CC11D39899C008DC254 /* NSCharacterSet+HTMLKit.m in Sources */, @@ -1838,6 +1863,7 @@ 62857CBC1D398992008DC254 /* HTMLNodeFilter.m in Sources */, 62857CC01D39899C008DC254 /* NSString+HTMLKit.m in Sources */, 62857CCA1D3989B8008DC254 /* CSSInputStream.m in Sources */, + 625A67D0224AC62C00C6D57D /* NSString+Private.m in Sources */, 62857CCE1D3989B8008DC254 /* CSSAttributeSelector.m in Sources */, 62857CC31D3989A3008DC254 /* HTMLOrderedDictionary.m in Sources */, 62857CC91D3989B8008DC254 /* CSSNthExpressionParser.m in Sources */, @@ -1875,6 +1901,7 @@ 62857D0F1D39A32A008DC254 /* HTMLNode.m in Sources */, 62857D2C1D39A334008DC254 /* CSSCombinatorSelector.m in Sources */, 62857D181D39A32A008DC254 /* HTMLNodeIterator.m in Sources */, + 625A67D4224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */, 62857D291D39A334008DC254 /* CSSPseudoClassSelector.m in Sources */, 62857D011D39A324008DC254 /* HTMLInputStreamReader.m in Sources */, 62857D1E1D39A334008DC254 /* NSCharacterSet+HTMLKit.m in Sources */, @@ -1893,6 +1920,7 @@ 62857D1B1D39A32A008DC254 /* HTMLNodeFilter.m in Sources */, 62857D1D1D39A334008DC254 /* NSString+HTMLKit.m in Sources */, 62857D241D39A334008DC254 /* CSSInputStream.m in Sources */, + 625A67CF224AC62C00C6D57D /* NSString+Private.m in Sources */, 62857D281D39A334008DC254 /* CSSAttributeSelector.m in Sources */, 62857D1F1D39A334008DC254 /* HTMLOrderedDictionary.m in Sources */, 62857D231D39A334008DC254 /* CSSNthExpressionParser.m in Sources */, @@ -1965,6 +1993,7 @@ 62ECBF721C0B6D2A00AF847B /* HTMLNode.m in Sources */, 62ECBF731C0B6D2A00AF847B /* HTMLDocument.m in Sources */, 62ECBF741C0B6D2A00AF847B /* HTMLDocumentType.m in Sources */, + 625A67D3224ADC7700C6D57D /* HTMLQuircksMode.m in Sources */, 62ECBF751C0B6D2A00AF847B /* HTMLDocumentFragment.m in Sources */, 62ECBF761C0B6D2A00AF847B /* HTMLElement.m in Sources */, 62ECBF771C0B6D2A00AF847B /* HTMLComment.m in Sources */, @@ -1983,6 +2012,7 @@ 62ECBF841C0B6D2A00AF847B /* CSSInputStream.m in Sources */, 62ECBF851C0B6D2A00AF847B /* CSSSelectorParser.m in Sources */, 62ECBF861C0B6D2A00AF847B /* CSSNthExpressionParser.m in Sources */, + 625A67CE224AC62C00C6D57D /* NSString+Private.m in Sources */, 62ECBF871C0B6D2A00AF847B /* CSSSelector.m in Sources */, 62ECBF881C0B6D2A00AF847B /* CSSSelectorBlock.m in Sources */, 62ECBF891C0B6D2A00AF847B /* CSSTypeSelector.m in Sources */, diff --git a/Sources/CSSAttributeSelector.m b/Sources/CSSAttributeSelector.m index 355d549..3cfe01d 100644 --- a/Sources/CSSAttributeSelector.m +++ b/Sources/CSSAttributeSelector.m @@ -61,7 +61,7 @@ - (BOOL)acceptElement:(HTMLElement *)element } case CSSAttributeSelectorIncludes: { - NSArray *components = [element[_name] componentsSeparatedByCharactersInSet:[NSCharacterSet HTMLWhitespaceCharacterSet]]; + NSArray *components = [element[_name] componentsSeparatedByCharactersInSet:[NSCharacterSet htmlkit_HTMLWhitespaceCharacterSet]]; return [components containsObject:_value]; } case CSSAttributeSelectorBegins: diff --git a/Sources/CSSNthExpressionParser.m b/Sources/CSSNthExpressionParser.m index 392acb4..7fa733a 100644 --- a/Sources/CSSNthExpressionParser.m +++ b/Sources/CSSNthExpressionParser.m @@ -8,7 +8,7 @@ #import "CSSNthExpressionParser.h" #import "CSSCodePoints.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #import "NSCharacterSet+HTMLKit.h" @implementation CSSNthExpressionParser @@ -26,7 +26,7 @@ + (CSSNthExpression)parseExpression:(NSString *)expression return CSSNthExpressionEven; } - NSCharacterSet *set = [[NSCharacterSet CSSNthExpressionCharacterSet] invertedSet]; + NSCharacterSet *set = [[NSCharacterSet htmlkit_CSSNthExpressionCharacterSet] invertedSet]; if ([string rangeOfCharacterFromSet:set].location != NSNotFound) { return CSSNthExpressionMake(0, 0); } diff --git a/Sources/CSSSelectorParser.m b/Sources/CSSSelectorParser.m index b3f0f63..13fdad8 100644 --- a/Sources/CSSSelectorParser.m +++ b/Sources/CSSSelectorParser.m @@ -10,7 +10,7 @@ #import "CSSInputStream.h" #import "CSSCodePoints.h" #import "CSSSelectors.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #import "NSCharacterSet+HTMLKit.h" #import "CSSNthExpressionParser.h" #import "CSSCompoundSelector.h" diff --git a/Sources/CSSStructuralPseudoSelectors.m b/Sources/CSSStructuralPseudoSelectors.m index a721217..44833ce 100644 --- a/Sources/CSSStructuralPseudoSelectors.m +++ b/Sources/CSSStructuralPseudoSelectors.m @@ -9,7 +9,7 @@ #import "CSSStructuralPseudoSelectors.h" #import "CSSSelectors.h" #import "HTMLElement.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #pragma mark - Elements diff --git a/Sources/CSSTypeSelector.m b/Sources/CSSTypeSelector.m index 053ec74..a22ffb3 100644 --- a/Sources/CSSTypeSelector.m +++ b/Sources/CSSTypeSelector.m @@ -8,7 +8,7 @@ #import "CSSTypeSelector.h" #import "HTMLElement.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" @interface CSSTypeSelector () { diff --git a/Sources/HTMLCharacterToken.m b/Sources/HTMLCharacterToken.m index f866509..58238eb 100644 --- a/Sources/HTMLCharacterToken.m +++ b/Sources/HTMLCharacterToken.m @@ -36,7 +36,7 @@ - (void)appendString:(NSString *)string - (BOOL)isWhitespaceToken { - return [_characters isHTMLWhitespaceString]; + return [_characters htmlkit_isHTMLWhitespaceString]; } - (BOOL)isEmpty @@ -46,7 +46,7 @@ - (BOOL)isEmpty - (void)retainLeadingWhitespace { - NSUInteger index = _characters.leadingHTMLWhitespaceLength; + NSUInteger index = _characters.htmlkit_leadingHTMLWhitespaceLength; if (index > 0) { [_characters setString:[_characters substringToIndex:index]]; } @@ -54,7 +54,7 @@ - (void)retainLeadingWhitespace - (void)trimLeadingWhitespace { - NSUInteger index = _characters.leadingHTMLWhitespaceLength; + NSUInteger index = _characters.htmlkit_leadingHTMLWhitespaceLength; if (index > 0) { [_characters setString:[_characters substringFromIndex:index]]; } @@ -67,7 +67,7 @@ - (void)trimFormIndex:(NSUInteger)index - (HTMLCharacterToken *)tokenBySplitingLeadingWhiteSpace { - NSUInteger index = _characters.leadingHTMLWhitespaceLength; + NSUInteger index = _characters.htmlkit_leadingHTMLWhitespaceLength; if (index > 0) { NSString *leading = [_characters substringToIndex:index]; [_characters setString:[_characters substringFromIndex:index]]; diff --git a/Sources/HTMLDocumentType.m b/Sources/HTMLDocumentType.m index 0bff20c..b24c9ee 100644 --- a/Sources/HTMLDocumentType.m +++ b/Sources/HTMLDocumentType.m @@ -7,7 +7,7 @@ // #import "HTMLDocumentType.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #import "HTMLNode+Private.h" NS_INLINE BOOL nilOrEqual(id first, id second) { diff --git a/Sources/HTMLElement.m b/Sources/HTMLElement.m index 2686818..3fc25cf 100644 --- a/Sources/HTMLElement.m +++ b/Sources/HTMLElement.m @@ -12,7 +12,7 @@ #import "HTMLText.h" #import "HTMLDOMTokenList.h" #import "HTMLOrderedDictionary.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #import "HTMLNode+Private.h" @interface HTMLElement () diff --git a/Sources/HTMLInputStreamReader.m b/Sources/HTMLInputStreamReader.m index 777b81d..6a1c165 100644 --- a/Sources/HTMLInputStreamReader.m +++ b/Sources/HTMLInputStreamReader.m @@ -170,7 +170,7 @@ - (BOOL)consumeDecimalNumber:(NSDecimal *)result - (BOOL)consumeHexNumber:(unsigned long long *)result { - NSCharacterSet *set = [NSCharacterSet HTMLHexNumberCharacterSet]; + NSCharacterSet *set = [NSCharacterSet htmlkit_HTMLHexNumberCharacterSet]; NSString *string = nil; BOOL success = [_scanner scanCharactersFromSet:set intoString:&string]; diff --git a/Sources/HTMLParser.m b/Sources/HTMLParser.m index 5aa9cbc..a20b85c 100644 --- a/Sources/HTMLParser.m +++ b/Sources/HTMLParser.m @@ -1142,7 +1142,7 @@ - (void)HTMLInsertionModeInBody:(HTMLToken *)token if (charactes.length > 0) { [self reconstructActiveFormattingElements]; [self insertCharacters:charactes]; - if (!charactes.isHTMLWhitespaceString) { + if (!charactes.htmlkit_isHTMLWhitespaceString) { _framesetOkFlag = NO; } } @@ -2313,7 +2313,7 @@ - (void)HTMLInsertionModeInFrameset:(HTMLToken *)token [characters enumerateSubstringsInRange:NSMakeRange(0, characters.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { - if (substring.isHTMLWhitespaceString) { + if (substring.htmlkit_isHTMLWhitespaceString) { [self insertCharacters:substring]; } else { [self emitParseError:@"Unexpected Character (%@) in ", substring]; @@ -2381,7 +2381,7 @@ - (void)HTMLInsertionModeAfterFrameset:(HTMLToken *)token [characters enumerateSubstringsInRange:NSMakeRange(0, characters.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { - if (substring.isHTMLWhitespaceString) { + if (substring.htmlkit_isHTMLWhitespaceString) { [self insertCharacters:substring]; } else { [self emitParseError:@"Unexpected Character (%@) after ", substring]; @@ -2515,7 +2515,7 @@ - (void)processTokenByApplyingRulesForParsingTokensInForeignContent:(HTMLToken * usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { if ([substring isEqualToString:@"\uFFFD"]) { [self emitParseError:@"Unexpected Character (0x0000) in foreign content"]; - } else if (!substring.isHTMLWhitespaceString) { + } else if (!substring.htmlkit_isHTMLWhitespaceString) { _framesetOkFlag = NO; } [self insertCharacters:substring]; diff --git a/Sources/HTMLQuircksMode.m b/Sources/HTMLQuircksMode.m new file mode 100644 index 0000000..7e1016e --- /dev/null +++ b/Sources/HTMLQuircksMode.m @@ -0,0 +1,21 @@ +// +// HTMLQuircksMode.m +// HTMLKit +// +// Created by Iska on 26.03.19. +// Copyright © 2019 BrainCookie. All rights reserved. +// + +#import +#import "HTMLQuirksMode.h" +#import "NSString+Private.h" + +BOOL QuirksModePrefixMatch(NSString *publicIdentifier) +{ + for (int i = 0; i < sizeof(HTMLQuirksModePrefixes) / sizeof(HTMLQuirksModePrefixes[0]); i++) { + if ([publicIdentifier hasPrefixIgnoringCase:HTMLQuirksModePrefixes[i]]) { + return YES; + } + } + return NO; +} diff --git a/Sources/HTMLText.m b/Sources/HTMLText.m index bea9c9b..29687c1 100644 --- a/Sources/HTMLText.m +++ b/Sources/HTMLText.m @@ -8,7 +8,7 @@ #import "HTMLText.h" #import "HTMLElement.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" #import "HTMLCharacterData+Private.h" #import "HTMLKitDOMExceptions.h" #import "HTMLDocument+Private.h" diff --git a/Sources/NSCharacterSet+HTMLKit.m b/Sources/NSCharacterSet+HTMLKit.m index 8ad588c..6012180 100644 --- a/Sources/NSCharacterSet+HTMLKit.m +++ b/Sources/NSCharacterSet+HTMLKit.m @@ -10,7 +10,7 @@ @implementation NSCharacterSet (HTMLKit) -+ (instancetype)HTMLWhitespaceCharacterSet ++ (instancetype)htmlkit_HTMLWhitespaceCharacterSet { static NSCharacterSet *set = nil; static dispatch_once_t onceToken; @@ -20,7 +20,7 @@ + (instancetype)HTMLWhitespaceCharacterSet return set; } -+ (instancetype)HTMLHexNumberCharacterSet ++ (instancetype)htmlkit_HTMLHexNumberCharacterSet { static NSCharacterSet *set = nil; static dispatch_once_t onceToken; @@ -30,7 +30,7 @@ + (instancetype)HTMLHexNumberCharacterSet return set; } -+ (instancetype)CSSNthExpressionCharacterSet ++ (instancetype)htmlkit_CSSNthExpressionCharacterSet { static NSCharacterSet *set = nil; static dispatch_once_t onceToken; diff --git a/Sources/NSString+HTMLKit.m b/Sources/NSString+HTMLKit.m index 2d37ac4..33663ca 100644 --- a/Sources/NSString+HTMLKit.m +++ b/Sources/NSString+HTMLKit.m @@ -15,37 +15,12 @@ NS_INLINE BOOL isHtmlWhitespaceChar(unichar c) @implementation NSString (HTMLKit) -- (BOOL)isEqualToStringIgnoringCase:(NSString *)aString +- (BOOL)htmlkit_isHTMLWhitespaceString { - return [self caseInsensitiveCompare:aString] == NSOrderedSame; + return self.htmlkit_leadingHTMLWhitespaceLength == self.length; } -- (BOOL)isEqualToAny:(NSString *)first, ... NS_REQUIRES_NIL_TERMINATION -{ - va_list list; - va_start(list, first); - for (NSString *next = first; next != nil; next = va_arg(list, NSString *)) { - if ([self isEqualToString:next]) { - return YES; - } - } - va_end(list); - return NO; -} - -- (BOOL)hasPrefixIgnoringCase:(NSString *)aString -{ - NSRange reange = [self rangeOfString:aString - options:NSAnchoredSearch|NSCaseInsensitiveSearch]; - return reange.location != NSNotFound; -} - -- (BOOL)isHTMLWhitespaceString -{ - return self.leadingHTMLWhitespaceLength == self.length; -} - -- (NSUInteger)leadingHTMLWhitespaceLength +- (NSUInteger)htmlkit_leadingHTMLWhitespaceLength { size_t idx = 0; NSUInteger length = self.length; diff --git a/Sources/NSString+Private.m b/Sources/NSString+Private.m new file mode 100644 index 0000000..6ab7dc8 --- /dev/null +++ b/Sources/NSString+Private.m @@ -0,0 +1,38 @@ +// +// NSString+Private.m +// HTMLKit +// +// Created by Iska on 26.03.19. +// Copyright © 2019 BrainCookie. All rights reserved. +// + +#import "NSString+Private.h" + +@implementation NSString (Private) + +- (BOOL)isEqualToStringIgnoringCase:(NSString *)aString +{ + return [self caseInsensitiveCompare:aString] == NSOrderedSame; +} + +- (BOOL)isEqualToAny:(NSString *)first, ... NS_REQUIRES_NIL_TERMINATION +{ + va_list list; + va_start(list, first); + for (NSString *next = first; next != nil; next = va_arg(list, NSString *)) { + if ([self isEqualToString:next]) { + return YES; + } + } + va_end(list); + return NO; +} + +- (BOOL)hasPrefixIgnoringCase:(NSString *)aString +{ + NSRange reange = [self rangeOfString:aString + options:NSAnchoredSearch|NSCaseInsensitiveSearch]; + return reange.location != NSNotFound; +} + +@end diff --git a/Sources/include/HTMLElementTypes.h b/Sources/include/HTMLElementTypes.h index 62be23d..5e6630c 100644 --- a/Sources/include/HTMLElementTypes.h +++ b/Sources/include/HTMLElementTypes.h @@ -12,7 +12,7 @@ #import "HTMLElement.h" #import "HTMLNamespaces.h" -#import "NSString+HTMLKit.h" +#import "NSString+Private.h" NS_INLINE BOOL IsNodeMathMLTextIntegrationPoint(HTMLElement *node) { diff --git a/Sources/include/HTMLQuirksMode.h b/Sources/include/HTMLQuirksMode.h index 2c6008d..4b127d0 100644 --- a/Sources/include/HTMLQuirksMode.h +++ b/Sources/include/HTMLQuirksMode.h @@ -6,8 +6,6 @@ // Copyright (c) 2015 BrainCookie. All rights reserved. // -#import "NSString+HTMLKit.h" - /** HTML quirks modes https://html.spec.whatwg.org/multipage/infrastructure.html#quirks-mode @@ -82,12 +80,4 @@ static NSString * HTMLQuirksModePrefixes[] = { #undef QUIRKS_ENTRY }; -NS_INLINE BOOL QuirksModePrefixMatch(NSString *publicIdentifier) -{ - for (int i = 0; i < sizeof(HTMLQuirksModePrefixes) / sizeof(HTMLQuirksModePrefixes[0]); i++) { - if ([publicIdentifier hasPrefixIgnoringCase:HTMLQuirksModePrefixes[i]]) { - return YES; - } - } - return NO; -} +extern BOOL QuirksModePrefixMatch(NSString *publicIdentifier); diff --git a/Sources/include/NSCharacterSet+HTMLKit.h b/Sources/include/NSCharacterSet+HTMLKit.h index 0b2e0e2..05dea35 100644 --- a/Sources/include/NSCharacterSet+HTMLKit.h +++ b/Sources/include/NSCharacterSet+HTMLKit.h @@ -19,17 +19,18 @@ NS_ASSUME_NONNULL_BEGIN A character set for HTML whitespace characters: CHARACTER TABULATION U+0009, LINE FEED U+000A, FORM FEED U+000C, CARRIAGE RETURN U+000D, and SPACE U+0020. */ -+ (instancetype)HTMLWhitespaceCharacterSet; + ++ (instancetype)htmlkit_HTMLWhitespaceCharacterSet; /** A character set for HTML HEX-Number characters: The digits 0-9, latin small letters a-f, and latin capital letters A-F. */ -+ (instancetype)HTMLHexNumberCharacterSet; ++ (instancetype)htmlkit_HTMLHexNumberCharacterSet; /** A character set for CSS Nth-Expression: The digits 0-9, space, latin small n, latin capital N, plus sing and minus sign. */ -+ (instancetype)CSSNthExpressionCharacterSet; ++ (instancetype)htmlkit_CSSNthExpressionCharacterSet; @end diff --git a/Sources/include/NSString+HTMLKit.h b/Sources/include/NSString+HTMLKit.h index b73d0ad..b86ff47 100644 --- a/Sources/include/NSString+HTMLKit.h +++ b/Sources/include/NSString+HTMLKit.h @@ -15,38 +15,17 @@ NS_ASSUME_NONNULL_BEGIN */ @interface NSString (HTMLKit) -/** - Checks whether this string is equal to another ignoring the case. - - @return `YES` if the two string are equal ignroing the case, `NO` otherwise. - */ -- (BOOL)isEqualToStringIgnoringCase:(NSString *)aString; - -/** - Checks whether this string is equal to any of the given strings. - - @return `YES` if there is an equal string, `NO` otherwise. - */ -- (BOOL)isEqualToAny:(NSString *)first, ... NS_REQUIRES_NIL_TERMINATION; - -/** - Checks whether this string has a prefix ignoring the case. - - @return `YES` if this string has a given prefix ignroing the case, `NO` otherwise. - */ -- (BOOL)hasPrefixIgnoringCase:(NSString *)aString; - /** Checks whether this string is a HTML whitespace string. @return `YES` if this string is a HTML whitespace string, `NO` otherwise. */ -- (BOOL)isHTMLWhitespaceString; +- (BOOL)htmlkit_isHTMLWhitespaceString; /** @return The length of the leading HTML whitespace characters in this string. */ -- (NSUInteger)leadingHTMLWhitespaceLength; +- (NSUInteger)htmlkit_leadingHTMLWhitespaceLength; @end diff --git a/Sources/include/NSString+Private.h b/Sources/include/NSString+Private.h new file mode 100644 index 0000000..27a7ba3 --- /dev/null +++ b/Sources/include/NSString+Private.h @@ -0,0 +1,41 @@ +// +// NSString+Private.h +// HTMLKit +// +// Created by Iska on 26.03.19. +// Copyright © 2019 BrainCookie. All rights reserved. +// + +///------------------------------------------------------ +/// HTMLKit private header +///------------------------------------------------------ + +#import + +/** + NSStirng category for common helper methods. + */ +@interface NSString (Private) + +/** + Checks whether this string is equal to another ignoring the case. + + @return `YES` if the two string are equal ignroing the case, `NO` otherwise. + */ +- (BOOL)isEqualToStringIgnoringCase:(NSString *)aString; + +/** + Checks whether this string is equal to any of the given strings. + + @return `YES` if there is an equal string, `NO` otherwise. + */ +- (BOOL)isEqualToAny:(NSString *)first, ... NS_REQUIRES_NIL_TERMINATION; + +/** + Checks whether this string has a prefix ignoring the case. + + @return `YES` if this string has a given prefix ignroing the case, `NO` otherwise. + */ +- (BOOL)hasPrefixIgnoringCase:(NSString *)aString; + +@end diff --git a/Sources/include/module.modulemap b/Sources/include/module.modulemap index 0b140b6..9548684 100644 --- a/Sources/include/module.modulemap +++ b/Sources/include/module.modulemap @@ -34,5 +34,6 @@ module HTMLKit { header "HTMLParser+Private.h" header "HTMLNodeTraversal.h" header "HTMLDOMUtils.h" + header "NSString+Private.h" } } diff --git a/Tests/HTMLKitTests/HTMLStringCategoryTests.m b/Tests/HTMLKitTests/HTMLStringCategoryTests.m index b5d5571..3298f52 100644 --- a/Tests/HTMLKitTests/HTMLStringCategoryTests.m +++ b/Tests/HTMLKitTests/HTMLStringCategoryTests.m @@ -7,6 +7,7 @@ // #import +#import "NSString+Private.h" #import "NSString+HTMLKit.h" @interface HTMLKitStringCategoryTests : XCTestCase @@ -50,33 +51,33 @@ - (void)testHasPrefixIgnoringCase - (void)testIsHTMLWhitespaceString { - XCTAssertTrue([@" " isHTMLWhitespaceString]); - XCTAssertTrue([@"\t" isHTMLWhitespaceString]); - XCTAssertTrue([@"\n" isHTMLWhitespaceString]); - XCTAssertTrue([@"\f" isHTMLWhitespaceString]); - XCTAssertTrue([@"\r" isHTMLWhitespaceString]); - XCTAssertTrue([@" \t\n\f\r" isHTMLWhitespaceString]); - XCTAssertTrue([@"\t\n\f\r " isHTMLWhitespaceString]); - XCTAssertTrue([@" \t \n \f \r" isHTMLWhitespaceString]); - XCTAssertFalse([@"html kit" isHTMLWhitespaceString]); + XCTAssertTrue([@" " htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@"\t" htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@"\n" htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@"\f" htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@"\r" htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@" \t\n\f\r" htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@"\t\n\f\r " htmlkit_isHTMLWhitespaceString]); + XCTAssertTrue([@" \t \n \f \r" htmlkit_isHTMLWhitespaceString]); + XCTAssertFalse([@"html kit" htmlkit_isHTMLWhitespaceString]); } - (void)testLeadingWhitespaceLength { - XCTAssertEqual([@"" leadingHTMLWhitespaceLength], 0); - XCTAssertEqual([@"\0" leadingHTMLWhitespaceLength], 0); + XCTAssertEqual([@"" htmlkit_leadingHTMLWhitespaceLength], 0); + XCTAssertEqual([@"\0" htmlkit_leadingHTMLWhitespaceLength], 0); - XCTAssertEqual([@" " leadingHTMLWhitespaceLength], 1); - XCTAssertEqual([@"\0 " leadingHTMLWhitespaceLength], 0); + XCTAssertEqual([@" " htmlkit_leadingHTMLWhitespaceLength], 1); + XCTAssertEqual([@"\0 " htmlkit_leadingHTMLWhitespaceLength], 0); - XCTAssertEqual([@" " leadingHTMLWhitespaceLength], 2); - XCTAssertEqual([@" \0 " leadingHTMLWhitespaceLength], 1); + XCTAssertEqual([@" " htmlkit_leadingHTMLWhitespaceLength], 2); + XCTAssertEqual([@" \0 " htmlkit_leadingHTMLWhitespaceLength], 1); - XCTAssertEqual([@"\t\r\n\f" leadingHTMLWhitespaceLength], 4); - XCTAssertEqual([@"\t\r\n\0\f" leadingHTMLWhitespaceLength], 3); + XCTAssertEqual([@"\t\r\n\f" htmlkit_leadingHTMLWhitespaceLength], 4); + XCTAssertEqual([@"\t\r\n\0\f" htmlkit_leadingHTMLWhitespaceLength], 3); - XCTAssertEqual([@"\t\r\n\f " leadingHTMLWhitespaceLength], 5); - XCTAssertEqual([@"\t\r\n\f\0 " leadingHTMLWhitespaceLength], 4); + XCTAssertEqual([@"\t\r\n\f " htmlkit_leadingHTMLWhitespaceLength], 5); + XCTAssertEqual([@"\t\r\n\f\0 " htmlkit_leadingHTMLWhitespaceLength], 4); } @end From 85bd39963f9d826c5caef310024d8a8451a09e10 Mon Sep 17 00:00:00 2001 From: iska Date: Thu, 28 Mar 2019 22:19:19 +0100 Subject: [PATCH 2/5] Add Changelog entry for HTMLKit 3.0.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b4c9e..aba75ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## [3.0.0](https://github.com/iabudiab/HTMLKit/releases/tag/3.0.0) + +Released on 2019.03.28 + +### Breaking Change + +- Introduce prefix for `NSString` and `NSCharacterSet` categories to prevent collision with existing code (issue #35) + + ## [2.1.5](https://github.com/iabudiab/HTMLKit/releases/tag/2.1.5) Released on 2018.07.16 From 91d1f85c1bb0f178f2769be54da3f46708a2e0d0 Mon Sep 17 00:00:00 2001 From: iska Date: Thu, 28 Mar 2019 22:19:32 +0100 Subject: [PATCH 3/5] Update jazzy.yaml for 3.0.0 --- .jazzy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jazzy.yaml b/.jazzy.yaml index f808537..af3dd6b 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -1,5 +1,5 @@ module: HTMLKit -module_version: 2.1.5 +module_version: 3.0.0 author: Iskandar Abudiab author_url: https://twitter.com/iabudiab github_url: https://github.com/iabudiab/HTMLKit From 2a641ddacdd81a2e8f8ba3c95911c0cb09e20785 Mon Sep 17 00:00:00 2001 From: iska Date: Thu, 28 Mar 2019 22:19:44 +0100 Subject: [PATCH 4/5] Update podspec for 3.0.0 --- HTMLKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTMLKit.podspec b/HTMLKit.podspec index 4d07935..bff8eb7 100644 --- a/HTMLKit.podspec +++ b/HTMLKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "HTMLKit" - s.version = "2.1.5" + s.version = "3.0.0" s.summary = "HTMLKit, an Objective-C framework for your everyday HTML needs." s.license = "MIT" s.homepage = "https://github.com/iabudiab/HTMLKit" From 918c59e5ff89757734b4adc0f3d2b0e843a04c8a Mon Sep 17 00:00:00 2001 From: iska Date: Thu, 28 Mar 2019 22:19:58 +0100 Subject: [PATCH 5/5] Bump HTMLKit version to 3.0.0 --- Sources/HTMLKit-Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/HTMLKit-Info.plist b/Sources/HTMLKit-Info.plist index 82ff466..ea8ab7f 100644 --- a/Sources/HTMLKit-Info.plist +++ b/Sources/HTMLKit-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.1.5 + 3.0.0 CFBundleSignature ???? CFBundleVersion