/* Copyright (c) 2017, Computer History Museum All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Computer History Museum nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /********************************************************************** * String utilities **********************************************************************/ #ifndef STRINGUTIL_H #define STRINGUTIL_H #define MakePPtr(pstr,ptr,len) do{*pstr=MIN(len,sizeof(Str255)-1);BMD(ptr,pstr+1,(Byte)*pstr);}while(false) #define CtoPPtrCpy(p,c) do{short l=strlen(c);MakePPtr(p,c,l);}while(0) #define StringToNum(a,b) MyStringToNum(a,b) void MyStringToNum(PStr string,long *num); Boolean AllDigits(UPtr chars, long len); Boolean BeginsWith(PStr string,PStr prefix); void CaptureHex(PStr from,PStr to); void CaptureHexPtr(Ptr from,Ptr to,long *pLen); UPtr ComposeRString(UPtr into,short format,...); UPtr ComposeString(UPtr into,UPtr format,...); #define CtoPCpy(p,c) do{short l=strlen(c);MakePStr(p,c,l);}while(0) Boolean HandleEndsWithR(Handle name,short resId); Boolean EndsWith(PStr name,PStr suffix); Boolean EndsWithR(PStr name,short resId); Boolean EqualStrRes(PStr string, short resId); Boolean StartsWithR(PStr name,short resId); Boolean StartsWith(PStr name,PStr prefix); Boolean StartsWithPtr(UPtr name,uLong len,PStr prefix); OSErr AccuComposeR(AccuPtr a,short format,...); OSErr AccuCompose(AccuPtr a,PStr format,...); long HighBits(UPtr s,long len); #define MixedHighBits(s,len) ((M_T1 = HighBits(s,len)),M_T1 && M_T10) #define AllHighBits(s,len) (HighBits(s,len)==len) void MyLowerText(UPtr buffer,long bufferSize); void MyUpperText(UPtr buffer,long bufferSize); #define MyLowerStr(s) MyLowerText((s)+1,*(s)) #define MyUpperStr(s) MyUpperText((s)+1,*(s)) #define BMD BlockMoveData #undef isupper #undef tolower #undef islower #undef toupper #undef isdigit #define isupper(c) ('A'<=(c) && (c)<='Z') #define tolower(c) ((c)+('a'-'A')) #define islower(c) ('a'<=(c) && (c)<='z') #define toupper(c) ((c)-('a'-'A')) #define isdigit(c) ('0'<=(c) && (c)<='9') #define IsWordOrDigit(c) (IsWordChar[c] || isdigit(c)) Boolean IsAllUpper(PStr s); PStr EscapeChars(PStr string, PStr toEscape); void EscapeInHex(PStr from,PStr to); void FixNewlines(UPtr string,long *count); PStr LCD(PStr s1,PStr s2); #define MakePStr(pasc,ptr,l) do{*pasc=MIN(l,sizeof(pasc)-2);BlockMoveData(ptr,pasc+1,*pasc);pasc[*pasc+1]=0;}while(0) UPtr PCat(PStr string,PStr suffix); #define PCatC(string,c) do { if (*(string)<255) (string)[++(string)[0]] = c ; else (string)[255]='É';} while(0) #define PSCatC(string,c) do{if (*(string)