Skip to content

Commit

Permalink
Allow values for attributes to be type id, not
Browse files Browse the repository at this point in the history
just NSString.  This allows us to use NSNumber
when appropriate.  Then, when actually writing,
we use -description to convert the object into
an NSString before escaping entities.
  • Loading branch information
Dan Wood committed Sep 29, 2010
1 parent 3e48d47 commit 30bbf6a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions KSHTMLWriter.h
Expand Up @@ -94,8 +94,8 @@
// <img src="..." alt="..." width="..." height="..." />
- (void)writeImageWithSrc:(NSString *)src
alt:(NSString *)alt
width:(NSString *)width
height:(NSString *)height;
width:(id)width
height:(id)height;


#pragma mark Link
Expand Down
6 changes: 3 additions & 3 deletions KSHTMLWriter.m
Expand Up @@ -90,7 +90,7 @@ - (NSString *)elementClassName;
return result;
}

- (void)pushAttribute:(NSString *)attribute value:(NSString *)value;
- (void)pushAttribute:(NSString *)attribute value:(id)value;
{
if ([attribute isEqualToString:@"class"])
{
Expand Down Expand Up @@ -176,8 +176,8 @@ - (void)startAnchorElementWithHref:(NSString *)href title:(NSString *)titleStrin

- (void)writeImageWithSrc:(NSString *)src
alt:(NSString *)alt
width:(NSString *)width
height:(NSString *)height;
width:(id)width
height:(id)height;
{
[self pushAttribute:@"src" value:src];
[self pushAttribute:@"alt" value:alt];
Expand Down
2 changes: 1 addition & 1 deletion KSXMLWriter.h
Expand Up @@ -96,7 +96,7 @@
* - More efficient than building up a temporary dictionary object
* - Can sneak extra attributes in when using a convenience method (e.g. for HTML)
*/
- (void)pushAttribute:(NSString *)attribute value:(NSString *)value;
- (void)pushAttribute:(NSString *)attribute value:(id)value;
- (NSDictionary *)elementAttributes;


Expand Down
10 changes: 6 additions & 4 deletions KSXMLWriter.m
Expand Up @@ -52,7 +52,7 @@ - (void)writeStringByEscapingXMLEntities:(NSString *)string escapeQuot:(BOOL)esc

// attribute="value"
- (void)writeAttribute:(NSString *)attribute
value:(NSString *)value;
value:(id)value;

// Starts tracking -writeString: calls to see if element is empty
- (void)didStartElement;
Expand Down Expand Up @@ -241,7 +241,7 @@ - (void)endElement;
}
}

- (void)pushAttribute:(NSString *)attribute value:(NSString *)value; // call before -startElement:
- (void)pushAttribute:(NSString *)attribute value:(id)value; // call before -startElement:
{
NSParameterAssert(value);
[_attributes addObject:attribute];
Expand Down Expand Up @@ -354,12 +354,14 @@ - (NSString *)topElement;
#pragma mark Element Primitives

- (void)writeAttribute:(NSString *)attribute
value:(NSString *)value;
value:(id)value;
{
NSString *valueString = [value description];

[self writeString:@" "];
[self writeString:attribute];
[self writeString:@"=\""];
[self writeStringByEscapingXMLEntities:value escapeQuot:YES]; // make sure to escape the quote mark
[self writeStringByEscapingXMLEntities:valueString escapeQuot:YES]; // make sure to escape the quote mark
[self writeString:@"\""];
}

Expand Down

0 comments on commit 30bbf6a

Please sign in to comment.