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 1 commit
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
25 changes: 25 additions & 0 deletions Framework/PCFileCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ - (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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else should be on separate lines... like so...

}
else
{

Other than that looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

[sanitizedString appendString:@"_"];
}
}

return sanitizedString;
}

- (void)replaceTagsInFileAtPath:(NSString *)newFile
withProject:(PCProject *)aProject
{
Expand All @@ -297,6 +320,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