Deprecating Zonble's on-write EOF fixer.
- Zonble thinks that his idea is superior than mine. However, his design, by putting an EOF fixer into the writeUserPhrase section, is totally meaningless: EOF fixer is for fixing manually-introduced EOF faults since automatically-inserted UserPhrase entries never generate EOF problems.
This commit is contained in:
parent
44748c2153
commit
ecee3ad7bf
|
@ -166,31 +166,9 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
|
|||
return NO;
|
||||
}
|
||||
|
||||
BOOL shouldAddLineBreakAtFront = NO;
|
||||
NSString *path = [self userPhrasesDataPath:inputMode];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
||||
NSError *error = nil;
|
||||
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
|
||||
unsigned long long fileSize = [attr fileSize];
|
||||
if (!error && fileSize) {
|
||||
NSFileHandle *readFile = [NSFileHandle fileHandleForReadingAtPath:path];
|
||||
if (readFile) {
|
||||
[readFile seekToFileOffset:fileSize - 1];
|
||||
NSData *data = [readFile readDataToEndOfFile];
|
||||
const void *bytes = [data bytes];
|
||||
if (*(char *)bytes != '\n') {
|
||||
shouldAddLineBreakAtFront = YES;
|
||||
}
|
||||
[readFile closeFile];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSMutableString *currentMarkedPhrase = [NSMutableString string];
|
||||
if (shouldAddLineBreakAtFront) {
|
||||
[currentMarkedPhrase appendString:@"\n"];
|
||||
}
|
||||
[currentMarkedPhrase appendString:userPhrase];
|
||||
[currentMarkedPhrase appendString:@"\n"];
|
||||
|
||||
|
|
Loading…
Reference in New Issue