Skip to content

Commit 119887e

Browse files
authored
Merge pull request #82 from rollout/master
Fixed handling references in unicode with characters taking more than…
2 parents 600e071 + 51492fc commit 119887e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Source/XCProject.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,29 @@ - (NSArray*)applicationTargets
406406
return filteredTargets;
407407
}
408408

409+
- (NSData *)_fixEncodingInData:(NSData *)data
410+
{
411+
NSString *source = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
412+
NSMutableString *destination = @"".mutableCopy;
413+
for(int i = 0; i < source.length; i++) {
414+
unichar c = [source characterAtIndex:i];
415+
if(c < 128) {
416+
[destination appendFormat:@"%c", c];
417+
} else {
418+
[destination appendFormat:@"&#%u;", c];
419+
}
420+
}
421+
422+
return [destination dataUsingEncoding:NSUTF8StringEncoding];
423+
}
424+
409425
- (void)save
410426
{
411427
[_fileOperationQueue commitFileOperations];
412-
[_dataStore writeToFile:[_filePath stringByAppendingPathComponent:@"project.pbxproj"] atomically:YES];
428+
429+
NSData *data = [NSPropertyListSerialization dataWithPropertyList:_dataStore format:NSPropertyListXMLFormat_v1_0 options:0 error:NULL];
430+
data = [self _fixEncodingInData:data];
431+
[data writeToFile:[_filePath stringByAppendingPathComponent:@"project.pbxproj"] atomically:YES];
413432

414433
// Don't forget to reset the cache so that we'll always get the latest data.
415434
[self dropCache];

0 commit comments

Comments
 (0)