2017-06-25 23:06:01 +02:00
|
|
|
//
|
2017-06-26 01:32:07 +02:00
|
|
|
// RSParserInternal.m
|
2017-06-25 23:06:01 +02:00
|
|
|
// RSParser
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 12/26/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <CommonCrypto/CommonDigest.h>
|
2017-06-26 01:32:07 +02:00
|
|
|
#import "RSParserInternal.h"
|
2017-06-25 23:06:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
static BOOL RSParserIsNil(id obj) {
|
|
|
|
|
|
|
|
return obj == nil || obj == [NSNull null];
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL RSParserObjectIsEmpty(id obj) {
|
|
|
|
|
|
|
|
if (RSParserIsNil(obj)) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([obj respondsToSelector:@selector(count)]) {
|
|
|
|
return [obj count] < 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([obj respondsToSelector:@selector(length)]) {
|
|
|
|
return [obj length] < 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO; /*Shouldn't get here very often.*/
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL RSParserStringIsEmpty(NSString *s) {
|
|
|
|
|
|
|
|
return RSParserIsNil(s) || s.length < 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSDictionary (RSParserInternal)
|
|
|
|
|
|
|
|
- (nullable id)rsparser_objectForCaseInsensitiveKey:(NSString *)key {
|
|
|
|
|
|
|
|
id obj = self[key];
|
|
|
|
if (obj) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSString *oneKey in self.allKeys) {
|
|
|
|
|
|
|
|
if ([oneKey isKindOfClass:[NSString class]] && [key caseInsensitiveCompare:oneKey] == NSOrderedSame) {
|
|
|
|
return self[oneKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|