Problem: 1155949

Title: (2-BYTE) Double Byte Characters

Received: Apr 7 1994 3:20PM


Sub: FindPos() bug

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()
// cloned from MacApp code, to fix bug in argument to CharByte()
short FindPos(const CStr255& pattern, CStr255& source)
{
short i = 0;
short j = ;
		++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 but no details provided.