StudyGlib/app/src/main/cpp/study/type.c
/* It'd be great to be able to write a generic string->array function, but
 * it doesn't seem possible.
 */
It'd be great to be able to write a generic string->array function, but
it doesn't seem possible.
It ' d be great to be able to write a generic string - > array function but it doesn ' t seem possible .
static void
transform_g_string_array_double( const GValue *src_value, GValue *dest_value )
{
    char *str;
    int n;
    char *p, *q;
    int i;
    double *array;
    str = g_value_dup_string( src_value );
    n = 0;
    for( p = str; (q = vips_break_token( p, "\t; " )); p = q )
        n += 1;
    g_free( str );
    vips_value_set_array_double( dest_value, NULL, n );
    array = vips_value_get_array_double( dest_value, NULL );
    str = g_value_dup_string( src_value );
    i = 0;
    for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) {
        if( sscanf( p, "%lf", &array[i] ) != 1 ) {
            vips_error( "vipstype",
                        _( "unable to convert \"%s\" to float" ), p );
            vips_value_set_array_double( dest_value, NULL, 0 );
            g_free( str );
            return;
        }
        i += 1;
    }
    g_free( str );
}
static void transform_g_string_array_double ( const GValue * src_value , GValue * dest_value ) { char * str ; int n ; char * p , * q ; int i ; double * array ; str = g_value_dup_string ( src_value ) ; n = 0 ; for ( p = str ; ( q = vips_break_token ( p , " \t " ) ) ; p = q ) n += 1 ; g_free ( str ) ; vips_value_set_array_double ( dest_value , NULL , n ) ; array = vips_value_get_array_double ( dest_value , NULL ) ; str = g_value_dup_string ( src_value ) ; i = 0 ; for ( p = str ; ( q = vips_break_token ( p , " \t " ) ) ; p = q ) { if ( sscanf ( p , " " , & array [ i ] ) != 1 ) { vips_error ( " " , _ ( " \" \" " ) , p ) ; vips_value_set_array_double ( dest_value , NULL , 0 ) ; g_free ( str ) ; return ; } i += 1 ; } g_free ( str ) ; }
It'd be great to be able to write a generic string->array function, but
 it doesn't seem possible.
It ' d be great to be able to write a generic string - > array function but it doesn ' t seem possible .
/* Walk the string to get the number of elements.
     * We need a copy of the string, since we insert \0 during scan.
     *
     * We can't allow ',' as a separator since some locales use it as a
     * decimal point.
     */ /* Set array to length zero to indicate an error.
             */