Example #1
0
static int
bibtex_addtitleurl( fields *info, newstr *in )
{
	int fstatus, status = BIBL_OK;
	newstr s;
	char *p;

	newstr_init( &s );

	/* ...skip past "\href{" and copy to "}" */
	p = newstr_cpytodelim( &s, in->data + 6, "}", 1 );
	if ( newstr_memerr( &s ) ) { status = BIBL_ERR_MEMERR; goto out; }

	/* ...add to URL */
	fstatus = fields_add( info, "URL", s.data, 0 );
	if ( fstatus!=FIELDS_OK ) { status = BIBL_ERR_MEMERR; goto out; }

	/* ...return deleted fragment to newstr in */
	p = newstr_cpytodelim( &s, p, "", 0 );
	if ( newstr_memerr( &s ) ) { status = BIBL_ERR_MEMERR; goto out; }
	newstr_swapstrings( &s, in );

out:
	newstr_free( &s );
	return status;
}
Example #2
0
static int
test_swapstrings( newstr *s )
{
	int failed = 0;
	newstr t;

	newstr_init( &t );

	newstr_strcpy( &t, "0123456789" );
	newstr_strcpy( s,  "abcde" );

	newstr_swapstrings( s, &t );
	if ( string_mismatch( &t, 5, "abcde" ) ) failed++;
	if ( string_mismatch( s, 10, "0123456789" ) ) failed++;

	newstr_swapstrings( s, &t );
	if ( string_mismatch( s, 5, "abcde" ) ) failed++;
	if ( string_mismatch( &t, 10, "0123456789" ) ) failed++;

	newstr_free( &t );

	return failed;
}
Example #3
0
static void
bibtex_addtitleurl( fields *info, newstr *in )
{
	newstr s;
	char *p,*q;
	newstr_init( &s );
	q = p = in->data + 6; /*skip past \href{ */
	while ( *q && *q!='}' ) q++;
	newstr_segcpy( &s, p, q );
	fields_add( info, "URL", s.data, 0 );
	newstr_empty( &s );
	if ( *q=='}' ) q++;
	p = q;
	while ( *q ) q++;
	newstr_segcpy( &s, p, q );
	newstr_swapstrings( &s, in );
	newstr_free( &s );
}