Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize uppercase filenames used in headers when adding new files to the project #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Framework/PCFileCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,31 @@ - (BOOL)createFiles:(NSDictionary *)fileList
return YES;
}

- (NSString *) sanitizeUppercaseFileNameString:(NSString *) input
{
NSMutableString *sanitizedString = [NSMutableString stringWithCapacity:[input length]];

// Create a character set that includes letters, digits, and the underscore character
NSMutableCharacterSet *allowedCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
[allowedCharacters addCharactersInString:@"_"];

for (NSUInteger i = 0; i < [input length]; i++)
{
unichar character = [input characterAtIndex:i];

if ([allowedCharacters characterIsMember:character])
{
[sanitizedString appendFormat:@"%C", character];
}
else
{
[sanitizedString appendString:@"_"];
}
}

return sanitizedString;
}

- (void)replaceTagsInFileAtPath:(NSString *)newFile
withProject:(PCProject *)aProject
{
Expand All @@ -297,6 +322,8 @@ - (void)replaceTagsInFileAtPath:(NSString *)newFile
NSString *fn = [aFile stringByDeletingPathExtension];
NSRange subRange;

UCfn = [self sanitizeUppercaseFileNameString: UCfn];

#ifdef WIN32
file = [[NSMutableString stringWithContentsOfFile: newFile
encoding: NSUTF8StringEncoding
Expand Down