From cb674c9ac37358023984b2103de74f17212de941 Mon Sep 17 00:00:00 2001 From: achmizs <1874748+achmizs@users.noreply.github.com> Date: Sun, 5 Dec 2021 15:20:50 -0500 Subject: [PATCH] Rename some methods; remove extraneous others --- NSData+SA_NSDataExtensions.h | 32 ++------------------------------ NSData+SA_NSDataExtensions.m | 23 +++-------------------- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/NSData+SA_NSDataExtensions.h b/NSData+SA_NSDataExtensions.h index 1b38dfa..3a6d898 100644 --- a/NSData+SA_NSDataExtensions.h +++ b/NSData+SA_NSDataExtensions.h @@ -30,7 +30,7 @@ null-terminated, the returned pointer will point to bytes managed by a copy of the receiver (and the bytes of the copy will be null-terminated). */ -@property (readonly) const char *SA_terminatedCString; +@property (readonly) const char *terminatedCString; /** Returns data containing the stored bytes as a null-terminated C string (byte array). @@ -40,35 +40,7 @@ reference to a fresh copy of the receiver (a copy that contains a null-terminated byte array, of course). */ -@property (readonly) NSData *SA_dataWithTerminatedCString; - -/** Returns the stored bytes as an non-null-terminated byte array. - - If the stored data was not null-terminated to begin with, the returned - pointer will be a pointer to the bytes managed by the receiver. If the - stored data was null-terminated, the returned pointer will point to bytes - managed by a copy of the receiver (and the bytes of the copy will not be - null-terminated; but see NOTE). - - NOTE: If the receiver's *last* byte is null, the bytes pointed to by the - returned pointer will have that null stripped; but if there are any more - null bytes prior to that last null, they will remain untouched! - */ -@property (readonly) const char *SA_unterminatedByteString; - -/** Returns data containing the stored bytes as a non-null-terminated byte - array. - - If the stored data was not null-terminated to begin with, this method simply - returns the receiver. If the stored data was null-terminated, this method - returns a reference to a fresh copy of the receiver (a copy that contains a - non-null-terminated byte array, of course; but see NOTE). - - NOTE: If the receiver's *last* byte is null, the bytes managed by the - returned object will have that null stripped; but if there are any more - null bytes prior to that last null, they will remain untouched! - */ -@property (readonly) NSData *SA_dataWithUnterminatedByteString; +@property (readonly) NSData *dataWithTerminatedCString; /** Returns an NSData object containing a blank C string (i.e. a byte sequence of length 1, containing the null character '\0'). diff --git a/NSData+SA_NSDataExtensions.m b/NSData+SA_NSDataExtensions.m index b60638f..8cfa859 100644 --- a/NSData+SA_NSDataExtensions.m +++ b/NSData+SA_NSDataExtensions.m @@ -15,11 +15,11 @@ return (((char*) self.bytes)[self.length - 1] == '\0'); } --(const char *) SA_terminatedCString { - return self.SA_dataWithTerminatedCString.bytes; +-(const char *) terminatedCString { + return self.dataWithTerminatedCString.bytes; } --(NSData *) SA_dataWithTerminatedCString { +-(NSData *) dataWithTerminatedCString { if (self.length == 0) { return [NSData dataWithBytes:"\0" length:1]; @@ -37,23 +37,6 @@ } } --(const char *) SA_unterminatedByteString { - return self.SA_dataWithUnterminatedByteString.bytes; -} - --(NSData *) SA_dataWithUnterminatedByteString { - if (self.length == 0 || self.isNullTerminated == NO) { - return self; - } else { - char* unterminated_string_buffer = malloc(self.length - 1); - [self getBytes:unterminated_string_buffer length:self.length - 1]; - - return [NSData dataWithBytesNoCopy:unterminated_string_buffer - length:(self.length - 1) - freeWhenDone:YES]; - } -} - +(NSData *) dataWithBlankCString { return [NSData dataWithBytes:"\0" length:1]; -- 2.11.4.GIT