aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPStringAdditions.h
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-19 23:02:15 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-19 23:02:15 +0000
commit4c4c5c22a47417eaa458739d1599c7bb24f75053 (patch)
tree6d0f15daa532684fe215b7fdf0a3ed3219bdf7c1 /Source/SPStringAdditions.h
parent77d8891b8b3dd3321eac871da0bde6fe1f38ea94 (diff)
downloadsequelpro-4c4c5c22a47417eaa458739d1599c7bb24f75053.tar.gz
sequelpro-4c4c5c22a47417eaa458739d1599c7bb24f75053.tar.bz2
sequelpro-4c4c5c22a47417eaa458739d1599c7bb24f75053.zip
• queryString: code cleaning and processing each encoding equally
- Since we are using mysql_real_query() there is no need to generate a \0 terminated cString. - The disadvantage of using UTF8String is that it returns NULL if the encoding fails. - To process each encoding equally we can now use [NSString dataUsingEncoding:enc allowLossyConversion:lossy]. In oder to avoid the overhead while calling it the following inline function is introduced: NSStringDataUsingLossyEncoding(aStr, enc, lossy) := [aStr dataUsingEncoding:enc allowLossyConversion:lossy] • import of CSV: code cleaned and optimized for speed a little
Diffstat (limited to 'Source/SPStringAdditions.h')
-rw-r--r--Source/SPStringAdditions.h11
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)