Skip to content

Commit 61c797a

Browse files
committed
Tweaked the thumbnail (icon)
1 parent 55b47d8 commit 61c797a

File tree

9 files changed

+296
-214
lines changed

9 files changed

+296
-214
lines changed

CSVDocument.m

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @implementation CSVDocument
1919
- (id) init
2020
{
2121
self = [super init];
22-
if(nil != self) {
22+
if (nil != self) {
2323
self.separator = @",";
2424
}
2525

@@ -54,20 +54,20 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
5454
NSUInteger numRows = 0;
5555

5656
// String is non-empty
57-
if([string length] > 0) {
57+
if ([string length] > 0) {
5858
NSMutableArray *thisRows = [NSMutableArray array];
5959
NSMutableArray *thisColumnKeys = [NSMutableArray array];
6060

6161
// Check whether the file uses ";" or TAB as separator by comparing relative occurrences in the first 200 chars
62-
if(autoDetectSeparator) {
62+
if (autoDetectSeparator) {
6363
self.separator = @",";
6464

6565
NSUInteger testStringLength = ([string length] > 200) ? 200 : [string length];
6666
NSString *testString = [string substringToIndex:testStringLength];
6767
NSArray *possSeparators = [NSArray arrayWithObjects:@";", @" ", nil];
6868

69-
for(NSString *s in possSeparators) {
70-
if([[testString componentsSeparatedByString:s] count] > [[testString componentsSeparatedByString:separator] count]) {
69+
for (NSString *s in possSeparators) {
70+
if ([[testString componentsSeparatedByString:s] count] > [[testString componentsSeparatedByString:separator] count]) {
7171
self.separator = s;
7272
}
7373
}
@@ -87,6 +87,7 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
8787
BOOL insideQuotes = NO; // needed to determine whether we're inside doublequotes
8888
BOOL finishedRow = NO; // used for the inner while loop
8989
BOOL isNewColumn = NO;
90+
BOOL skipWhitespace = (NSNotFound == [separator rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location);
9091
NSMutableDictionary *columns = nil;
9192
NSMutableString *currentCellString = [NSMutableString string];
9293
NSUInteger colIndex = 0;
@@ -106,7 +107,7 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
106107
while(!finishedRow) {
107108
NSString *tempString;
108109
NSString *colKey;
109-
if([thisColumnKeys count] > colIndex) {
110+
if ([thisColumnKeys count] > colIndex) {
110111
colKey = [thisColumnKeys objectAtIndex:colIndex];
111112
isNewColumn = NO;
112113
}
@@ -117,25 +118,25 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
117118

118119

119120
// Scan characters into our string
120-
if([scanner scanUpToCharactersFromSet:importantCharactersSet intoString:&tempString] ) {
121+
if ([scanner scanUpToCharactersFromSet:importantCharactersSet intoString:&tempString] ) {
121122
[currentCellString appendString:tempString];
122123
}
123124

124125

125126
// found the separator
126-
if([scanner scanString:separator intoString:NULL]) {
127-
if(insideQuotes) { // Separator character inside double quotes
127+
if ([scanner scanString:separator intoString:NULL]) {
128+
if (insideQuotes) { // Separator character inside double quotes
128129
[currentCellString appendString:separator];
129130
}
130131
else { // This is a column separating comma
131132
[columns setObject:[currentCellString copy] forKey:colKey];
132-
if(isNewColumn) {
133+
if (isNewColumn) {
133134
[thisColumnKeys addObject:colKey];
134135
}
135136

136137
// on to the next column/cell!
137138
[currentCellString setString:@""];
138-
if (NSNotFound == [separator rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location) {
139+
if (skipWhitespace) {
139140
[scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL];
140141
}
141142
colIndex++;
@@ -144,8 +145,8 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
144145

145146

146147
// found a doublequote (")
147-
else if([scanner scanString:@"\"" intoString:NULL]) {
148-
if(insideQuotes && [scanner scanString:@"\"" intoString:NULL]) { // Replace double - doublequotes with a single doublequote in our string.
148+
else if ([scanner scanString:@"\"" intoString:NULL]) {
149+
if (insideQuotes && [scanner scanString:@"\"" intoString:NULL]) { // Replace double - doublequotes with a single doublequote in our string.
149150
[currentCellString appendString:@"\""];
150151
}
151152
else { // Start or end of a quoted string.
@@ -155,13 +156,13 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
155156

156157

157158
// found a newline
158-
else if([scanner scanCharactersFromSet:newlineCharacterSet intoString:&tempString]) {
159-
if(insideQuotes) { // We're inside quotes - add line break to column text
159+
else if ([scanner scanCharactersFromSet:newlineCharacterSet intoString:&tempString]) {
160+
if (insideQuotes) { // We're inside quotes - add line break to column text
160161
[currentCellString appendString:tempString];
161162
}
162163
else { // End of row
163164
[columns setObject:[currentCellString copy] forKey:colKey];
164-
if(isNewColumn) {
165+
if (isNewColumn) {
165166
[thisColumnKeys addObject:colKey];
166167
}
167168

@@ -171,9 +172,9 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
171172

172173

173174
// found the end
174-
else if([scanner isAtEnd]) {
175+
else if ([scanner isAtEnd]) {
175176
[columns setObject:[currentCellString copy] forKey:colKey];
176-
if(isNewColumn) {
177+
if (isNewColumn) {
177178
[thisColumnKeys addObject:colKey];
178179
}
179180

@@ -183,13 +184,13 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
183184

184185

185186
// one row scanned - add to the lines array
186-
if([columns count] > 0) {
187+
if ([columns count] > 0) {
187188
CSVRowObject *newRow = [CSVRowObject rowFromDict:columns];
188189
[thisRows addObject:newRow];
189190
}
190191

191192
numRows++;
192-
if((maxRows > 0) && (numRows > maxRows)) {
193+
if ((maxRows > 0) && (numRows > maxRows)) {
193194
break;
194195
}
195196
}
@@ -200,7 +201,7 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
200201
}
201202

202203
// empty string
203-
else if(nil != error) {
204+
else if (nil != error) {
204205
NSDictionary *errorDict = [NSDictionary dictionaryWithObject:@"Cannot parse an empty string" forKey:@"userInfo"];
205206
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:errorDict];
206207
}
@@ -214,7 +215,7 @@ - (NSUInteger) numRowsFromCSVString:(NSString *)string maxRows:(NSUInteger)maxRo
214215
#pragma mark Document Properties
215216
- (BOOL) isFirstColumn:(NSString *)columnKey
216217
{
217-
if((nil != columnKeys) && ([columnKeys count] > 0)) {
218+
if ((nil != columnKeys) && ([columnKeys count] > 0)) {
218219
return [columnKey isEqualToString:[columnKeys objectAtIndex:0]];
219220
}
220221

CSVRowObject.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ + (CSVRowObject *) rowFromDict:(NSMutableDictionary *)dict
2525
{
2626
CSVRowObject *row = [CSVRowObject row];
2727

28-
if(dict) {
28+
if (dict) {
2929
row.columns = dict;
3030
}
3131

@@ -47,7 +47,7 @@ - (NSString *) columns:(NSArray *)columnKeys combinedByString:(NSString *)sepStr
4747
{
4848
NSString *rowString = nil;
4949

50-
if((nil != columnKeys) && (nil != columns)) {
50+
if ((nil != columnKeys) && (nil != columns)) {
5151
rowString = [[columns objectsForKeys:columnKeys notFoundMarker:@""] componentsJoinedByString:sepString];
5252
}
5353

@@ -58,7 +58,7 @@ - (NSString *) columnForKey:(NSString *)columnKey
5858
{
5959
NSString *cellString = nil;
6060

61-
if((nil != columnKey) && (nil != columns)) {
61+
if ((nil != columnKey) && (nil != columns)) {
6262
cellString = [columns objectForKey:columnKey];
6363
}
6464

English.lproj/InfoPlist.strings

-4 Bytes
Binary file not shown.

GeneratePreviewForURL.m

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
3939
NSString *fileString = [NSString stringWithContentsOfURL:myURL usedEncoding:&stringEncoding error:&theErr];
4040

4141
// We could not open the file, probably unknown encoding; try ISO-8859-1
42-
if(nil == fileString) {
42+
if (nil == fileString) {
4343
stringEncoding = NSISOLatin1StringEncoding;
4444
fileString = [NSString stringWithContentsOfURL:myURL encoding:stringEncoding error:&theErr];
4545

4646
// Still no success, give up
47-
if(nil == fileString) {
48-
if(nil != theErr) {
47+
if (nil == fileString) {
48+
if (nil != theErr) {
4949
NSLog(@"Error opening the file: %@", theErr);
5050
}
5151

@@ -56,14 +56,14 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
5656

5757

5858
// Parse the data if still interested in the preview
59-
if(false == QLPreviewRequestIsCancelled(preview)) {
59+
if (false == QLPreviewRequestIsCancelled(preview)) {
6060
CSVDocument *csvDoc = [CSVDocument csvDoc];
6161
csvDoc.autoDetectSeparator = YES;
6262
NSUInteger numRowsParsed = [csvDoc numRowsFromCSVString:fileString maxRows:MAX_ROWS error:NULL];
6363

6464

6565
// Create HTML of the data if still interested in the preview
66-
if(false == QLPreviewRequestIsCancelled(preview)) {
66+
if (false == QLPreviewRequestIsCancelled(preview)) {
6767
NSBundle *myBundle = [NSBundle bundleForClass:[CSVDocument class]];
6868

6969
NSString *cssPath = [myBundle pathForResource:@"Style" ofType:@"css"];
@@ -77,7 +77,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
7777
[html appendString:@"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\"><head>\n"];
7878
[html appendFormat:@"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n", htmlReadableFileEncoding(stringEncoding)];
7979
[html appendString:@"<style>\n"];
80-
if(nil != css) {
80+
if (nil != css) {
8181
[html appendString:css];
8282
[css release];
8383
}
@@ -90,7 +90,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
9090

9191
// add the table rows
9292
BOOL altRow = NO;
93-
for(CSVRowObject *row in csvDoc.rows) {
93+
for (CSVRowObject *row in csvDoc.rows) {
9494
[html appendFormat:@"<tr%@><td>", altRow ? @" class=\"alt_row\"" : @""];
9595
[html appendString:[row columns:csvDoc.columnKeys combinedByString:@"</td><td>"]];
9696
[html appendString:@"</td></tr>\n"];
@@ -101,7 +101,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
101101
[html appendString:@"</table>\n"];
102102

103103
// not all rows were parsed, show hint
104-
if(numRowsParsed > MAX_ROWS) {
104+
if (numRowsParsed > MAX_ROWS) {
105105
NSString *rowsHint = [NSString stringWithFormat:NSLocalizedString(@"Only the first %i rows are being displayed", nil), MAX_ROWS];
106106
[html appendFormat:@"<div class=\"truncated_rows\">%@</div>", rowsHint];
107107
}
@@ -131,24 +131,24 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
131131
// to be used for the generated HTML
132132
static char* htmlReadableFileEncoding(NSStringEncoding stringEncoding)
133133
{
134-
if(NSUTF8StringEncoding == stringEncoding ||
134+
if (NSUTF8StringEncoding == stringEncoding ||
135135
NSUnicodeStringEncoding == stringEncoding) {
136136
return "utf-8";
137137
}
138-
if(NSASCIIStringEncoding == stringEncoding) {
138+
if (NSASCIIStringEncoding == stringEncoding) {
139139
return "ascii";
140140
}
141-
if(NSISOLatin1StringEncoding == stringEncoding) {
141+
if (NSISOLatin1StringEncoding == stringEncoding) {
142142
return "iso-8859-1";
143143
}
144-
if(NSMacOSRomanStringEncoding == stringEncoding) {
144+
if (NSMacOSRomanStringEncoding == stringEncoding) {
145145
return "x-mac-roman";
146146
}
147-
if(NSUTF16BigEndianStringEncoding == stringEncoding ||
147+
if (NSUTF16BigEndianStringEncoding == stringEncoding ||
148148
NSUTF16LittleEndianStringEncoding == stringEncoding) {
149149
return "utf-16";
150150
}
151-
if(NSUTF32StringEncoding == stringEncoding ||
151+
if (NSUTF32StringEncoding == stringEncoding ||
152152
NSUTF32BigEndianStringEncoding == stringEncoding ||
153153
NSUTF32LittleEndianStringEncoding == stringEncoding) {
154154
return "utf-32";
@@ -160,24 +160,24 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
160160

161161
static char* humanReadableFileEncoding(NSStringEncoding stringEncoding)
162162
{
163-
if(NSUTF8StringEncoding == stringEncoding ||
163+
if (NSUTF8StringEncoding == stringEncoding ||
164164
NSUnicodeStringEncoding == stringEncoding) {
165165
return "UTF-8";
166166
}
167-
if(NSASCIIStringEncoding == stringEncoding) {
167+
if (NSASCIIStringEncoding == stringEncoding) {
168168
return "ASCII-text";
169169
}
170-
if(NSISOLatin1StringEncoding == stringEncoding) {
170+
if (NSISOLatin1StringEncoding == stringEncoding) {
171171
return "ISO-8859-1";
172172
}
173-
if(NSMacOSRomanStringEncoding == stringEncoding) {
173+
if (NSMacOSRomanStringEncoding == stringEncoding) {
174174
return "Mac-Roman";
175175
}
176-
if(NSUTF16BigEndianStringEncoding == stringEncoding ||
176+
if (NSUTF16BigEndianStringEncoding == stringEncoding ||
177177
NSUTF16LittleEndianStringEncoding == stringEncoding) {
178178
return "UTF-16";
179179
}
180-
if(NSUTF32StringEncoding == stringEncoding ||
180+
if (NSUTF32StringEncoding == stringEncoding ||
181181
NSUTF32BigEndianStringEncoding == stringEncoding ||
182182
NSUTF32LittleEndianStringEncoding == stringEncoding) {
183183
return "UTF-32";
@@ -188,7 +188,7 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
188188

189189

190190
static char* formatFilesize(float bytes) {
191-
if(bytes < 1) {
191+
if (bytes < 1) {
192192
return "";
193193
}
194194

@@ -199,7 +199,7 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
199199
bytes /= 1024;
200200
i++;
201201

202-
if(i >= 5) { // we most likely won't end up here, but let's be sure
202+
if (i >= 5) { // we most likely won't end up here, but let's be sure
203203
break;
204204
}
205205
}

0 commit comments

Comments
 (0)