OSDN Git Service

Remove characters from note's title which can't use file name.
authorHirami <tomohisa.hirami@nifty.com>
Sun, 1 Apr 2012 02:49:49 +0000 (11:49 +0900)
committerHirami <tomohisa.hirami@nifty.com>
Sun, 1 Apr 2012 02:49:49 +0000 (11:49 +0900)
iOS/Tombo/Tombo/Storage.m

index c235d3a..012ec76 100644 (file)
     
     return result;
 }
+// Remove characters which can't use file name from given string.
+- (NSString *)removeInvalidFilenameChars:(NSString *)src {
+    NSString *result = src;
+    // chars are same as Tombo for Windows.
+    NSArray *chars = [[NSArray alloc] initWithObjects:@"\\", @"/", @":", @",", @";", @"*", @"?", @"<", @">", @"\"", @"\t", nil];
+    
+    for (NSString *t in chars) {
+        result = [result stringByReplacingOccurrencesOfString:t withString:@""];
+    }
+    return result;
+}
 
 - (FileItem *)decideFileName:(NSString *)titleCand path:(NSString *)origPath {
     FileItem *result = [FileItem alloc];
     NSMutableString *path = [NSMutableString stringWithCapacity:256];
     [path appendString:[origPath stringByDeletingLastPathComponent]];
     [path appendString:@"/"];
-    [path appendString:titleCand];
+    [path appendString:[self removeInvalidFilenameChars:titleCand]];
     NSUInteger n = [path length];
     [path appendString:@"."];
     [path appendString:ext];