Fixed bugs: canParse & expected type error & html entities method name

This commit is contained in:
relikd
2019-01-15 22:08:23 +01:00
parent ca9452bc18
commit 8e5938972d
5 changed files with 53 additions and 38 deletions

View File

@@ -42,4 +42,4 @@ typedef NS_ERROR_ENUM(kRSXMLParserErrorDomain, RSXMLError) {
};
NSError * RSXMLMakeError(RSXMLError code);
NSError * RSXMLMakeErrorWrongParser(RSXMLError code, RSXMLError expected);
NSError * RSXMLMakeErrorWrongParser(RSXMLError expected, RSXMLError other);

View File

@@ -36,8 +36,8 @@ const char * parserDescriptionForError(RSXMLError code) {
}
}
NSString * getErrorMessageForRSXMLError(RSXMLError code, RSXMLError expected);
NSString * getErrorMessageForRSXMLError(RSXMLError code, RSXMLError expected) {
NSString * getErrorMessageForRSXMLError(RSXMLError code, RSXMLError other);
NSString * getErrorMessageForRSXMLError(RSXMLError code, RSXMLError other) {
switch (code) { // switch statement will warn if an enum value is missing
case RSXMLErrorNoData:
return @"Can't parse data. Empty data.";
@@ -53,7 +53,7 @@ NSString * getErrorMessageForRSXMLError(RSXMLError code, RSXMLError expected) {
case RSXMLErrorExpectingOPML:
case RSXMLErrorExpectingFeed:
return [NSString stringWithFormat:@"Can't parse XML. %s expected, but %s found.",
parserDescriptionForError(code), parserDescriptionForError(expected)];
parserDescriptionForError(code), parserDescriptionForError(other)];
}
}
@@ -61,7 +61,7 @@ NSError * RSXMLMakeError(RSXMLError code) {
return RSXMLMakeErrorWrongParser(code, RSXMLErrorNoData);
}
NSError * RSXMLMakeErrorWrongParser(RSXMLError code, RSXMLError expected) {
return [NSError errorWithDomain:kRSXMLParserErrorDomain code:code
userInfo:@{NSLocalizedDescriptionKey: getErrorMessageForRSXMLError(code, expected)}];
NSError * RSXMLMakeErrorWrongParser(RSXMLError expected, RSXMLError other) {
return [NSError errorWithDomain:kRSXMLParserErrorDomain code:expected
userInfo:@{NSLocalizedDescriptionKey: getErrorMessageForRSXMLError(expected, other)}];
}

View File

@@ -118,9 +118,9 @@
});
}
/// @return @c YES if @c .xmlInputError is not @c nil.
/// @return @c YES if @c .xmlInputError is @c nil.
- (BOOL)canParse {
return (self.xmlInputError != nil);
return (self.xmlInputError == nil);
}
@@ -150,10 +150,10 @@
if (!xmlParserClass)
return NO;
if (xmlParserClass != [self class]) { // && !_xmlInputError
RSXMLError current = [self getExpectedErrorForClass:[self class]];
RSXMLError expected = [self getExpectedErrorForClass:xmlParserClass];
RSXMLError current = [self getExpectedErrorForClass:xmlParserClass];
RSXMLError expected = [self getExpectedErrorForClass:[self class]];
if (current != expected) {
_xmlInputError = RSXMLMakeErrorWrongParser(current, expected);
_xmlInputError = RSXMLMakeErrorWrongParser(expected, current);
return NO;
}
}