library/src/utility/BP-StringUtilities.cc
// attempt to calculate string length (generic drop in replacement for bpstrlen() but stops on any binary characters)
attempt to calculate string length (generic drop in replacement for bpstrlen() but stops on any binary characters)
attempt to calculate string length ( generic drop in replacement for bpstrlen () but stops on any binary characters )
size_t bpstrlen_real(const char *str, BPLN_PARMS)
{
	if(!str)
		return 0;
	if(!str[0])
		return 0;
	size_t char_iter = 0;
	for(; str[char_iter]; char_iter++)
	{
		if(isalnum(str[char_iter]))
			continue;
		if(!str[char_iter])
			break;
		switch(str[char_iter])
		{
			case ' ':
			case '\t':
			case '!':
			case '@':
			case '#':
			case '$':
			case '%':
			case '^':
			case '&':
			case '*':
			case '(':
			case ')':
			case '_':
			case '+':
			case '=':
			case '-':
			case '~':
			case '`':
			case '<':
			case '>':
			case ',':
			case '.':
			case '?':
			case '/':
			case '\\':
			case '"':
			case '\'':
			case ':':
			case ';':
			case '{':
			case '[':
			case ']':
			case '}':
			case '|':
			case '\r':
			case '\n':
				continue;
			case '\x1b':
				continue;
			case 0x00:
				break;
			default:
				printf("\n [!!] string found with binary data while using bpstrlen_real (should never occur): We are continuing, but please look at this later. ");
				printf("\n - offending char: 0x%.02x at position %u", (unsigned char)  str[char_iter], char_iter);
				printf("\n - func: %s", func);
				printf("\n - line: %u", line_number);
				printf("\n - file: %s", file_name);
				printf("\n");
				continue;
		}
	}
	return char_iter;
}
size_t bpstrlen_real ( const char * str , BPLN_PARMS ) { if ( ! str ) return 0 ; if ( ! str [ 0 ] ) return 0 ; size_t char_iter = 0 ; for ( ; str [ char_iter ] ; char_iter ++ ) { if ( isalnum ( str [ char_iter ] ) ) continue ; if ( ! str [ char_iter ] ) break ; switch ( str [ char_iter ] ) { case ' ' : case ' \t ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' \\ ' : case ' ' : case ' \' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' \r ' : case ' \n ' : continue ; case ' \x1b ' : continue ; case 0x00 : break ; default : printf ( " \n " ) ; printf ( " \n " , ( unsigned char ) str [ char_iter ] , char_iter ) ; printf ( " \n " , func ) ; printf ( " \n " , line_number ) ; printf ( " \n " , file_name ) ; printf ( " \n " ) ; continue ; } } return char_iter ; }
attempt to calculate string length (generic drop in replacement for bpstrlen() but stops on any binary characters)
attempt to calculate string length ( generic drop in replacement for bpstrlen () but stops on any binary characters )
// ensure we have a string to analyze and a length // iterate through string // if it's not alphanumeric continue // ensure the character isn't null before doing any tests // switch on allowed chars (long code but fastest pathing) // all valid characters pass through ok // 0x1b is terminal color escape. // null terminator // return zero if the string has a bad char in it somehow (also display stack output) // return total number of good characters