Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e165673
commit d60fc7b
Showing
2 changed files
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,29 +163,25 @@ - (NSString *)body | |
return [[self elementForName:@"body"] stringValue]; | ||
} | ||
|
||
- (NSString*)bodyWithLang:(NSString*)lang | ||
- (NSString *)bodyForLanguage:(NSString *)language | ||
{ | ||
if (lang == nil) | ||
if ([language length] == 0) | ||
{ | ||
return [self body]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ObjColumnist
Author
Collaborator
|
||
NSArray *bodies = [self elementsForName:@"body"]; | ||
if (bodies == nil) | ||
return nil; | ||
for (int i = 0; i < bodies.count; i++) | ||
} | ||
|
||
NSString *bodyForLanguage = nil; | ||
|
||
for (NSXMLElement *bodyElement in [self elementsForName:@"body"]) | ||
{ | ||
DDXMLElement *elem = [bodies objectAtIndex:i]; | ||
DDXMLNode *langAttr = [elem attributeForName:@"lang"]; | ||
if (lang == nil) | ||
{ | ||
if (langAttr == nil) | ||
return [elem stringValue]; | ||
} | ||
else | ||
if ([language isEqualToString:[[bodyElement attributeForName:@"xml:lang"] stringValue]]) | ||
{ | ||
if ([lang isEqualToString:[langAttr stringValue]]) | ||
return [elem stringValue]; | ||
bodyForLanguage = [bodyElement stringValue]; | ||
break; | ||
} | ||
} | ||
return nil; | ||
|
||
return bodyForLanguage; | ||
} | ||
|
||
- (NSString *)thread | ||
|
@@ -205,11 +201,15 @@ - (void)addBody:(NSString *)body | |
[self addChild:bodyElement]; | ||
} | ||
|
||
- (void)addBody:(NSString *)body withLang:(NSString *)lang | ||
- (void)addBody:(NSString *)body withLanguage:(NSString *)language | ||
{ | ||
NSXMLElement *bodyElement = [NSXMLElement elementWithName:@"body" stringValue:body]; | ||
if (lang) | ||
[bodyElement addAttributeWithName:@"xml:lang" stringValue:lang]; | ||
|
||
if ([language length]) | ||
{ | ||
[bodyElement addAttributeWithName:@"xml:lang" stringValue:language]; | ||
} | ||
|
||
[self addChild:bodyElement]; | ||
} | ||
|
||
|
This is wrong! Your changes return the first found, whereas nil language would mean the body with no xml:lang attribute