placeholder.c
/* Parse a placeholder from a format string */
Parse a placeholder from a format string
Parse a placeholder from a format string
Placeholder* Placeholder_parse(const char** expr) {
	if(**expr != '@') {
		RAISE(badChar(*expr), true);
	}
	(*expr)++;
	unsigned index = 0;
	if(isdigit(**expr)) {
		char* end;
		errno = 0;
		index = (unsigned)strtoul(*expr, &end, 10);
		if(errno != 0 || index == 0 || *expr == end) {
			RAISE(syntaxError(*expr, "Invalid number in placeholder"), true);
		}
		*expr = end;
	}
	PLACETYPE type = getPlaceholderType(**expr);
	if(type == PH_ERR) {
		RAISE(badChar(*expr), true);
	}
	(*expr)++;
	return Placeholder_new(type, index);
}
Placeholder * Placeholder_parse ( const char * * expr ) { if ( * * expr != ' ' ) { RAISE ( badChar ( * expr ) , true ) ; } ( * expr ) ++ ; unsigned index = 0 ; if ( isdigit ( * * expr ) ) { char * end ; errno = 0 ; index = ( unsigned ) strtoul ( * expr , & end , 10 ) ; if ( errno != 0 || index == 0 || * expr == end ) { RAISE ( syntaxError ( * expr , " " ) , true ) ; } * expr = end ; } PLACETYPE type = getPlaceholderType ( * * expr ) ; if ( type == PH_ERR ) { RAISE ( badChar ( * expr ) , true ) ; } ( * expr ) ++ ; return Placeholder_new ( type , index ) ; }
Parse a placeholder from a format string
Parse a placeholder from a format string
/* Move past '@' */ /* Like @1v or @4@ */ /* Read the number after the '@' */ /* An error occurred (EINVAL, ERANGE) */ /* Advance past the number */