Logo Search packages:      
Sourcecode: qfits version File versions  Download package

char* qfits_pretty_string ( const char *  s  ) 

Clean out a FITS string value.

Parameters:
s pointer to allocated FITS value string.
Returns:
pointer to statically allocated character string
From a string FITS value like 'marvin o''hara', remove head and tail quotes, replace double '' with simple ', trim blanks on each side, and return the result in a statically allocated area.

Examples:

  • ['o''hara'] becomes [o'hara]
  • [' H '] becomes [H]
  • ['1.0 '] becomes [1.0]

Definition at line 301 of file qfits_tools.c.

Referenced by qfits_card_build(), qfits_is_table(), qfits_table_open(), and qfitsloader_init().

{
    static char     pretty_buf[PRETTY_STRING_STATICBUFS][81] ;
    static int      flip=0 ;
    char        *   pretty ;
    int             i,j ;

    /* bulletproof */
    if (s==NULL) return NULL ;

    /* Switch between static buffers */
    pretty = pretty_buf[flip];
    flip++ ;
    if (flip==PRETTY_STRING_STATICBUFS)
        flip=0 ;
    
    pretty[0] = (char)0 ;
    if (s[0]!='\'') return (char *)s ;

    /* skip first quote */
    i=1 ;
    j=0 ;
    /* trim left-side blanks */
    while (s[i]==' ') {
        if (i==(int)strlen(s)) break ;
        i++ ;
    }
    if (i>=(int)(strlen(s)-1)) return pretty ;
    /* copy string, changing double quotes to single ones */
    while (i<(int)strlen(s)) {
        if (s[i]=='\'') {
            i++ ;
        }
        pretty[j]=s[i];
        i++ ;
        j++ ;
    }
    /* NULL-terminate the pretty string */
    pretty[j+1]=(char)0;
    /* trim right-side blanks */
    j = (int)strlen(pretty)-1;
    while (pretty[j]==' ') j-- ;
    pretty[j+1]=(char)0;
    return pretty;
}


Generated by  Doxygen 1.6.0   Back to index