C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
ppc,
i386,
);
+ GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
#include <netdb.h>
#include <stdlib.h>
#include <WebKit/WebKit.h>
+#include <unistd.h>
@interface AppController (Private)
- (void)setStatus:(NSString *)msg isError:(BOOL)error;
*/
- (NSString *)getUploadSafeName:(NSString *)name
{
- NSMutableString *n = [NSMutableString stringWithString:name];
- [n replaceOccurrencesOfString:@" " withString:@"" options:NSBackwardsSearch range:NSMakeRange(0, [name length])];
- name = (NSString *)n;
+ NSMutableString *safeName = [NSMutableString string];
+
name = [name lastPathComponent];
name = [name stringByDeletingPathExtension];
- if ([name length] > 20)
- name = [name substringToIndex:20];
+
+ for (int i = 0, j = 0; i < [name length] && j < 20; i++)
+ {
+ char c = [name characterAtIndex:i];
+ if ((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && 122) || c == 95)
+ {
+ [safeName appendFormat:@"%c", c];
+ j++;
+ }
+ else if (c == 32)
+ {
+ if (j > 0 && [safeName characterAtIndex:j - 1] != '-')
+ {
+ [safeName appendString:@"_"];
+ j++;
+ }
+ }
+ else if (c >= 38 && c <= 46)
+ {
+ if (j > 0 && [safeName characterAtIndex:j - 1] != '_')
+ {
+ [safeName appendString:@"-"];
+ j++;
+ }
+ }
+ }
srandomdev();
- return [NSString stringWithFormat:@"~/%@.%d.pdf", name, random()];
+ return [NSString stringWithFormat:@"~/%@.%d.pdf", safeName, random()];
}
@end