aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPStringAdditions.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-05-24 18:07:43 +0000
committerstuconnolly <stuart02@gmail.com>2010-05-24 18:07:43 +0000
commitbbe0f861dd4e3ab99aa3d555d3fc5db5ee5ae39d (patch)
tree1cf7d41f091854e8e2288946684267ce0f8ceaf4 /Source/SPStringAdditions.m
parentd48005bd9b34f2fb1afd31f7487b7bbf8b9b978f (diff)
downloadsequelpro-bbe0f861dd4e3ab99aa3d555d3fc5db5ee5ae39d.tar.gz
sequelpro-bbe0f861dd4e3ab99aa3d555d3fc5db5ee5ae39d.tar.bz2
sequelpro-bbe0f861dd4e3ab99aa3d555d3fc5db5ee5ae39d.zip
Merge export redesign branch back into trunk.
Includes a completely redesign approach to all export data types based on the use of NSOperation subclasses. CSV, SQL, XML and dot export types are currently functional, while the source files for PDF and HTML export types exist they are to be implemented, but are currently hidden from the interface. Also includes the following: - Completely redesigned export interface. - The ability to customize CSV NULL values. - The ability to specify whether the UTF-8 BOM should be used in SQL dumps. - The ability to specify whether BLOB fields are output as hex or plain text during SQL dumps. Defaults to hex. - Exporting currently selected tables via the tables list context menu. Outstanding issues: - Not all progress indicators for all export types are functional (or functioning correctly). - A few issues related to the introduction of only exporting the content and create and drop syntax of specific tables during SQL dumps. Needs some serious testing and benchmarking to ensure it replicates the current export functionality.
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r--Source/SPStringAdditions.m110
1 files changed, 67 insertions, 43 deletions
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index c36e55c1..de1fdf5e 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -82,12 +82,9 @@
return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:size]];
}
-
-// -------------------------------------------------------------------------------
-// stringForTimeInterval:
-//
-// Returns a human readable version string of the supplied time interval.
-// -------------------------------------------------------------------------------
+/**
+ * Returns a human readable version string of the supplied time interval.
+ */
+ (NSString *)stringForTimeInterval:(CGFloat)timeInterval
{
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
@@ -145,42 +142,64 @@
return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:timeInterval]];
}
+/**
+ * Escapes HTML special characters.
+ */
+- (NSString *)HTMLEscapeString
+{
+ NSMutableString *mutableString = [NSMutableString stringWithString:self];
+
+ [mutableString replaceOccurrencesOfString:@"&" withString:@"&amp;"
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [mutableString length])];
+
+ [mutableString replaceOccurrencesOfString:@"<" withString:@"&lt;"
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [mutableString length])];
+
+ [mutableString replaceOccurrencesOfString:@">" withString:@"&gt;"
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [mutableString length])];
+
+ [mutableString replaceOccurrencesOfString:@"\"" withString:@"&quot;"
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [mutableString length])];
+
+ return [NSString stringWithString:mutableString];
+}
-// -------------------------------------------------------------------------------
-// backtickQuotedString
-//
-// Returns the string quoted with backticks as required for MySQL identifiers
-// eg.: tablename => `tablename`
-// my`table => `my``table`
-// -------------------------------------------------------------------------------
+/**
+ * Returns the string quoted with backticks as required for MySQL identifiers
+ * eg.: tablename => `tablename`
+ * my`table => `my``table`
+ */
- (NSString *)backtickQuotedString
{
return [NSString stringWithFormat: @"`%@`", [self stringByReplacingOccurrencesOfString:@"`" withString:@"``"]];
}
-// -------------------------------------------------------------------------------
-// tickQuotedString
-//
-// Returns the string quoted with ticks as required for MySQL identifiers
-// eg.: tablename => 'tablename'
-// my'table => 'my''table'
-// -------------------------------------------------------------------------------
+/**
+ * Returns the string quoted with ticks as required for MySQL identifiers
+ * eg.: tablename => 'tablename'
+ * my'table => 'my''table'
+ */
- (NSString *)tickQuotedString
{
return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]];
}
+/**
+ *
+ */
- (NSString *)replaceUnderscoreWithSpace
{
return [self stringByReplacingOccurrencesOfString:@"_" withString:@" "];
}
-// -------------------------------------------------------------------------------
-// createViewSyntaxPrettifier
-//
-// Returns a 'CREATE VIEW SYNTAX' string a bit more readable
-// If the string doesn't match it returns the unchanged string.
-// -------------------------------------------------------------------------------
+/**
+ * Returns a 'CREATE VIEW SYNTAX' string a bit more readable
+ * If the string doesn't match it returns the unchanged string.
+ */
- (NSString *)createViewSyntaxPrettifier
{
NSRange searchRange = NSMakeRange(0, [self length]);
@@ -219,16 +238,13 @@
return(tblSyntax);
}
-
-// -------------------------------------------------------------------------------
-// lineRangesForRange
-//
-// Returns an array of serialised NSRanges, each representing a line within the string
-// which is at least partially covered by the NSRange supplied.
-// Each line includes the line termination character(s) for the line. As per
-// lineRangeForRange, lines are split by CR, LF, CRLF, U+2028 (Unicode line separator),
-// or U+2029 (Unicode paragraph separator).
-// -------------------------------------------------------------------------------
+/**
+ * Returns an array of serialised NSRanges, each representing a line within the string
+ * which is at least partially covered by the NSRange supplied.
+ * Each line includes the line termination character(s) for the line. As per
+ * lineRangeForRange, lines are split by CR, LF, CRLF, U+2028 (Unicode line separator),
+ * or U+2029 (Unicode paragraph separator).
+ */
- (NSArray *)lineRangesForRange:(NSRange)aRange
{
NSMutableArray *lineRangesArray = [NSMutableArray array];
@@ -252,7 +268,6 @@
return lineRangesArray;
}
-
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
/*
* componentsSeparatedByCharactersInSet:
@@ -286,8 +301,10 @@
}
#endif
-
-- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*) charSet options:(NSUInteger) mask
+/**
+ *
+ */
+- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet *)charSet options:(NSUInteger)mask
{
NSRange range;
NSMutableString* newString = [NSMutableString string];
@@ -316,13 +333,17 @@
return newString;
}
-
-- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*) charSet
+/**
+ *
+ */
+- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet *)charSet
{
return [self stringByRemovingCharactersInSet:charSet options:0];
}
-// calculate the distance between two string case-insensitively
+/**
+ * Calculate the distance between two string case-insensitively
+ */
- (CGFloat)levenshteinDistanceWithWord:(NSString *)stringB
{
// normalize strings
@@ -368,10 +389,13 @@
return distance;
}
+
return 0.0;
}
-// return the minimum of a, b and c
+/**
+ * Returns the minimum of a, b and c
+ */
- (NSInteger)smallestOf:(NSInteger)a andOf:(NSInteger)b andOf:(NSInteger)c
{
NSInteger min = a;