#include #include #include #include #include #include #include @implementation PXString /* init/lifecycle */ + (instancetype)stringWithCString:(const char *)cstring { PXString *string = [PXString alloc]; return [string initWithCString:cstring]; } - (instancetype)init { return [self initWithCString:""]; } - (instancetype)initWithCString:(const char *)cstring { self = [super init]; if (self) { if (cstring == NULL) cstring = ""; _length = strlen(cstring); _bytes = malloc(_length + 1); memcpy(_bytes, cstring, _length + 1); } return self; } - (void)dealloc { free(_bytes); [super dealloc]; } /* getters */ - (const char *)UTF8String { return _bytes; } - (size_t)length { return _length; } - (BOOL)isEqual:(PXString *)string { if (self == string) return YES; if (string == nil || _length != string->_length) return NO; return (memcmp(_bytes, string->_bytes, _length) == 0); } @end