Tweak AWGS/Teach output

Officially the \u value is signed 16-bit decimal, but we were treating
it as unsigned.  The Windows parsers handled it anyway, but it's best
to do what the spec says.
This commit is contained in:
Andy McFadden 2014-12-18 18:35:30 -08:00
parent 4dd0c9339d
commit e7512f5f07
3 changed files with 16 additions and 12 deletions

View File

@ -388,7 +388,7 @@ int ReformatAWGS_WP::PrintParagraph(const uint8_t* ptr, long maxLen)
RTFTab(); RTFTab();
break; break;
default: default:
RTFPrintExtChar(ConvertMacRomanToUTF16(uch)); RTFPrintUTF16Char(ConvertMacRomanToUTF16(uch));
break; break;
} }
} }

View File

@ -342,22 +342,25 @@ protected:
// (only use this if we're in RTF mode) // (only use this if we're in RTF mode)
inline void RTFPrintChar(uint8_t ch) { inline void RTFPrintChar(uint8_t ch) {
char pch = PrintableChar(ch); char pch = PrintableChar(ch);
RTFPrintExtChar(pch); RTFPrintUTF16Char(pch);
} }
// output an RTF-escaped char, allowing high ASCII // output an RTF-escaped char, allowing UTF-16 Unicode values
// (only use this if we're in RTF mode) // (only use this if we're in RTF mode)
inline void RTFPrintExtChar(uint16_t ch) { inline void RTFPrintUTF16Char(uint16_t ch) {
if (ch == '\\') if (ch == '\\') {
fExpBuf.Printf("\\\\"); fExpBuf.Printf("\\\\");
else if (ch == '{') } else if (ch == '{') {
fExpBuf.Printf("\\{"); fExpBuf.Printf("\\{");
else if (ch == '}') } else if (ch == '}') {
fExpBuf.Printf("\\}"); fExpBuf.Printf("\\}");
else if (ch < 256) { } else if (ch >= 0x20 && ch < 0x80) {
// TODO: should be \'xx for 0x80-ff? // don't use Unicode escapes for these, or the output will be
// unreadable by mere humans
fExpBuf.Printf("%c", ch); fExpBuf.Printf("%c", ch);
} else { } else {
fExpBuf.Printf("\\u%d?", ch); // must print as a *signed* 16-bit decimal value, though it
// looks like most parsers work either way
fExpBuf.Printf("\\u%d?", (int16_t)ch);
} }
} }
// output a char, doubling up double quotes (for .CSV) // output a char, doubling up double quotes (for .CSV)
@ -378,7 +381,8 @@ protected:
} }
// Convert a Mac OS Roman character value (from a IIgs document) to // Convert a Mac OS Roman character value (from a IIgs document) to
// its UTF-16 Unicode equivalent. // its UTF-16 Unicode equivalent. This also includes a conversion
// for the control characters.
uint16_t ConvertMacRomanToUTF16(uint8_t ch) { uint16_t ConvertMacRomanToUTF16(uint8_t ch) {
return kUTF16Conv[ch]; return kUTF16Conv[ch];
} }

View File

@ -206,7 +206,7 @@ int ReformatTeach::Process(const ReformatHolder* pHolder,
} else if (uch == '\t') { } else if (uch == '\t') {
RTFTab(); RTFTab();
} else { } else {
RTFPrintExtChar(ConvertMacRomanToUTF16(uch)); RTFPrintUTF16Char(ConvertMacRomanToUTF16(uch));
} }
dataBuf++; dataBuf++;
dataLen--; dataLen--;