Character encoding fixups

This commit is contained in:
elasota
2020-10-14 18:18:57 -04:00
parent 7858aff6cd
commit b682004f29
5 changed files with 118 additions and 116 deletions

View File

@@ -14,13 +14,13 @@
//============================================================== Functions
//-------------------------------------------------------------- PasStringCopy
// Given a source string and storage for a second, this function<EFBFBD>
// Given a source string and storage for a second, this function?
// copies from one to the other. It assumes Pascal style strings.
void PasStringCopy (StringPtr p1, StringPtr p2)
{
register short stringLength;
short stringLength;
stringLength = *p2++ = *p1++;
while (--stringLength >= 0)
*p2++ = *p1++;
@@ -28,9 +28,9 @@ void PasStringCopy (StringPtr p1, StringPtr p2)
//-------------------------------------------------------------- WhichStringFirst
// This is a sorting function that handles two Pascal strings. It<EFBFBD>
// will return a 1 to indicate the 1st string is "greater", a 1 to<EFBFBD>
// indicate the 2nd was greater and a 0 to indicate that the strings<EFBFBD>
// This is a sorting function that handles two Pascal strings. It?
// will return a 1 to indicate the 1st string is "greater", a 1 to?
// indicate the 2nd was greater and a 0 to indicate that the strings?
// are equal.
short WhichStringFirst (StringPtr p1, StringPtr p2)
@@ -38,11 +38,11 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
short smallestLength, seek, greater;
char char1, char2;
Boolean foundIt;
smallestLength = p1[0];
if (p2[0] < smallestLength)
smallestLength = p2[0];
greater = 0; // neither are greater, they are equal
seek = 1; // start at character #1
foundIt = false;
@@ -54,7 +54,7 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
char2 = p2[seek]; // make upper case (if applicable)
if ((char2 > 0x60) && (char2 < 0x7B))
char2 -= 0x20;
if (char1 > char2) // first string is greater
{
greater = 1;
@@ -79,69 +79,69 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
}
}
while (!foundIt);
return (greater);
}
//-------------------------------------------------------------- PasStringCopyNum
// This function copies a specified number of characters from one<EFBFBD>
// This function copies a specified number of characters from one?
// Pascal string to another.
void PasStringCopyNum (StringPtr p1, StringPtr p2, short charsToCopy)
{
short i;
if (charsToCopy > *p1) // if trying to copy more chars than there are
charsToCopy = *p1; // reduce the number of chars to copy to this size
*p2 = static_cast<unsigned char>(charsToCopy);
*p2++;
*p1++;
p2++;
p1++;
for (i = 0; i < charsToCopy; i++)
*p2++ = *p1++;
}
//-------------------------------------------------------------- PasStringConcat
// This function concatenates the second Pascal string to the end of<EFBFBD>
// This function concatenates the second Pascal string to the end of?
// the first Pascal string.
void PasStringConcat (StringPtr p1, const PLPasStr &p2)
{
short wasLength, addedLength;
wasLength = *p1;
if (wasLength > 255)
wasLength = 255;
addedLength = p2.Length();
if ((wasLength + addedLength) > 255)
addedLength = 255 - wasLength;
*p1 = wasLength + addedLength;
p1 += (1 + wasLength);
memcpy(p1, p2.Chars(), addedLength);
}
//-------------------------------------------------------------- GetLineOfText
// This function walks through a source string and looks for an<EFBFBD>
// entire line of text. A "line" of text is assumed to be bounded<EFBFBD>
// by carriage returns. The index variable indicates which line<EFBFBD>
// This function walks through a source string and looks for an?
// entire line of text. A "line" of text is assumed to be bounded?
// by carriage returns. The index variable indicates which line?
// is sought.
void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
{
short i, srcLength, count, start, stop;
Boolean foundIt;
PasStringCopy(PSTR(""), textLine);
srcLength = srcStr[0];
if (index == 0) // walk through to "index"
start = 1;
else
@@ -165,11 +165,11 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
}
while ((i < srcLength) && (!foundIt));
}
if (start != 0)
{
i = start;
foundIt = false;
do
{
@@ -181,7 +181,7 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
i++;
}
while ((i < srcLength) && (!foundIt));
if (!foundIt)
{
if (start > srcLength)
@@ -192,9 +192,9 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
else
stop = i;
}
count = 0;
for (i = start; i <= stop; i++)
{
count++;
@@ -206,18 +206,18 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
//-------------------------------------------------------------- WrapText
// Given a string and the maximum number of characters to put on<EFBFBD>
// one line, this function goes through and inserts carriage returns<EFBFBD>
// Given a string and the maximum number of characters to put on?
// one line, this function goes through and inserts carriage returns?
// in order to ensure that no line of text exceeds maxChars.
void WrapText (StringPtr theText, short maxChars)
{
short lastChar, count, chars, spaceIs;
Boolean foundEdge, foundSpace;
lastChar = theText[0];
count = 0;
do
{
chars = 0;
@@ -236,7 +236,7 @@ void WrapText (StringPtr theText, short maxChars)
}
}
while ((count < lastChar) && (chars < maxChars) && (!foundEdge));
if ((!foundEdge) && (count < lastChar) && (foundSpace))
{
theText[spaceIs] = '\r';
@@ -253,16 +253,16 @@ void WrapText (StringPtr theText, short maxChars)
void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut)
{
short isLong, spaceAt, i;
isLong = stringIn[0];
spaceAt = isLong;
for (i = 1; i < isLong; i++)
{
if ((stringIn[i] == ' ') && (spaceAt == isLong))
spaceAt = i - 1;
}
if (spaceAt <= 0)
PasStringCopy(PSTR(""), stringOut);
else
@@ -271,24 +271,24 @@ void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut)
//-------------------------------------------------------------- CollapseStringToWidth
// Given a string and a maximum width (in pixels), this function<EFBFBD>
// calculates how wide the text would be drawn with the current<EFBFBD>
// font. If the text would exceed our width limit, characters<EFBFBD>
// are dropped off the end of the string and "<EFBFBD>" appended.
// Given a string and a maximum width (in pixels), this function?
// calculates how wide the text would be drawn with the current?
// font. If the text would exceed our width limit, characters?
// are dropped off the end of the string and "?" appended.
void CollapseStringToWidth (PortabilityLayer::RenderedFont *font, StringPtr theStr, short wide)
{
short dotsWide;
Boolean tooWide;
dotsWide = font->MeasurePStr(PSTR("<EFBFBD>"));
dotsWide = font->MeasurePStr(PSTR("\xc9"));
tooWide = font->MeasurePStr(theStr) > wide;
while (tooWide && theStr[0] > 0)
{
theStr[0]--;
tooWide = ((font->MeasurePStr(theStr) + dotsWide) > wide);
if (!tooWide)
PasStringConcat(theStr, PSTR("<EFBFBD>"));
PasStringConcat(theStr, PSTR("\xc9"));
}
}
@@ -297,7 +297,7 @@ void CollapseStringToWidth (PortabilityLayer::RenderedFont *font, StringPtr theS
StringPtr GetLocalizedString (short index, StringPtr theString)
{
#define kLocalizedStringsID 150
GetIndString(theString, kLocalizedStringsID, index);
return (theString);
}