⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpstringutils.cpp

📁 开源的ssl算法openssl,版本0.9.8H
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				}								if (inIgnoreCase && currentChar >= 'a' && currentChar <= 'z')				{					currentChar = currentChar - 'a' + 'A';				}								if (currentChar != searchChar)				{					break;				}			}		}				theOffset = -1;	}EXITPOINT:		return(theOffset);}void InsertCStrIntoCStr(const char *theSrcCStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength){int		currentLength;int		insertLength;int		numCharsToInsert;int		numCharsToShift;		if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)	{		currentLength = CStrLength(theDstCStr);				insertLength = CStrLength(theSrcCStr);				if (theInsertionOffset + insertLength < maxDstStrLength - 1)		{			numCharsToInsert = insertLength;		}				else		{			numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;		}				if (numCharsToInsert + currentLength < maxDstStrLength - 1)		{			numCharsToShift = currentLength - theInsertionOffset;		}				else		{			numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;		}				if (numCharsToShift > 0)		{			BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);		}				if (numCharsToInsert > 0)		{			BlockMove(theSrcCStr,theDstCStr + theInsertionOffset,numCharsToInsert);		}				theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;	}}void InsertPStrIntoCStr(const unsigned char *theSrcPStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength){int		currentLength;int		insertLength;int		numCharsToInsert;int		numCharsToShift;		if (theDstCStr != nil && theSrcPStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)	{		currentLength = CStrLength(theDstCStr);				insertLength = PStrLength(theSrcPStr);				if (theInsertionOffset + insertLength < maxDstStrLength - 1)		{			numCharsToInsert = insertLength;		}				else		{			numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;		}				if (numCharsToInsert + currentLength < maxDstStrLength - 1)		{			numCharsToShift = currentLength - theInsertionOffset;		}				else		{			numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;		}				if (numCharsToShift > 0)		{			BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);		}				if (numCharsToInsert > 0)		{			BlockMove(theSrcPStr + 1,theDstCStr + theInsertionOffset,numCharsToInsert);		}				theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;	}}OSErr InsertCStrIntoHandle(const char *theCString,Handle theHandle,const long inInsertOffset){OSErr	errCode;int		currentLength;int		insertLength;		SetErrorMessageAndBailIfNil(theCString,"InsertCStrIntoHandle: Bad parameter, theCString == nil");	SetErrorMessageAndBailIfNil(theHandle,"InsertCStrIntoHandle: Bad parameter, theHandle == nil");		currentLength = CStrLength(*theHandle);		if (currentLength + 1 > ::GetHandleSize(theHandle))	{		SetErrorMessageAndBail("InsertCStrIntoHandle: Handle has been overflowed");	}		if (inInsertOffset > currentLength)	{		SetErrorMessageAndBail("InsertCStrIntoHandle: Insertion offset is greater than string length");	}		insertLength = CStrLength(theCString);		::SetHandleSize(theHandle,currentLength + 1 + insertLength);		if (::GetHandleSize(theHandle) < currentLength + 1 + insertLength)	{		SetErrorMessageAndLongIntAndBail("InsertCStrIntoHandle: Can't expand storage for Handle, MemError() = ",MemError());	}		::BlockMove(*theHandle + inInsertOffset,*theHandle + inInsertOffset + insertLength,currentLength - inInsertOffset + 1);		::BlockMove(theCString,*theHandle + inInsertOffset,insertLength);	errCode = noErr;		EXITPOINT:	return(errCode);}void CopyCStrAndInsert1LongIntIntoCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength){	CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,nil,theNum,theDstCStr,maxDstStrLength);}void CopyCStrAndInsert2LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,char *theDstCStr,const int maxDstStrLength){const long	theLongInts[] = { long1,long2 };	CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);}void CopyCStrAndInsert3LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,const long long3,char *theDstCStr,const int maxDstStrLength){const long	theLongInts[] = { long1,long2,long3 };	CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);}void CopyCStrAndInsertCStrIntoCStr(const char *theSrcCStr,const char *theInsertCStr,char *theDstCStr,const int maxDstStrLength){const char	*theCStrs[2] = { theInsertCStr,nil };	CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,nil,theDstCStr,maxDstStrLength);}void CopyCStrAndInsertCStrLongIntIntoCStr(const char *theSrcCStr,const char *theInsertCStr,const long theNum,char *theDstCStr,const int maxDstStrLength){const char	*theCStrs[2] = { theInsertCStr,nil };const long	theLongInts[1] = { theNum };	CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,theLongInts,theDstCStr,maxDstStrLength);}void CopyCStrAndInsertCStrsLongIntsIntoCStr(const char *theSrcCStr,const char **theInsertCStrs,const long *theLongInts,char *theDstCStr,const int maxDstStrLength){int			dstCharIndex,srcCharIndex,theMaxDstStrLength;int			theCStrIndex = 0;int			theLongIntIndex = 0;		theMaxDstStrLength = maxDstStrLength;		if (theDstCStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)	{		dstCharIndex = 0;				srcCharIndex = 0;						//	Allow room for NULL at end of string				theMaxDstStrLength--;						for (;;)		{			//	Hit end of buffer?						if (dstCharIndex >= theMaxDstStrLength)			{				theDstCStr[dstCharIndex++] = 0;								goto EXITPOINT;			}						//	End of source string?						else if (theSrcCStr[srcCharIndex] == 0)			{				theDstCStr[dstCharIndex++] = 0;								goto EXITPOINT;			}						//	Did we find a '%s'?						else if (theInsertCStrs != nil && theInsertCStrs[theCStrIndex] != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 's')			{				//	Skip over the '%s'								srcCharIndex += 2;												//	Terminate the dest string and then concat the string								theDstCStr[dstCharIndex] = 0;								ConcatCStrToCStr(theInsertCStrs[theCStrIndex],theDstCStr,theMaxDstStrLength);								dstCharIndex = CStrLength(theDstCStr);								theCStrIndex++;			}						//	Did we find a '%ld'?						else if (theLongInts != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 'l' && theSrcCStr[srcCharIndex + 2] == 'd')			{				//	Skip over the '%ld'								srcCharIndex += 3;												//	Terminate the dest string and then concat the number								theDstCStr[dstCharIndex] = 0;								ConcatLongIntToCStr(theLongInts[theLongIntIndex],theDstCStr,theMaxDstStrLength);								theLongIntIndex++;								dstCharIndex = CStrLength(theDstCStr);			}						else			{				theDstCStr[dstCharIndex++] = theSrcCStr[srcCharIndex++];			}		}	}EXITPOINT:	return;}OSErr CopyCStrAndInsertCStrLongIntIntoHandle(const char *theSrcCStr,const char *theInsertCStr,const long theNum,Handle *theHandle){OSErr	errCode;long	byteCount;		if (theHandle != nil)	{		byteCount = CStrLength(theSrcCStr) + CStrLength(theInsertCStr) + 32;				*theHandle = NewHandle(byteCount);				if (*theHandle == nil)		{			SetErrorMessageAndLongIntAndBail("CopyCStrAndInsertCStrLongIntIntoHandle: Can't allocate Handle, MemError() = ",MemError());		}						HLock(*theHandle);				CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,theInsertCStr,theNum,**theHandle,byteCount);				HUnlock(*theHandle);	}		errCode = noErr;		EXITPOINT:	return(errCode);}OSErr CopyIndexedWordToCStr(char *theSrcCStr,int whichWord,char *theDstCStr,int maxDstCStrLength){OSErr		errCode;char		*srcCharPtr,*dstCharPtr;int			wordCount;int			byteCount;	if (theSrcCStr == nil)	{		SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theSrcCStr == nil"));	}		if (theDstCStr == nil)	{		SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theDstCStr == nil"));	}		if (whichWord < 0)	{		SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, whichWord < 0"));	}		if (maxDstCStrLength <= 0)	{		SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, maxDstCStrLength <= 0"));	}		*theDstCStr = '\0';		srcCharPtr = theSrcCStr;	while (*srcCharPtr == ' ' || *srcCharPtr == '\t')	{		srcCharPtr++;	}		for (wordCount = 0;wordCount < whichWord;wordCount++)	{		while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')		{			srcCharPtr++;		}				if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')		{			errCode = noErr;						goto EXITPOINT;		}		while (*srcCharPtr == ' ' || *srcCharPtr == '\t')		{			srcCharPtr++;		}				if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')		{			errCode = noErr;						goto EXITPOINT;		}	}	dstCharPtr = theDstCStr;	byteCount = 0;			for(;;)	{		if (byteCount >= maxDstCStrLength - 1 || *srcCharPtr == '\0' || *srcCharPtr == ' ' || *srcCharPtr == '\t' || *srcCharPtr == '\r' || *srcCharPtr == '\n')		{			*dstCharPtr = '\0';			break;		}				*dstCharPtr++ = *srcCharPtr++;				byteCount++;	}	errCode = noErr;EXITPOINT:	return(errCode);}OSErr CopyIndexedWordToNewHandle(char *theSrcCStr,int whichWord,Handle *outTheHandle){OSErr		errCode;char		*srcCharPtr;int			wordCount;int			byteCount;	if (theSrcCStr == nil)	{		SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, theSrcCStr == nil"));	}		if (outTheHandle == nil)	{		SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, outTheHandle == nil"));	}		if (whichWord < 0)	{		SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, whichWord < 0"));	}		*outTheHandle = nil;		srcCharPtr = theSrcCStr;	while (*srcCharPtr == ' ' || *srcCharPtr == '\t')	{		srcCharPtr++;	}		for (wordCount = 0;wordCount < whichWord;wordCount++)	{		while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')		{			srcCharPtr++;		}				if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')		{			break;		}		while (*srcCharPtr == ' ' || *srcCharPtr == '\t')		{			srcCharPtr++;		}				if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')		{			break;		}	}	for (byteCount = 0;;byteCount++)	{		if (srcCharPtr[byteCount] == ' ' || srcCharPtr[byteCount] == '\t' || srcCharPtr[byteCount] == '\r' || srcCharPtr[byteCount] == '\n' || srcCharPtr[byteCount] == '\0')		{			break;		}	}		*outTheHandle = NewHandle(byteCount + 1);		if (*outTheHandle == nil)	{		SetErrorMessageAndLongIntAndBail("CopyIndexedWordToNewHandle: Can't allocate Handle, MemError() = ",MemError());	}			::BlockMove(srcCharPtr,**outTheHandle,byteCount);		(**outTheHandle)[byteCount] = '\0';	errCode = noErr;EXITPOINT:	return(errCode);}OSErr CopyIndexedLineToCStr(const char *theSrcCStr,int inWhichLine,int *lineEndIndex,Boolean *gotLastLine,char *theDstCStr,const int maxDstCStrLength){OSErr		errCode;int			theCurrentLine;int			theCurrentLineOffset;int			theEOSOffset;	if (theSrcCStr == nil)	{		SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theSrcCStr == nil"));	}		if (theDstCStr == nil)	{		SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theDstCStr == nil"));	}		if (inWhichLine < 0)	{		SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, inWhichLine < 0"));	}		if (maxDstCStrLength <= 0)	{		SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, maxDstCStrLength <= 0"));	}			if (gotLastLine != nil)	{		*gotLastLine = false;	}		*theDstCStr = 0;		theCurrentLineOffset = 0;		theCurrentLine = 0;			while (theCurrentLine < inWhichLine)	{		while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != 0)		{			theCurrentLineOffset++;		}				if (theSrcCStr[theCurrentLineOffset] == 0)		{			break;		}				theCurrentLineOffset++;		theCurrentLine++;	}			if (theSrcCStr[theCurrentLineOffset] == 0)	{		SetErrorMessageAndLongIntAndBail("CopyIndexedLineToCStr: Too few lines in source text, can't get line ",inWhichLine);	}	theEOSOffset = FindCharOffsetInCStr('\r',theSrcCStr + theCurrentLineOffset);		if (theEOSOffset >= 0)	{		CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);				if (gotLastLine != nil)		{			*gotLastLine = false;		}			if (lineEndIndex != nil)		{			*lineEndIndex = theEOSOffset;		}	}		else	{		theEOSOffset = CStrLength(theSrcCStr + theCurrentLineOffset);		CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);				if (gotLastLine != nil)		{			*gotLastLine = true;		}			if (lineEndIndex != nil)		{			*lineEndIndex = theEOSOffset;		}	}		errCode = noErr;EXITPOINT:	return(errCode);}OSErr CopyIndexedLineToNewHandle(const char *theSrcCStr,int inWhichLine,Handle *outNewHandle){OSErr		errCode;int			theCurrentLine;int			theCurrentLineOffset;int			byteCount;	SetErrorMessageAndBailIfNil(theSrcCStr,"CopyIndexedLineToNewHandle: Bad parameter, theSrcCStr == nil");	SetErrorMessageAndBailIfNil(outNewHandle,"CopyIndexedLineToNewHandle: Bad parameter, outNewHandle == nil");		if (inWhichLine < 0)	{		SetErrorMessageAndBail(("CopyIndexedLineToNewHandle: Bad parameter, inWhichLine < 0"));	}		theCurrentLineOffset = 0;		theCurrentLine = 0;			while (theCurrentLine < inWhichLine)	{		while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != '\0')		{			theCurrentLineOffset++;		}				if (theSrcCStr[theCurrentLineOffset] == '\0')		{			break;		}				theCurrentLineOffset++;		theCurrentLine++;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -