diff options
Diffstat (limited to 'Source/SPStringAdditions.h')
-rw-r--r-- | Source/SPStringAdditions.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 3b6805e2..540492c0 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -38,6 +38,17 @@ static inline const char* NSStringUTF8String(NSString* self) { return to_return; } +/* + * NSStringDataUsingLossyEncoding(aStr, enc, lossy) := [aStr dataUsingEncoding:enc allowLossyConversion:lossy] + */ +static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, int encoding, int lossy) { + typedef NSData* (*SPStringDataUsingLossyEncodingMethodPtr)(NSString*, SEL, int, int); + static SPStringDataUsingLossyEncodingMethodPtr SPNSStringDataUsingLossyEncoding; + if (!SPNSStringDataUsingLossyEncoding) SPNSStringDataUsingLossyEncoding = (SPStringDataUsingLossyEncodingMethodPtr)[self methodForSelector:@selector(dataUsingEncoding:allowLossyConversion:)]; + NSData* to_return = SPNSStringDataUsingLossyEncoding(self, @selector(dataUsingEncoding:allowLossyConversion:), encoding, lossy); + return to_return; +} + @interface NSString (SPStringAdditions) |