mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Escape more chars (' ', '\t', '\\', '%', '#', '|' '"') in "drop files"
git-svn-id: http://macvim.googlecode.com/svn/trunk@313 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
+1
-1
@@ -2008,7 +2008,7 @@ enum {
|
||||
for (i = 0; i < n && bytes < end; ++i) {
|
||||
int len = *((int*)bytes); bytes += sizeof(int);
|
||||
NSString *file = [NSString stringWithUTF8String:bytes];
|
||||
file = [file stringByEscapingInvalidFilenameCharacters];
|
||||
file = [file stringByEscapingSpecialFilenameCharacters];
|
||||
bytes += len;
|
||||
|
||||
[cmd appendString:@" "];
|
||||
|
||||
@@ -220,9 +220,7 @@ ATSFontContainerRef loadFonts();
|
||||
|
||||
|
||||
@interface NSString (MMExtras)
|
||||
- (NSString *)stringByEscapingPercent;
|
||||
- (NSString *)stringByEscapingSpace;
|
||||
- (NSString *)stringByEscapingInvalidFilenameCharacters;
|
||||
- (NSString *)stringByEscapingSpecialFilenameCharacters;
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -124,46 +124,42 @@ loadFonts()
|
||||
|
||||
@implementation NSString (MMExtras)
|
||||
|
||||
- (NSString *)stringByEscapingPercent
|
||||
- (NSString *)stringByEscapingSpecialFilenameCharacters
|
||||
{
|
||||
// NOTE: This code assumes that no characters already have been escaped.
|
||||
NSMutableString *string = [self mutableCopy];
|
||||
|
||||
// Some '%' may already be escaped, so un-escape first...
|
||||
[string replaceOccurrencesOfString:@"\\%"
|
||||
withString:@"%"
|
||||
[string replaceOccurrencesOfString:@"\\"
|
||||
withString:@"\\\\"
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
// ...then escape all '%'
|
||||
[string replaceOccurrencesOfString:@"%"
|
||||
withString:@"\\%"
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
|
||||
return [string autorelease];
|
||||
}
|
||||
|
||||
- (NSString *)stringByEscapingSpace
|
||||
{
|
||||
NSMutableString *string = [self mutableCopy];
|
||||
|
||||
// Some space chars may already be escaped, so un-escape first...
|
||||
[string replaceOccurrencesOfString:@"\\ "
|
||||
withString:@" "
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
// ...then escape all space chars
|
||||
[string replaceOccurrencesOfString:@" "
|
||||
withString:@"\\ "
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
[string replaceOccurrencesOfString:@"\t"
|
||||
withString:@"\\\t "
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
[string replaceOccurrencesOfString:@"%"
|
||||
withString:@"\\%"
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
[string replaceOccurrencesOfString:@"#"
|
||||
withString:@"\\#"
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
[string replaceOccurrencesOfString:@"|"
|
||||
withString:@"\\|"
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
[string replaceOccurrencesOfString:@"\""
|
||||
withString:@"\\\""
|
||||
options:NSLiteralSearch
|
||||
range:NSMakeRange(0, [string length])];
|
||||
|
||||
return [string autorelease];
|
||||
}
|
||||
|
||||
- (NSString *)stringByEscapingInvalidFilenameCharacters
|
||||
{
|
||||
return [[self stringByEscapingSpace] stringByEscapingPercent];
|
||||
}
|
||||
|
||||
|
||||
@end // NSString (MMExtras)
|
||||
|
||||
Reference in New Issue
Block a user