From c7fa95c9183e88b01db602ea17bcea051b229a4f Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 6 Oct 2021 21:05:58 -0400 Subject: [PATCH] software list - support for the notes field. --- Ample/SoftwareList.h | 2 ++ Ample/SoftwareList.m | 55 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Ample/SoftwareList.h b/Ample/SoftwareList.h index b13e5e5..59d6cd1 100644 --- a/Ample/SoftwareList.h +++ b/Ample/SoftwareList.h @@ -17,6 +17,7 @@ @property NSString *name; @property NSString *title; @property NSArray *items; +@property NSString *notes; -(SoftwareList *)filter: (NSString *)filter; @@ -27,6 +28,7 @@ @property NSString *title; @property NSString *compatibility; @property NSString *list; +@property NSString *notes; -(NSString *)fullName; diff --git a/Ample/SoftwareList.m b/Ample/SoftwareList.m index c4be6a4..4b44128 100644 --- a/Ample/SoftwareList.m +++ b/Ample/SoftwareList.m @@ -172,9 +172,14 @@ @interface SoftwareListDelegate : NSObject { unsigned _state; + NSString *_name; NSString *_description; NSString *_compatibility; + NSString *_notes; + + NSString *_scratch; + NSMutableArray *_array; SoftwareList *_list; } @@ -201,8 +206,10 @@ The parts we care about: + ... ... + ... ... @@ -239,6 +246,13 @@ _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 { @@ -268,30 +282,65 @@ [s setTitle: _description]; [s setName: _name]; [s setCompatibility: _compatibility]; + [s setNotes: _notes]; [s setList: [_list name]]; [_array addObject: s]; } _name = nil; _description = nil; _compatibility = nil; + _notes = nil; } return; } if ([@"description" isEqualToString: elementName]) { if (_state == 0b0111) { _state &= ~0b0100; + _description = _scratch; + _scratch = nil; } 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 { - if (_state == 0b0111) { - if (_description) _description = [_description stringByAppendingString: string]; - else _description = string; + if (_state == 0b0111 || _state == 0b1011 || _state == 0b1001) { + if (_scratch) _scratch = [_scratch stringByAppendingString: 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