/* Split a page label into a text prefix and numeric suffix. Leading '0's are included in the prefix. eg "3" => NULL, 3 "cover" => "cover", 0 "A-2" => "A-", 2 "A-002" => "A-00", 2  */
static char* split_label(const char *label, int *num)
/* Split a page label into a text prefix and numeric suffix. Leading '0's are included in the prefix. eg "3" => NULL, 3 "cover" => "cover", 0 "A-2" => "A-", 2 "A-002" => "A-00", 2  */
static char* split_label(const char *label, int *num)
{
    int len, i;
    *num = 0;
    len = strlen (label);
    if (len == 0)
	return NULL;
    i = len;
    while (i > 0 && _cairo_isdigit (label[i-1]))
	   i--;
    while (i < len && label[i] == '0')
	i++;
    if (i < len)
	sscanf (label + i, "%d", num);
    if (i > 0) {
	char *s;
	s = _cairo_malloc (i + 1);
	if (!s)
	    return NULL;
	memcpy (s, label, i);
	s[i] = 0;
	return s;
    }
    return NULL;
}