aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/SPMySQLFramework')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m15
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h1
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m14
3 files changed, 17 insertions, 13 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
index 0ed8a51e..639ff0b9 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
@@ -239,17 +239,6 @@ static inline NSString * _bitStringWithBytes(const char *bytes, NSUInteger lengt
return returnString;
}
-static inline NSString * _convertStringDataSafely(const void *dataBytes, NSUInteger dataLength, NSStringEncoding aStringEncoding)
-{
- NSString * result = [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease];
-
- if (result == nil) {
- return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:NSASCIIStringEncoding] autorelease];
- }
-
- return result;
-}
-
/**
* Converts stored string data - which may contain nul bytes - to a native
* Objective-C string, using the current class encoding.
@@ -259,7 +248,7 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da
// Fast case - if not using a preview length, or if the data length is shorter, return the requested data.
if (previewLength == NSNotFound || dataLength <= previewLength) {
- return _convertStringDataSafely(dataBytes, dataLength, aStringEncoding);
+ return [NSString stringForDataBytes:dataBytes length:dataLength encoding:aStringEncoding];
}
NSUInteger i = 0, characterLength = 0, byteLength = previewLength;
@@ -405,7 +394,7 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da
// If returning the full string, use a fast path
if (byteLength >= dataLength) {
- return _convertStringDataSafely(dataBytes, dataLength, aStringEncoding);
+ return [NSString stringForDataBytes:dataBytes length:dataLength encoding:aStringEncoding];
}
// Get a string using the calculated details
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h
index bb29c02b..60832c53 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h
@@ -33,5 +33,6 @@
- (NSString *)mySQLBacktickQuotedString;
- (NSString *)mySQLTickQuotedString;
++ (NSString *)stringForDataBytes:(const void *)dataBytes length:(NSUInteger)dataLength encoding:(NSStringEncoding)aStringEncoding;
@end
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m
index 39688ea8..f987c98b 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m
@@ -52,4 +52,18 @@
return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]];
}
+/**
+ * Returns the string for the bytes according to the encoding, decode in ASCII if failed
+ */
++ (NSString *) stringForDataBytes:(const void *)dataBytes length:(NSUInteger)dataLength encoding:(NSStringEncoding)aStringEncoding
+{
+ NSString * string = [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease];
+
+ if (string == nil) {
+ return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:NSASCIIStringEncoding] autorelease];
+ }
+
+ return string;
+}
+
@end