Permalink
Browse files

HTML Writer tracks all element IDs written, so can tell you if an ID …

…is available for use at any time.
  • Loading branch information...
1 parent 99c57a9 commit fba7c0456a4a756e2111bbbc27265df43b0a6930 Mike committed Sep 3, 2010
Showing with 17 additions and 6 deletions.
  1. +4 −1 KSHTMLWriter.h
  2. +13 −5 KSHTMLWriter.m
View
@@ -13,7 +13,8 @@
@interface KSHTMLWriter : KSXMLWriter
{
@private
- BOOL _isXHTML;
+ BOOL _isXHTML;
+ NSMutableSet *_IDs;
NSMutableArray *_classNames;
}
@@ -56,6 +57,8 @@
idName:(NSString *)idName
className:(NSString *)className;
+- (BOOL)isIDValid:(NSString *)anID; // NO if the ID has already been used
+
#pragma mark Line Break
// <br /> OR <br>
View
@@ -18,6 +18,7 @@ - (id)initWithOutputWriter:(id <KSWriter>)output;
[super initWithOutputWriter:output];
_isXHTML = YES;
+ _IDs = [[NSMutableSet alloc] init];
_classNames = [[NSMutableArray alloc] init];
return self;
@@ -35,6 +36,7 @@ - (id)initWithOutputWriter:(id <KSWriter>)output isXHTML:(BOOL)isXHTML;
- (void)dealloc
{
+ [_IDs release];
[_classNames release];
[super dealloc];
@@ -73,12 +75,12 @@ - (void)pushAttribute:(NSString *)attribute value:(NSString *)value;
{
if ([attribute isEqualToString:@"class"])
{
- [self pushClassName:value];
- }
- else
- {
- [super pushAttribute:attribute value:value];
+ return [self pushClassName:value];
}
+
+ // Keep track of IDs in use
+ if ([attribute isEqualToString:@"id"]) [_IDs addObject:value];
+ [super pushAttribute:attribute value:value];
}
- (NSDictionary *)elementAttributes;
@@ -127,6 +129,12 @@ - (void)startElement:(NSString *)tagName idName:(NSString *)idName className:(NS
[self startElement:tagName];
}
+- (BOOL)isIDValid:(NSString *)anID; // NO if the ID has already been used
+{
+ BOOL result = ![_IDs containsObject:anID];
+ return result;
+}
+
#pragma mark Line Break
- (void)writeLineBreak;

0 comments on commit fba7c04

Please sign in to comment.