mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
* Tools/make_strings/StringsFile.m: Write the file in UTF8 format
if the string contains any non ASCII character.
This commit is contained in:
parent
6977d9e759
commit
46c463c006
2 changed files with 43 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
2021-02-05 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Tools/make_strings/StringsFile.m: Write the file in UTF8 format
|
||||
if the string contains any non ASCII character.
|
||||
|
||||
2021-02-03 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Tools/GNUmakefile: disable gdomap on Android (unsupported).
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#import "Foundation/NSString.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSFileManager.h"
|
||||
#import "Foundation/NSData.h"
|
||||
#import "Foundation/NSDate.h"
|
||||
|
||||
#include "StringsFile.h"
|
||||
|
@ -373,6 +374,42 @@ static NSString *parse_string(NSString **ptr)
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) _writeString: (NSString *)str toFile: (NSString *)filename
|
||||
{
|
||||
BOOL isAscii = YES;
|
||||
NSUInteger len = [str length];
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unichar u = [str characterAtIndex: i];
|
||||
if (u > 127)
|
||||
{
|
||||
isAscii = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isAscii)
|
||||
{
|
||||
return [str writeToFile: filename atomically: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSData *d = [str dataUsingEncoding: NSUTF8StringEncoding];
|
||||
NSMutableData *md = [[NSMutableData alloc] initWithCapacity: [d length] + 3];
|
||||
// Add BOM at the beginning of the file
|
||||
char bytes[] = {0xEF, 0xBB, 0xBF};
|
||||
BOOL result;
|
||||
|
||||
[md appendBytes: bytes length: 3];
|
||||
[md appendData: d];
|
||||
result = [md writeToFile: filename atomically: YES];
|
||||
[md release];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) writeToFile: (NSString *)filename
|
||||
{
|
||||
unsigned int i,c;
|
||||
|
@ -528,7 +565,7 @@ static NSString *parse_string(NSString **ptr)
|
|||
[[NSFileManager defaultManager] movePath: filename
|
||||
toPath: backupname
|
||||
handler: nil];
|
||||
result = [str writeToFile: filename atomically: YES];
|
||||
result = [self _writeString: str toFile: filename];
|
||||
|
||||
if (!result)
|
||||
fprintf(stderr,"Error saving '%s'!\n",[filename cString]);
|
||||
|
|
Loading…
Reference in a new issue