library/src/utility/BP-StringUtilities.cc
// returns true if the string contains only
returns true if the string contains only
returns true if the string contains only
BP_BOOL BP_StringContainsOnlyNumericASCIIDigits
(
	char  *str,
	size_t len
)
{
	if(!str || !len)
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(str, len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);
	ascii_config.count_ascii                      = BP_TRUE;
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
			(unsigned char *) str,
			(size_t) len,
			&ascii_config
	);
	if(!buff_analysis)
		return BP_FALSE;
	size_t digit_len = \
			buff_analysis->ascii->char_counts['0'] +
			buff_analysis->ascii->char_counts['1'] +
			buff_analysis->ascii->char_counts['2'] +
			buff_analysis->ascii->char_counts['3'] +
			buff_analysis->ascii->char_counts['4'] +
			buff_analysis->ascii->char_counts['5'] +
			buff_analysis->ascii->char_counts['6'] +
			buff_analysis->ascii->char_counts['7'] +
			buff_analysis->ascii->char_counts['8'] +
			buff_analysis->ascii->char_counts['9'];
	BP_DestroyBufferAnalysis(buff_analysis);
	if(digit_len != len)
		return BP_FALSE;
	return BP_TRUE;
}
BP_BOOL BP_StringContainsOnlyNumericASCIIDigits ( char * str , size_t len ) { if ( ! str || ! len ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( str , len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) str , ( size_t ) len , & ascii_config ) ; if ( ! buff_analysis ) return BP_FALSE ; size_t digit_len = buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] + buff_analysis -> ascii -> char_counts [ ' ' ] ; BP_DestroyBufferAnalysis ( buff_analysis ) ; if ( digit_len != len ) return BP_FALSE ; return BP_TRUE ; }
returns true if the string contains only
returns true if the string contains only
// ensure we have a directory and a length // attempt to verify that the string is reasonable first // create ascii configuration // zero out the structure (automagic macro) // set some flags in the structure to count ascii (we already counted invalid with our initial check) // attempt to generate analysis // ensure we h ave a buffer analysis // get the digit length (number of characters in all digit places) // destroy the buffer analysis // if the calculated digit length is mismatched, we have a bad buffer, exit failing here // return indicating a successful match