mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Delete RSCoreObjC.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// NSData+RSCore.h
|
||||
// RSCore
|
||||
//
|
||||
// Created by Brent Simmons on 3/25/15.
|
||||
// Copyright (c) 2015 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
@import Foundation;
|
||||
|
||||
|
||||
BOOL RSEqualBytes(const void *bytes1, const void *bytes2, size_t length);
|
||||
|
||||
NSString *RSHexadecimalStringWithBytes(const unsigned char *bytes, NSUInteger numberOfBytes);
|
||||
|
||||
|
||||
@interface NSData (RSCore)
|
||||
|
||||
- (NSData *)rs_md5Hash;
|
||||
- (NSString *)rs_md5HashString;
|
||||
|
||||
- (BOOL)rs_dataIsPNG;
|
||||
- (BOOL)rs_dataIsGIF;
|
||||
- (BOOL)rs_dataIsJPEG;
|
||||
- (BOOL)rs_dataIsImage;
|
||||
|
||||
- (BOOL)rs_dataIsProbablyHTML;
|
||||
|
||||
- (BOOL)rs_dataBeginsWithBytes:(const void *)bytes length:(size_t)numberOfBytes;
|
||||
|
||||
- (NSString *)rs_noCopyString; //This data object must out-live returned string. May return nil.
|
||||
|
||||
/*If bytes are deadbeef, then string is @"deadbeef". Returns nil for empty data.*/
|
||||
|
||||
- (NSString *)rs_hexadecimalString;
|
||||
|
||||
@end
|
||||
@@ -1,156 +0,0 @@
|
||||
//
|
||||
// NSData+RSCore.m
|
||||
// RSCore
|
||||
//
|
||||
// Created by Brent Simmons on 3/25/15.
|
||||
// Copyright (c) 2015 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import "NSData+RSCore.h"
|
||||
|
||||
|
||||
@implementation NSData (RSCore)
|
||||
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
- (NSData *)rs_md5Hash {
|
||||
|
||||
unsigned char hash[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5([self bytes], (CC_LONG)[self length], hash);
|
||||
|
||||
return [NSData dataWithBytes:(const void *)hash length:CC_MD5_DIGEST_LENGTH];
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
- (NSString *)rs_md5HashString {
|
||||
|
||||
NSData *d = [self rs_md5Hash];
|
||||
return [d rs_hexadecimalString];
|
||||
}
|
||||
|
||||
BOOL RSEqualBytes(const void *bytes1, const void *bytes2, size_t length) {
|
||||
|
||||
return memcmp(bytes1, bytes2, length) == 0;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataBeginsWithBytes:(const void *)bytes length:(size_t)numberOfBytes {
|
||||
|
||||
if ([self length] < numberOfBytes) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return RSEqualBytes([self bytes], bytes, numberOfBytes);
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataIsPNG {
|
||||
|
||||
/* http://www.w3.org/TR/PNG/#5PNG-file-signature : "The first eight bytes of a PNG datastream always contain the following (decimal) values: 137 80 78 71 13 10 26 10" */
|
||||
|
||||
static const Byte pngHeader[] = {137, 'P', 'N', 'G', 13, 10, 26, 10};
|
||||
return [self rs_dataBeginsWithBytes:pngHeader length:sizeof(pngHeader)];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataIsGIF {
|
||||
|
||||
/* http://www.onicos.com/staff/iz/formats/gif.html */
|
||||
|
||||
static const Byte gifHeader1[] = {'G', 'I', 'F', '8', '7', 'a'};
|
||||
if ([self rs_dataBeginsWithBytes:gifHeader1 length:sizeof(gifHeader1)]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
static const Byte gifHeader2[] = {'G', 'I', 'F', '8', '9', 'a'};
|
||||
return [self rs_dataBeginsWithBytes:gifHeader2 length:sizeof(gifHeader2)];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataIsJPEG {
|
||||
|
||||
const void *bytes = [self bytes];
|
||||
|
||||
static const Byte jpegHeader1[] = {'J', 'F', 'I', 'F'};
|
||||
|
||||
if (RSEqualBytes(bytes + 6, jpegHeader1, sizeof(jpegHeader1))) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
static const Byte jpegHeader2[] = {'E', 'x', 'i', 'f'};
|
||||
return RSEqualBytes(bytes + 6, jpegHeader2, sizeof(jpegHeader2));
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataIsImage {
|
||||
|
||||
return [self rs_dataIsPNG] || [self rs_dataIsJPEG] || [self rs_dataIsGIF];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)rs_dataIsProbablyHTML {
|
||||
|
||||
NSString *s = [self rs_noCopyString];
|
||||
if (!s) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![s containsString:@">"] || ![s containsString:@">"]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
for (NSString *oneString in @[@"html", @"body"]) {
|
||||
NSRange range = [s rangeOfString:oneString options:NSCaseInsensitiveSearch];
|
||||
if (range.location == NSNotFound) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)rs_noCopyString {
|
||||
|
||||
NSDictionary *options = @{NSStringEncodingDetectionSuggestedEncodingsKey : @[@(NSUTF8StringEncoding)]};
|
||||
BOOL usedLossyConversion = NO;
|
||||
NSStringEncoding encoding = [NSString stringEncodingForData:self encodingOptions:options convertedString:nil usedLossyConversion:&usedLossyConversion];
|
||||
if (encoding == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [[NSString alloc] initWithBytesNoCopy:(void *)self.bytes length:self.length encoding:encoding freeWhenDone:NO];
|
||||
}
|
||||
|
||||
|
||||
NSString *RSHexadecimalStringWithBytes(const Byte *bytes, NSUInteger numberOfBytes) {
|
||||
|
||||
if (numberOfBytes < 1) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (numberOfBytes == 16) {
|
||||
// Common case — MD5 hash, for example.
|
||||
return [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]];
|
||||
}
|
||||
|
||||
NSMutableString *s = [[NSMutableString alloc] initWithString:@""];
|
||||
NSUInteger i = 0;
|
||||
|
||||
for (i = 0; i < numberOfBytes; i++) {
|
||||
[s appendString:[NSString stringWithFormat:@"%02x", bytes[i]]];
|
||||
}
|
||||
|
||||
return [s copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)rs_hexadecimalString {
|
||||
|
||||
return RSHexadecimalStringWithBytes([self bytes], [self length]);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// NSObject+NSSharingService_RSCore.h
|
||||
// RSCore
|
||||
//
|
||||
// Created by Brent Simmons on 11/3/24.
|
||||
//
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
|
||||
@import AppKit;
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
@interface NSSharingService (NoDeprecationWarning)
|
||||
|
||||
// The only way to create custom UI — a Share menu, for instance —
|
||||
// is to use the unfortunately deprecated
|
||||
// +[NSSharingService sharingServicesForItems:].
|
||||
// This cover method allows us to not generate a warning.
|
||||
//
|
||||
// We know it’s deprecated, and we don’t want to be bugged
|
||||
// about it every time we build. (If anyone from Apple
|
||||
// is reading this — a replacement would be very welcome!)
|
||||
|
||||
+ (NSArray *)sharingServicesForItems_noDeprecationWarning:(NSArray *)items;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// NSSharingService+RSCore.m
|
||||
// RSCore
|
||||
//
|
||||
// Created by Brent Simmons on 11/3/24.
|
||||
//
|
||||
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
|
||||
#import "NSSharingService+RSCore.h"
|
||||
|
||||
@implementation NSSharingService (NoDeprecationWarning)
|
||||
|
||||
+ (NSArray *)sharingServicesForItems_noDeprecationWarning:(NSArray *)items {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
return [NSSharingService sharingServicesForItems:items];
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
//
|
||||
// RSCore.h
|
||||
//
|
||||
//
|
||||
// Created by Maurice Parker on 11/20/20.
|
||||
//
|
||||
|
||||
@import Foundation;
|
||||
|
||||
#import "../NSData+RSCore.h"
|
||||
#import "../NSSharingService+RSCore.h"
|
||||
Reference in New Issue
Block a user