tier1/strtools.cpp
void V_StrSlice( const char *pStr, int firstChar, int lastCharNonInclusive, char *pOut, int outSize )
{
	if ( outSize == 0 )
		return;
	
	int length = V_strlen( pStr );

	// Fixup the string indices.
	if ( firstChar < 0 )
	{
		firstChar = length - (-firstChar % length);
	}
	else if ( firstChar >= length )
	{
		pOut[0] = 0;
		return;
	}

	if ( lastCharNonInclusive < 0 )
	{
		lastCharNonInclusive = length - (-lastCharNonInclusive % length);
	}
	else if ( lastCharNonInclusive > length )
	{
		lastCharNonInclusive %= length;
	}

	if ( lastCharNonInclusive <= firstChar )
	{
		pOut[0] = 0;
		return;
	}

	int copyLen = lastCharNonInclusive - firstChar;
	if ( copyLen <= (outSize-1) )
	{
		memcpy( pOut, &pStr[firstChar], copyLen );
		pOut[copyLen] = 0;
	}
	else
	{
		memcpy( pOut, &pStr[firstChar], outSize-1 );
		pOut[outSize-1] = 0;
	}
}
// This function takes a slice out of pStr and stores it in pOut.
// It follows the Python slice convention:
// Negative numbers wrap around the string (-1 references the last character).
// Numbers are clamped to the end of the string.
This function takes a slice out of pStr and stores it in pOut.
It follows the Python slice convention:
Negative numbers wrap around the string (-1 references the last character).
Numbers are clamped to the end of the string.
This function takes a slice out of pStr and stores it in pOut . It follows the Python slice convention : Negative numbers wrap around the string ( - 1 references the last character ) . Numbers are clamped to the end of the string .
void V_StrSlice( const char *pStr, int firstChar, int lastCharNonInclusive, char *pOut, int outSize )
{
	if ( outSize == 0 )
		return;
	int length = V_strlen( pStr );
	if ( firstChar < 0 )
	{
		firstChar = length - (-firstChar % length);
	}
	else if ( firstChar >= length )
	{
		pOut[0] = 0;
		return;
	}
	if ( lastCharNonInclusive < 0 )
	{
		lastCharNonInclusive = length - (-lastCharNonInclusive % length);
	}
	else if ( lastCharNonInclusive > length )
	{
		lastCharNonInclusive %= length;
	}
	if ( lastCharNonInclusive <= firstChar )
	{
		pOut[0] = 0;
		return;
	}
	int copyLen = lastCharNonInclusive - firstChar;
	if ( copyLen <= (outSize-1) )
	{
		memcpy( pOut, &pStr[firstChar], copyLen );
		pOut[copyLen] = 0;
	}
	else
	{
		memcpy( pOut, &pStr[firstChar], outSize-1 );
		pOut[outSize-1] = 0;
	}
}
void V_StrSlice ( const char * pStr , int firstChar , int lastCharNonInclusive , char * pOut , int outSize ) { if ( outSize == 0 ) return ; int length = V_strlen ( pStr ) ; if ( firstChar < 0 ) { firstChar = length - ( - firstChar % length ) ; } else if ( firstChar >= length ) { pOut [ 0 ] = 0 ; return ; } if ( lastCharNonInclusive < 0 ) { lastCharNonInclusive = length - ( - lastCharNonInclusive % length ) ; } else if ( lastCharNonInclusive > length ) { lastCharNonInclusive %= length ; } if ( lastCharNonInclusive <= firstChar ) { pOut [ 0 ] = 0 ; return ; } int copyLen = lastCharNonInclusive - firstChar ; if ( copyLen <= ( outSize - 1 ) ) { memcpy ( pOut , & pStr [ firstChar ] , copyLen ) ; pOut [ copyLen ] = 0 ; } else { memcpy ( pOut , & pStr [ firstChar ] , outSize - 1 ) ; pOut [ outSize - 1 ] = 0 ; } }
This function takes a slice out of pStr and stores it in pOut.
This function takes a slice out of pStr and stores it in pOut .
// Fixup the string indices.