Rename some methods; remove extraneous others

This commit is contained in:
achmizs 2021-12-05 15:20:50 -05:00
parent 76fe55b89c
commit cb674c9ac3
2 changed files with 5 additions and 50 deletions

View File

@ -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').

View File

@ -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];