62 #define kNumberFormatString "\p########0.00#######;-########0.00#######"
69 void CopyPStrToCStr(
const unsigned char *thePStr,
char *theCStr,
const int maxCStrLength)
74 if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
76 numPChars = thePStr[0];
80 if (i >= numPChars || i >= maxCStrLength - 1)
89 theCStr[i] = thePStr[i + 1];
96 void CopyPStrToPStr(
const unsigned char *theSrcPStr,
unsigned char *theDstPStr,
const int maxDstStrLength)
98 int theMaxDstStrLength;
101 theMaxDstStrLength = maxDstStrLength;
104 if (theDstPStr != nil && theSrcPStr != nil && theMaxDstStrLength > 0)
106 if (theMaxDstStrLength > 255)
108 theMaxDstStrLength = 255;
112 if (theMaxDstStrLength - 1 < theSrcPStr[0])
114 BlockMove(theSrcPStr + 1,theDstPStr + 1,theMaxDstStrLength - 1);
116 theDstPStr[0] = theMaxDstStrLength - 1;
121 BlockMove(theSrcPStr,theDstPStr,theSrcPStr[0] + 1);
127 void CopyCStrToCStr(
const char *theSrcCStr,
char *theDstCStr,
const int maxDstStrLength)
132 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
136 if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1)
145 theDstCStr[i] = theSrcCStr[i];
153 void CopyCSubstrToCStr(
const char *theSrcCStr,
const int maxCharsToCopy,
char *theDstCStr,
const int maxDstStrLength)
158 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
162 if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1 || i >= maxCharsToCopy)
171 theDstCStr[i] = theSrcCStr[i];
179 void CopyCSubstrToPStr(
const char *theSrcCStr,
const int maxCharsToCopy,
unsigned char *theDstPStr,
const int maxDstStrLength)
182 int theMaxDstStrLength;
185 theMaxDstStrLength = maxDstStrLength;
187 if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
189 if (theMaxDstStrLength > 255)
191 theMaxDstStrLength = 255;
197 if (theSrcCStr[i] == 0 || i >= theMaxDstStrLength - 1 || i >= maxCharsToCopy)
206 theDstPStr[i + 1] = theSrcCStr[i];
214 void CopyCStrToPStr(
const char *theSrcCStr,
unsigned char *theDstPStr,
const int maxDstStrLength)
217 int theMaxDstStrLength;
220 theMaxDstStrLength = maxDstStrLength;
222 if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
224 if (theMaxDstStrLength > 255)
226 theMaxDstStrLength = 255;
232 if (i >= theMaxDstStrLength - 1 || theSrcCStr[i] == 0)
241 theDstPStr[i + 1] = theSrcCStr[i];
250 int i,numPChars,cStrLength;
253 if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
255 for (cStrLength = 0;theCStr[cStrLength] != 0;cStrLength++)
261 numPChars = thePStr[0];
266 if (i >= numPChars || cStrLength >= maxCStrLength - 1)
268 theCStr[cStrLength++] = 0;
275 theCStr[cStrLength++] = thePStr[i + 1];
283 void ConcatPStrToPStr(
const unsigned char *theSrcPStr,
unsigned char *theDstPStr,
const int maxDstStrLength)
285 int theMaxDstStrLength;
288 theMaxDstStrLength = maxDstStrLength;
290 if (theSrcPStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
292 if (theMaxDstStrLength > 255)
294 theMaxDstStrLength = 255;
298 if (theMaxDstStrLength - theDstPStr[0] - 1 < theSrcPStr[0])
300 BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theMaxDstStrLength - 1 - theDstPStr[0]);
302 theDstPStr[0] = theMaxDstStrLength - 1;
307 BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theSrcPStr[0]);
309 theDstPStr[0] += theSrcPStr[0];
316 void ConcatCStrToPStr(
const char *theSrcCStr,
unsigned char *theDstPStr,
const int maxDstStrLength)
319 int theMaxDstStrLength;
322 theMaxDstStrLength = maxDstStrLength;
324 if (theSrcCStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
326 if (theMaxDstStrLength > 255)
328 theMaxDstStrLength = 255;
332 thePStrLength = theDstPStr[0];
336 if (theSrcCStr[i] == 0 || thePStrLength >= theMaxDstStrLength - 1)
338 theDstPStr[0] = thePStrLength;
345 theDstPStr[thePStrLength + 1] = theSrcCStr[i];
360 if (theSrcCStr != nil && theDstCStr != nil && maxCStrLength > 0)
362 for (cStrLength = 0;theDstCStr[cStrLength] != 0;cStrLength++)
370 if (*theSrcCStr == 0 || cStrLength >= maxCStrLength - 1)
372 theDstCStr[cStrLength++] = 0;
379 theDstCStr[cStrLength++] = *theSrcCStr++;
392 if (theDstCStr != nil && maxCStrLength > 0)
396 if (cStrLength < maxCStrLength - 1)
398 theDstCStr[cStrLength++] = theChar;
399 theDstCStr[cStrLength++] =
'\0';
406 void ConcatCharToPStr(
const char theChar,
unsigned char *theDstPStr,
const int maxPStrLength)
411 if (theDstPStr != nil && maxPStrLength > 0)
415 if (pStrLength < maxPStrLength - 1 && pStrLength < 255)
417 theDstPStr[pStrLength + 1] = theChar;
426 int CompareCStrs(
const char *theFirstCStr,
const char *theSecondCStr,
const Boolean ignoreCase)
429 char firstChar,secondChar;
435 if (theFirstCStr != nil && theSecondCStr != nil)
439 firstChar = *theFirstCStr;
440 secondChar = *theSecondCStr;
442 if (ignoreCase ==
true)
444 if (firstChar >=
'A' && firstChar <=
'Z')
446 firstChar =
'a' + (firstChar -
'A');
449 if (secondChar >=
'A' && secondChar <=
'Z')
451 secondChar =
'a' + (secondChar -
'A');
456 if (firstChar == 0 && secondChar != 0)
463 else if (firstChar != 0 && secondChar == 0)
470 else if (firstChar == 0 && secondChar == 0)
477 else if (firstChar < secondChar)
484 else if (firstChar > secondChar)
502 Boolean
CStrsAreEqual(
const char *theFirstCStr,
const char *theSecondCStr,
const Boolean ignoreCase)
504 if (
CompareCStrs(theFirstCStr,theSecondCStr,ignoreCase) == 0)
516 Boolean
PStrsAreEqual(
const unsigned char *theFirstPStr,
const unsigned char *theSecondPStr,
const Boolean ignoreCase)
518 if (
ComparePStrs(theFirstPStr,theSecondPStr,ignoreCase) == 0)
531 int ComparePStrs(
const unsigned char *theFirstPStr,
const unsigned char *theSecondPStr,
const Boolean ignoreCase)
534 char firstChar,secondChar;
540 if (theFirstPStr != nil && theSecondPStr != nil)
544 firstChar = theFirstPStr[i];
545 secondChar = theSecondPStr[i];
547 if (ignoreCase ==
true)
549 if (firstChar >=
'A' && firstChar <=
'Z')
551 firstChar =
'a' + (firstChar -
'A');
554 if (secondChar >=
'A' && secondChar <=
'Z')
556 secondChar =
'a' + (secondChar -
'A');
561 if (theFirstPStr[0] < i && theSecondPStr[0] >= i)
568 else if (theFirstPStr[0] >= i && theSecondPStr[0] < i)
575 else if (theFirstPStr[0] < i && theSecondPStr[0] < i)
582 else if (firstChar < secondChar)
589 else if (firstChar > secondChar)
604 int CompareCStrToPStr(
const char *theCStr,
const unsigned char *thePStr,
const Boolean ignoreCase)
607 char tempString[256];
612 if (theCStr != nil && thePStr != nil)
616 returnValue =
CompareCStrs(theCStr,tempString,ignoreCase);
630 NumToString(theNum,theStr255);
638 charsToInsert = numDigits -
PStrLength(theStr255);
640 if (charsToInsert > 0)
642 char tempString[256];
646 for (;charsToInsert > 0;charsToInsert--)
664 void ConcatLongIntToPStr(
const long theNum,
unsigned char *thePStr,
const int maxPStrLength,
const int numDigits)
669 NumToString(theNum,theStr255);
677 charsToInsert = numDigits -
PStrLength(theStr255);
679 if (charsToInsert > 0)
681 char tempString[256];
685 for (;charsToInsert > 0;charsToInsert--)
711 void CopyLongIntToCStr(
const long theNum,
char *theCStr,
const int maxCStrLength,
const int numDigits)
716 NumToString(theNum,theStr255);
724 charsToInsert = numDigits -
PStrLength(theStr255);
726 if (charsToInsert > 0)
728 char tempString[256];
732 for (;charsToInsert > 0;charsToInsert--)
753 char tempString[256];
754 int srcCharIndex,dstCharIndex;
755 unsigned long tempNum,quotient,remainder;
771 if (srcCharIndex >=
sizeof(tempString) - 1 || tempNum == 0)
773 for (dstCharIndex = 0;;)
775 if (dstCharIndex >= maxCStrLength - 1 || srcCharIndex <= 0)
777 theCStr[dstCharIndex] = 0;
782 theCStr[dstCharIndex++] = tempString[--srcCharIndex];
789 quotient = tempNum / 10;
791 remainder = tempNum - (quotient * 10);
793 tempString[srcCharIndex] =
'0' + remainder;
805 void CopyLongIntToPStr(
const long theNum,
unsigned char *thePStr,
const int maxPStrLength,
const int numDigits)
807 char tempString[256];
819 OSErr errCode = noErr;
833 OSErr errCode = noErr;
849 OSErr errCode = noErr;
853 if (theCString == nil)
858 if (theHandle == nil)
863 if (*theHandle == nil)
872 SetHandleSize(theHandle,stringLength);
874 if (GetHandleSize(theHandle) < stringLength)
880 ::BlockMove(theCString,*theHandle,stringLength);
894 OSErr errCode = noErr;
898 if (theCString == nil)
903 if (theHandle == nil)
912 *theHandle = NewHandle(stringLength);
914 if (*theHandle == nil)
920 ::BlockMove(theCString,**theHandle,stringLength);
932 OSErr errCode = noErr;
936 if (thePString == nil)
941 if (theHandle == nil)
950 *theHandle = NewHandle(stringLength);
952 if (*theHandle == nil)
958 if (stringLength > 1)
960 BlockMove(thePString + 1,**theHandle,stringLength - 1);
963 (**theHandle)[stringLength - 1] = 0;
974 OSErr errCode = noErr;
975 char tempString[256];
990 OSErr
AppendCStrToHandle(
const char *theCString,Handle theHandle,
long *currentLength,
long *maxLength)
992 OSErr errCode = noErr;
993 long handleMaxLength,handleCurrentLength,stringLength,byteCount;
996 if (theCString == nil)
1001 if (theHandle == nil)
1007 if (maxLength != nil)
1009 handleMaxLength = *maxLength;
1014 handleMaxLength = GetHandleSize(theHandle);
1018 if (currentLength != nil && *currentLength >= 0)
1020 handleCurrentLength = *currentLength;
1025 handleCurrentLength =
CStrLength(*theHandle);
1031 byteCount = handleCurrentLength + stringLength + 1;
1033 if (byteCount > handleMaxLength)
1035 SetHandleSize(theHandle,handleCurrentLength + stringLength + 1);
1037 if (maxLength != nil)
1039 *maxLength = GetHandleSize(theHandle);
1041 handleMaxLength = *maxLength;
1046 handleMaxLength = GetHandleSize(theHandle);
1049 if (byteCount > handleMaxLength)
1056 BlockMove(theCString,*theHandle + handleCurrentLength,stringLength + 1);
1059 if (currentLength != nil)
1061 *currentLength += stringLength;
1075 OSErr
AppendCharsToHandle(
const char *theChars,
const int numChars,Handle theHandle,
long *currentLength,
long *maxLength)
1077 OSErr errCode = noErr;
1078 long handleMaxLength,handleCurrentLength,byteCount;
1081 if (theChars == nil)
1086 if (theHandle == nil)
1092 if (maxLength != nil)
1094 handleMaxLength = *maxLength;
1099 handleMaxLength = GetHandleSize(theHandle);
1103 if (currentLength != nil && *currentLength >= 0)
1105 handleCurrentLength = *currentLength;
1110 handleCurrentLength =
CStrLength(*theHandle);
1114 byteCount = handleCurrentLength + numChars + 1;
1116 if (byteCount > handleMaxLength)
1118 SetHandleSize(theHandle,handleCurrentLength + numChars + 1);
1120 if (maxLength != nil)
1122 *maxLength = GetHandleSize(theHandle);
1124 handleMaxLength = *maxLength;
1129 handleMaxLength = GetHandleSize(theHandle);
1132 if (byteCount > handleMaxLength)
1139 BlockMove(theChars,*theHandle + handleCurrentLength,numChars);
1141 (*theHandle)[handleCurrentLength + numChars] =
'\0';
1143 if (currentLength != nil)
1145 *currentLength += numChars;
1161 OSErr errCode = noErr;
1162 char tempString[32];
1177 long cStrLength = 0;
1180 if (theCString != nil)
1182 for (cStrLength = 0;theCString[cStrLength] != 0;cStrLength++)
1196 long pStrLength = 0;
1199 if (thePString != nil)
1201 pStrLength = thePString[0];
1212 void ZeroMem(
void *theMemPtr,
const unsigned long numBytes)
1214 unsigned char *theBytePtr;
1215 unsigned long *theLongPtr;
1216 unsigned long numSingleBytes;
1217 unsigned long theNumBytes;
1220 theNumBytes = numBytes;
1222 if (theMemPtr != nil && theNumBytes > 0)
1224 theBytePtr = (
unsigned char *) theMemPtr;
1226 numSingleBytes = (
unsigned long) theBytePtr & 0x0003;
1228 while (numSingleBytes > 0)
1237 theLongPtr = (
unsigned long *) theBytePtr;
1239 while (theNumBytes >= 4)
1247 theBytePtr = (
unsigned char *) theLongPtr;
1249 while (theNumBytes > 0)
1263 char *theStringSearchPtr;
1266 theStringSearchPtr = (
char *) theCString;
1268 if (theStringSearchPtr != nil)
1270 while (*theStringSearchPtr !=
'\0' && *theStringSearchPtr != theChar)
1272 theStringSearchPtr++;
1275 if (*theStringSearchPtr ==
'\0')
1277 theStringSearchPtr = nil;
1281 return(theStringSearchPtr);
1288 long theOffset = -1;
1291 if (theCString != nil)
1298 char searchChar = theChar;
1300 if (searchChar >=
'a' && searchChar <=
'z')
1302 searchChar = searchChar -
'a' +
'A';
1306 while (*theCString != 0)
1308 char currentChar = *theCString;
1310 if (currentChar >=
'a' && currentChar <=
'z')
1312 currentChar = currentChar -
'a' +
'A';
1315 if (currentChar == searchChar)
1327 while (*theCString != 0 && *theCString != theChar)
1334 if (*theCString == 0)
1346 long theOffset = -1;
1349 if (theCSubstring != nil && theCString != nil)
1351 for (theOffset = 0;;theOffset++)
1353 if (theCString[theOffset] == 0)
1361 for (
const char *tempSubstringPtr = theCSubstring,*tempCStringPtr = theCString + theOffset;;tempSubstringPtr++,tempCStringPtr++)
1363 if (*tempSubstringPtr == 0)
1368 else if (*tempCStringPtr == 0)
1373 char searchChar = *tempSubstringPtr;
1374 char currentChar = *tempCStringPtr;
1376 if (inIgnoreCase && searchChar >=
'a' && searchChar <=
'z')
1378 searchChar = searchChar -
'a' +
'A';
1381 if (inIgnoreCase && currentChar >=
'a' && currentChar <=
'z')
1383 currentChar = currentChar -
'a' +
'A';
1386 if (currentChar != searchChar)
1404 void InsertCStrIntoCStr(
const char *theSrcCStr,
const int theInsertionOffset,
char *theDstCStr,
const int maxDstStrLength)
1408 int numCharsToInsert;
1409 int numCharsToShift;
1412 if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
1419 if (theInsertionOffset + insertLength < maxDstStrLength - 1)
1421 numCharsToInsert = insertLength;
1426 numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
1430 if (numCharsToInsert + currentLength < maxDstStrLength - 1)
1432 numCharsToShift = currentLength - theInsertionOffset;
1437 numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
1441 if (numCharsToShift > 0)
1443 BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
1446 if (numCharsToInsert > 0)
1448 BlockMove(theSrcCStr,theDstCStr + theInsertionOffset,numCharsToInsert);
1451 theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
1457 void InsertPStrIntoCStr(
const unsigned char *theSrcPStr,
const int theInsertionOffset,
char *theDstCStr,
const int maxDstStrLength)
1461 int numCharsToInsert;
1462 int numCharsToShift;
1465 if (theDstCStr != nil && theSrcPStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
1472 if (theInsertionOffset + insertLength < maxDstStrLength - 1)
1474 numCharsToInsert = insertLength;
1479 numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
1483 if (numCharsToInsert + currentLength < maxDstStrLength - 1)
1485 numCharsToShift = currentLength - theInsertionOffset;
1490 numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
1494 if (numCharsToShift > 0)
1496 BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
1499 if (numCharsToInsert > 0)
1501 BlockMove(theSrcPStr + 1,theDstCStr + theInsertionOffset,numCharsToInsert);
1504 theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
1523 if (currentLength + 1 > ::GetHandleSize(theHandle))
1528 if (inInsertOffset > currentLength)
1535 ::SetHandleSize(theHandle,currentLength + 1 + insertLength);
1537 if (::GetHandleSize(theHandle) < currentLength + 1 + insertLength)
1542 ::BlockMove(*theHandle + inInsertOffset,*theHandle + inInsertOffset + insertLength,currentLength - inInsertOffset + 1);
1544 ::BlockMove(theCString,*theHandle + inInsertOffset,insertLength);
1566 const long theLongInts[] = { long1,long2 };
1574 const long theLongInts[] = { long1,long2,long3 };
1582 const char *theCStrs[2] = { theInsertCStr,nil };
1591 const char *theCStrs[2] = { theInsertCStr,nil };
1592 const long theLongInts[1] = { theNum };
1601 int dstCharIndex,srcCharIndex,theMaxDstStrLength;
1602 int theCStrIndex = 0;
1603 int theLongIntIndex = 0;
1606 theMaxDstStrLength = maxDstStrLength;
1608 if (theDstCStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
1617 theMaxDstStrLength--;
1624 if (dstCharIndex >= theMaxDstStrLength)
1626 theDstCStr[dstCharIndex++] = 0;
1633 else if (theSrcCStr[srcCharIndex] == 0)
1635 theDstCStr[dstCharIndex++] = 0;
1642 else if (theInsertCStrs != nil && theInsertCStrs[theCStrIndex] != nil && theSrcCStr[srcCharIndex] ==
'%' && theSrcCStr[srcCharIndex + 1] ==
's')
1651 theDstCStr[dstCharIndex] = 0;
1653 ConcatCStrToCStr(theInsertCStrs[theCStrIndex],theDstCStr,theMaxDstStrLength);
1662 else if (theLongInts != nil && theSrcCStr[srcCharIndex] ==
'%' && theSrcCStr[srcCharIndex + 1] ==
'l' && theSrcCStr[srcCharIndex + 2] ==
'd')
1671 theDstCStr[dstCharIndex] = 0;
1682 theDstCStr[dstCharIndex++] = theSrcCStr[srcCharIndex++];
1704 if (theHandle != nil)
1708 *theHandle = NewHandle(byteCount);
1710 if (*theHandle == nil)
1720 HUnlock(*theHandle);
1738 char *srcCharPtr,*dstCharPtr;
1743 if (theSrcCStr == nil)
1748 if (theDstCStr == nil)
1758 if (maxDstCStrLength <= 0)
1766 srcCharPtr = theSrcCStr;
1768 while (*srcCharPtr ==
' ' || *srcCharPtr ==
'\t')
1774 for (wordCount = 0;wordCount < whichWord;wordCount++)
1776 while (*srcCharPtr !=
' ' && *srcCharPtr !=
'\t' && *srcCharPtr !=
'\r' && *srcCharPtr !=
'\n' && *srcCharPtr !=
'\0')
1781 if (*srcCharPtr ==
'\r' || *srcCharPtr ==
'\n' || *srcCharPtr ==
'\0')
1788 while (*srcCharPtr ==
' ' || *srcCharPtr ==
'\t')
1793 if (*srcCharPtr ==
'\r' || *srcCharPtr ==
'\n' || *srcCharPtr ==
'\0')
1802 dstCharPtr = theDstCStr;
1808 if (byteCount >= maxDstCStrLength - 1 || *srcCharPtr ==
'\0' || *srcCharPtr ==
' ' || *srcCharPtr ==
'\t' || *srcCharPtr ==
'\r' || *srcCharPtr ==
'\n')
1814 *dstCharPtr++ = *srcCharPtr++;
1840 if (theSrcCStr == nil)
1845 if (outTheHandle == nil)
1856 *outTheHandle = nil;
1859 srcCharPtr = theSrcCStr;
1861 while (*srcCharPtr ==
' ' || *srcCharPtr ==
'\t')
1867 for (wordCount = 0;wordCount < whichWord;wordCount++)
1869 while (*srcCharPtr !=
' ' && *srcCharPtr !=
'\t' && *srcCharPtr !=
'\r' && *srcCharPtr !=
'\n' && *srcCharPtr !=
'\0')
1874 if (*srcCharPtr ==
'\r' || *srcCharPtr ==
'\n' || *srcCharPtr ==
'\0')
1879 while (*srcCharPtr ==
' ' || *srcCharPtr ==
'\t')
1884 if (*srcCharPtr ==
'\r' || *srcCharPtr ==
'\n' || *srcCharPtr ==
'\0')
1891 for (byteCount = 0;;byteCount++)
1893 if (srcCharPtr[byteCount] ==
' ' || srcCharPtr[byteCount] ==
'\t' || srcCharPtr[byteCount] ==
'\r' || srcCharPtr[byteCount] ==
'\n' || srcCharPtr[byteCount] ==
'\0')
1900 *outTheHandle = NewHandle(byteCount + 1);
1902 if (*outTheHandle == nil)
1908 ::BlockMove(srcCharPtr,**outTheHandle,byteCount);
1910 (**outTheHandle)[byteCount] =
'\0';
1922 OSErr
CopyIndexedLineToCStr(
const char *theSrcCStr,
int inWhichLine,
int *lineEndIndex,Boolean *gotLastLine,
char *theDstCStr,
const int maxDstCStrLength)
1926 int theCurrentLineOffset;
1930 if (theSrcCStr == nil)
1935 if (theDstCStr == nil)
1940 if (inWhichLine < 0)
1945 if (maxDstCStrLength <= 0)
1951 if (gotLastLine != nil)
1953 *gotLastLine =
false;
1959 theCurrentLineOffset = 0;
1964 while (theCurrentLine < inWhichLine)
1966 while (theSrcCStr[theCurrentLineOffset] !=
'\r' && theSrcCStr[theCurrentLineOffset] != 0)
1968 theCurrentLineOffset++;
1971 if (theSrcCStr[theCurrentLineOffset] == 0)
1976 theCurrentLineOffset++;
1980 if (theSrcCStr[theCurrentLineOffset] == 0)
1988 if (theEOSOffset >= 0)
1990 CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
1992 if (gotLastLine != nil)
1994 *gotLastLine =
false;
1997 if (lineEndIndex != nil)
1999 *lineEndIndex = theEOSOffset;
2005 theEOSOffset =
CStrLength(theSrcCStr + theCurrentLineOffset);
2007 CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
2009 if (gotLastLine != nil)
2011 *gotLastLine =
true;
2014 if (lineEndIndex != nil)
2016 *lineEndIndex = theEOSOffset;
2035 int theCurrentLineOffset;
2042 if (inWhichLine < 0)
2048 theCurrentLineOffset = 0;
2053 while (theCurrentLine < inWhichLine)
2055 while (theSrcCStr[theCurrentLineOffset] !=
'\r' && theSrcCStr[theCurrentLineOffset] !=
'\0')
2057 theCurrentLineOffset++;
2060 if (theSrcCStr[theCurrentLineOffset] ==
'\0')
2065 theCurrentLineOffset++;
2069 if (theSrcCStr[theCurrentLineOffset] ==
'\0')
2077 while (theSrcCStr[theCurrentLineOffset + byteCount] !=
'\r' && theSrcCStr[theCurrentLineOffset + byteCount] !=
'\0')
2083 *outNewHandle = NewHandle(byteCount + 1);
2085 if (*outNewHandle == nil)
2090 ::BlockMove(theSrcCStr + theCurrentLineOffset,**outNewHandle,byteCount);
2092 (**outNewHandle)[byteCount] =
'\0';
2105 OSErr
CountDigits(
const char *inCStr,
int *outNumIntegerDigits,
int *outNumFractDigits)
2107 OSErr errCode = noErr;
2108 int numIntDigits = 0;
2109 int numFractDigits = 0;
2119 while (inCStr[digitIndex] >=
'0' && inCStr[digitIndex] <=
'9')
2125 if (inCStr[digitIndex] ==
'.')
2129 while (inCStr[digitIndex] >=
'0' && inCStr[digitIndex] <=
'9')
2136 *outNumIntegerDigits = numIntDigits;
2138 *outNumFractDigits = numFractDigits;
2155 if (theSrcCStr == nil)
2170 if (skipLeadingSpaces ==
true)
2172 while (theSrcCStr[theCharIndex] ==
' ')
2178 if (theSrcCStr[theCharIndex] <
'0' || theSrcCStr[theCharIndex] >
'9')
2180 SetErrorMessageAndBail((
"ExtractIntFromCStr: Bad parameter, theSrcCStr contains a bogus numeric representation"));
2184 while (theSrcCStr[theCharIndex] >=
'0' && theSrcCStr[theCharIndex] <=
'9')
2186 *outInt = (*outInt * 10) + (theSrcCStr[theCharIndex] -
'0');
2208 if (theSrcPStr == nil)
2234 int theSrcCharIndex;
2235 int numOccurrences = -1;
2238 if (inSrcCStr != nil && inChar !=
'\0')
2242 for (theSrcCharIndex = 0;inSrcCStr[theSrcCharIndex] !=
'\0';theSrcCharIndex++)
2244 if (inSrcCStr[theSrcCharIndex] == inChar)
2251 return(numOccurrences);
2260 if (inSrcCStr != nil)
2266 while (*inSrcCStr ==
' ')
2271 while (*inSrcCStr !=
'\0')
2275 while (*inSrcCStr !=
' ' && *inSrcCStr !=
'\0')
2280 while (*inSrcCStr ==
' ')
2298 if (theSrcCStr != nil)
2300 theCharPtr = theSrcCStr;
2302 while (*theCharPtr != 0)
2304 if (*theCharPtr >=
'a' && *theCharPtr <=
'z')
2306 *theCharPtr = *theCharPtr -
'a' +
'A';
2320 void ExtractCStrItemFromCStr(
const char *inSrcCStr,
const char inItemDelimiter,
const int inItemNumber,Boolean *foundItem,
char *outDstCharPtr,
const int inDstCharPtrMaxLength,
const Boolean inTreatMultipleDelimsAsSingleDelim)
2323 int theSrcCharIndex;
2324 int theDstCharIndex;
2327 if (foundItem != nil)
2333 if (outDstCharPtr != nil && inDstCharPtrMaxLength > 0 && inItemNumber >= 0 && inItemDelimiter != 0)
2338 theSrcCharIndex = 0;
2340 for (theItem = 0;theItem < inItemNumber;theItem++)
2342 while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] !=
'\0')
2347 if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2351 if (inTreatMultipleDelimsAsSingleDelim)
2353 while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2361 if (inSrcCStr[theSrcCharIndex] ==
'\0')
2368 if (foundItem != nil)
2374 theDstCharIndex = 0;
2378 if (inSrcCStr[theSrcCharIndex] == 0 || inSrcCStr[theSrcCharIndex] == inItemDelimiter || theDstCharIndex >= inDstCharPtrMaxLength - 1)
2380 outDstCharPtr[theDstCharIndex] = 0;
2385 outDstCharPtr[theDstCharIndex++] = inSrcCStr[theSrcCharIndex++];
2397 OSErr
ExtractCStrItemFromCStrIntoNewHandle(
const char *inSrcCStr,
const char inItemDelimiter,
const int inItemNumber,Boolean *foundItem,Handle *outNewHandle,
const Boolean inTreatMultipleDelimsAsSingleDelim)
2401 int theSrcCharIndex;
2405 if (inSrcCStr == nil)
2407 SetErrorMessage(
"ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inSrcCStr == nil");
2412 if (outNewHandle == nil)
2414 SetErrorMessage(
"ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, outNewHandle == nil");
2419 if (foundItem == nil)
2421 SetErrorMessage(
"ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, foundItem == nil");
2426 if (inItemNumber < 0)
2428 SetErrorMessage(
"ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemNumber < 0");
2433 if (inItemDelimiter == 0)
2435 SetErrorMessage(
"ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemDelimiter == 0");
2443 theSrcCharIndex = 0;
2445 for (theItem = 0;theItem < inItemNumber;theItem++)
2447 while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] !=
'\0')
2452 if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2456 if (inTreatMultipleDelimsAsSingleDelim)
2458 while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
2466 if (inSrcCStr[theSrcCharIndex] ==
'\0')
2478 for (theItemLength = 0;;theItemLength++)
2480 if (inSrcCStr[theSrcCharIndex + theItemLength] == 0 || inSrcCStr[theSrcCharIndex + theItemLength] == inItemDelimiter)
2487 *outNewHandle = NewHandle(theItemLength + 1);
2489 if (*outNewHandle == nil)
2495 BlockMove(inSrcCStr + theSrcCharIndex,**outNewHandle,theItemLength);
2497 (**outNewHandle)[theItemLength] = 0;
2516 Handle theNumberPartsTableHandle = nil;
2517 long theNumberPartsOffset,theNumberPartsLength;
2518 FormatResultType theFormatResultType;
2519 NumberParts theNumberPartsTable;
2520 NumFormatStringRec theNumFormatStringRec;
2523 if (inCString == nil)
2525 SetErrorMessage(
"ExtractFloatFromCStr: Bad parameter, inCString == nil");
2530 if (outFloat == nil)
2532 SetErrorMessage(
"ExtractFloatFromCStr: Bad parameter, outFloat == nil");
2540 GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2542 if (theNumberPartsTableHandle == nil)
2544 SetErrorMessage(
"ExtractFloatFromCStr: Can't get number parts table for converting string representations to/from numeric representations");
2549 if (theNumberPartsLength >
sizeof(theNumberPartsTable))
2551 SetErrorMessage(
"ExtractFloatFromCStr: Number parts table has bad length");
2557 BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
2560 theFormatResultType = (FormatResultType) StringToFormatRec(
kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
2562 if (theFormatResultType != fFormatOK)
2564 SetErrorMessage(
"ExtractFloatFromCStr: StringToFormatRec() != fFormatOK");
2573 theFormatResultType = (FormatResultType) StringToExtended(theStr255,&theNumFormatStringRec,&theNumberPartsTable,outFloat);
2575 if (theFormatResultType != fFormatOK && theFormatResultType != fBestGuess)
2591 OSErr
CopyFloatToCStr(
const extended80 *theFloat,
char *theCStr,
const int maxCStrLength,
const int inMaxNumIntDigits,
const int inMaxNumFractDigits)
2595 Handle theNumberPartsTableHandle = nil;
2596 long theNumberPartsOffset,theNumberPartsLength;
2597 FormatResultType theFormatResultType;
2598 NumberParts theNumberPartsTable;
2599 NumFormatStringRec theNumFormatStringRec;
2609 if (theFloat == nil)
2619 GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
2621 if (theNumberPartsTableHandle == nil)
2623 SetErrorMessage(
"CopyFloatToCStr: Can't get number parts table for converting string representations to/from numeric representations");
2628 if (theNumberPartsLength >
sizeof(theNumberPartsTable))
2630 SetErrorMessage(
"CopyFloatToCStr: Number parts table has bad length");
2636 BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
2639 if (inMaxNumIntDigits >= 0 || inMaxNumFractDigits >= 0)
2641 char numberFormat[64];
2642 int numberFormatLength = 0;
2644 for (
int i = 0;i < inMaxNumIntDigits && numberFormatLength <
sizeof(numberFormat) - 1;i++)
2646 numberFormat[numberFormatLength++] =
'0';
2649 if (inMaxNumFractDigits > 0 && numberFormatLength <
sizeof(numberFormat) - 1)
2651 numberFormat[numberFormatLength++] =
'.';
2653 for (
int i = 0;i < inMaxNumFractDigits && numberFormatLength <
sizeof(numberFormat) - 1;i++)
2655 numberFormat[numberFormatLength++] =
'0';
2660 if (numberFormatLength <
sizeof(numberFormat) - 1)
2662 numberFormat[numberFormatLength++] =
';';
2665 if (numberFormatLength <
sizeof(numberFormat) - 1)
2667 numberFormat[numberFormatLength++] =
'-';
2671 for (
int i = 0;i < inMaxNumIntDigits && numberFormatLength <
sizeof(numberFormat) - 1;i++)
2673 numberFormat[numberFormatLength++] =
'0';
2676 if (inMaxNumFractDigits > 0 && numberFormatLength <
sizeof(numberFormat) - 1)
2678 numberFormat[numberFormatLength++] =
'.';
2680 for (
int i = 0;i < inMaxNumFractDigits && numberFormatLength <
sizeof(numberFormat) - 1;i++)
2682 numberFormat[numberFormatLength++] =
'0';
2686 numberFormat[numberFormatLength] =
'\0';
2693 theFormatResultType = (FormatResultType) StringToFormatRec(tempStr255,&theNumberPartsTable,&theNumFormatStringRec);
2698 theFormatResultType = (FormatResultType) StringToFormatRec(
kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
2701 if (theFormatResultType != fFormatOK)
2709 theFormatResultType = (FormatResultType) ExtendedToString(theFloat,&theNumFormatStringRec,&theNumberPartsTable,theStr255);
2711 if (theFormatResultType != fFormatOK)
2735 if (ioSrcCharPtr != nil && *ioSrcCharPtr != nil)
2739 while ((**ioSrcCharPtr ==
' ' || **ioSrcCharPtr ==
'\t') && **ioSrcCharPtr !=
'\r' && **ioSrcCharPtr !=
'\n')
2747 while (**ioSrcCharPtr ==
' ' || **ioSrcCharPtr ==
'\t')