소스 검색

Rename some methods; remove extraneous others

master
achmizs 4 년 전
부모
커밋
cb674c9ac3
2개의 변경된 파일5개의 추가작업 그리고 50개의 파일을 삭제
  1. 2
    30
      NSData+SA_NSDataExtensions.h
  2. 3
    20
      NSData+SA_NSDataExtensions.m

+ 2
- 30
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').

+ 3
- 20
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];

Loading…
취소
저장