software list - support for the notes field.

This commit is contained in:
Kelvin Sherlock 2021-10-06 21:05:58 -04:00
parent 7178118ea9
commit c7fa95c918
2 changed files with 54 additions and 3 deletions

View File

@ -17,6 +17,7 @@
@property NSString *name; @property NSString *name;
@property NSString *title; @property NSString *title;
@property NSArray *items; @property NSArray *items;
@property NSString *notes;
-(SoftwareList *)filter: (NSString *)filter; -(SoftwareList *)filter: (NSString *)filter;
@ -27,6 +28,7 @@
@property NSString *title; @property NSString *title;
@property NSString *compatibility; @property NSString *compatibility;
@property NSString *list; @property NSString *list;
@property NSString *notes;
-(NSString *)fullName; -(NSString *)fullName;

View File

@ -172,9 +172,14 @@
@interface SoftwareListDelegate : NSObject<NSXMLParserDelegate> { @interface SoftwareListDelegate : NSObject<NSXMLParserDelegate> {
unsigned _state; unsigned _state;
NSString *_name; NSString *_name;
NSString *_description; NSString *_description;
NSString *_compatibility; NSString *_compatibility;
NSString *_notes;
NSString *_scratch;
NSMutableArray *_array; NSMutableArray *_array;
SoftwareList *_list; SoftwareList *_list;
} }
@ -201,8 +206,10 @@
The parts we care about: The parts we care about:
<softwarelist name="" description=""> <softwarelist name="" description="">
<notes>...</notes>
<software name=""> <software name="">
<description>...</description> <description>...</description>
<notes>...</notes>
</software> </software>
... ...
</softwarelist> </softwarelist>
@ -239,6 +246,13 @@
_compatibility = [attributeDict objectForKey: @"value"]; _compatibility = [attributeDict objectForKey: @"value"];
} }
} }
if ([@"notes" isEqualToString: elementName]) {
/* notes is a child of software list and software. */
if (_state == 0b0001 || _state == 0b0011) {
_state |= 0b1000;
}
return;
}
} }
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
@ -268,30 +282,65 @@
[s setTitle: _description]; [s setTitle: _description];
[s setName: _name]; [s setName: _name];
[s setCompatibility: _compatibility]; [s setCompatibility: _compatibility];
[s setNotes: _notes];
[s setList: [_list name]]; [s setList: [_list name]];
[_array addObject: s]; [_array addObject: s];
} }
_name = nil; _name = nil;
_description = nil; _description = nil;
_compatibility = nil; _compatibility = nil;
_notes = nil;
} }
return; return;
} }
if ([@"description" isEqualToString: elementName]) { if ([@"description" isEqualToString: elementName]) {
if (_state == 0b0111) { if (_state == 0b0111) {
_state &= ~0b0100; _state &= ~0b0100;
_description = _scratch;
_scratch = nil;
} }
return; return;
} }
if ([@"notes" isEqualToString: elementName]) {
if (_state == 0b1001) {
_state &= ~0b1000;
[_list setNotes: _scratch];
_scratch = nil;
}
if (_state == 0b1011) {
_state &= ~0b1000;
_notes = _scratch;
_scratch = nil;
}
return;
}
} }
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (_state == 0b0111) { if (_state == 0b0111 || _state == 0b1011 || _state == 0b1001) {
if (_description) _description = [_description stringByAppendingString: string]; if (_scratch) _scratch = [_scratch stringByAppendingString: string];
else _description = string; else _scratch = string;
} }
} }
- (void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespaceString {
// ?
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock {
if (_state & 0b1000) {
// notes
NSString *string = [[NSString new] initWithData: CDATABlock encoding: NSUTF8StringEncoding];
if (_scratch) _notes = [_scratch stringByAppendingString: string];
else _scratch = string;
}
}
@end @end