Problem: 1613449

Title: (2-BYTE) Double Byte Characters

Received: Dec 16 1996 4:19PM


While attempting to work with two-byte scripts, I found an apparent problem in the global routine FindPos() in MA3.0.1. It doesn't check the correct character in its call to CharByte(). I think it should also compare the CharByte() value in both source and patter. I have used the following corrected code successfully:
// cloned from MacApp code, to fix bug in argument to CharByte()
short FindPos(const CStr255& pattern, CStr255& source)
{
   short i = 0;
   short j = 0;
   short position = 0;
 
   do
   {
   ++i;
   position = i;
   for (j = 1; j <= pattern.Length(); ++j)
   if (!((source[i + j - 1] == pattern[j]) &&
   (CharByte((Ptr) & source + 1, i + j - 2) ==
   CharByte((Ptr) & pattern + 1, j - 1))))
   {
   position = 0;
   break;
   }
   } while (!((position > 0) || (i >= source.Length() - pattern.Length() + 1)));
 
   return position;
}

Fix:

Fixed as recommended.