Changeset 14803 for branches/1.5

Show
Ignore:
Timestamp:
07/03/08 13:44:52 (5 months ago)
Author:
rouault
Message:

Fix compilation problem in CPLStrtodDelim due to absence of localeconv() on WinCE (#2451)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/port/cpl_strtod.cpp

    r14568 r14803  
    146146/************************************************************************/ 
    147147 
    148 /** 
    149  * Converts ASCII string to floating point number using specified delimiter. 
    150  * 
    151  * This function converts the initial portion of the string pointed to 
    152  * by nptr to double floating point representation. This function does the 
    153  * same as standard strtod(3), but does not take locale in account. Instead of 
    154  * locale defined decimal delimiter you can specify your own one. Also see 
    155  * notes for CPLAtof() function. 
    156  * 
    157  * @param nptr Pointer to string to convert. 
    158  * @param endptr If is not NULL, a pointer to the character after the last 
    159  * character used in the conversion is stored in the location referenced 
    160  * by endptr. 
    161  * @param point Decimal delimiter. 
    162  * 
    163  * @return Converted value, if any. 
    164  */ 
    165 double CPLStrtodDelim(const char *nptr, char **endptr, char point) 
    166 
    167 /* -------------------------------------------------------------------- */ 
    168 /*  We are implementing a simple method here: copy the input string     */ 
    169 /*  into the temporary buffer, replace the specified decimal delimiter  */ 
    170 /*  with the one, taken from locale settings and use standard strtod()  */ 
    171 /*  on that buffer.                                                     */ 
    172 /* -------------------------------------------------------------------- */ 
    173  
    174     struct lconv *poLconv = localeconv(); 
    175     char        *pszNumber = CPLStrdup( nptr ); 
    176     double      dfValue; 
    177     int         nError; 
    178  
    179     if ( poLconv 
    180          && poLconv->decimal_point 
    181          && strlen(poLconv->decimal_point) > 0 ) 
     148static void CPLReplacePointByLocalePoint(char* pszNumber, char point) 
     149
     150#if defined(WIN32CE) 
     151    static char byPoint = 0; 
     152    if (byPoint == 0) 
     153    { 
     154        char szBuf[16]; 
     155        sprintf(szBuf, "%.1f", 1.0); 
     156        byPoint = szBuf[1]; 
     157    } 
     158    if (point != byPoint) 
    182159    { 
    183160        int     i = 0; 
    184         char    byPoint = poLconv->decimal_point[0]; 
    185161 
    186162        while ( pszNumber[i] ) 
     
    194170        } 
    195171    } 
     172#else 
     173    struct lconv *poLconv = localeconv(); 
     174    if ( poLconv 
     175         && poLconv->decimal_point 
     176         && strlen(poLconv->decimal_point) > 0 ) 
     177    { 
     178        int     i = 0; 
     179        char    byPoint = poLconv->decimal_point[0]; 
     180 
     181        if (point != byPoint) 
     182        { 
     183            while ( pszNumber[i] ) 
     184            { 
     185                if ( pszNumber[i] == point ) 
     186                { 
     187                    pszNumber[i] = byPoint; 
     188                    break; 
     189                } 
     190                i++; 
     191            } 
     192        } 
     193    } 
     194#endif 
     195} 
     196 
     197 
     198/** 
     199 * Converts ASCII string to floating point number using specified delimiter. 
     200 * 
     201 * This function converts the initial portion of the string pointed to 
     202 * by nptr to double floating point representation. This function does the 
     203 * same as standard strtod(3), but does not take locale in account. Instead of 
     204 * locale defined decimal delimiter you can specify your own one. Also see 
     205 * notes for CPLAtof() function. 
     206 * 
     207 * @param nptr Pointer to string to convert. 
     208 * @param endptr If is not NULL, a pointer to the character after the last 
     209 * character used in the conversion is stored in the location referenced 
     210 * by endptr. 
     211 * @param point Decimal delimiter. 
     212 * 
     213 * @return Converted value, if any. 
     214 */ 
     215double CPLStrtodDelim(const char *nptr, char **endptr, char point) 
     216{ 
     217/* -------------------------------------------------------------------- */ 
     218/*  We are implementing a simple method here: copy the input string     */ 
     219/*  into the temporary buffer, replace the specified decimal delimiter  */ 
     220/*  with the one, taken from locale settings and use standard strtod()  */ 
     221/*  on that buffer.                                                     */ 
     222/* -------------------------------------------------------------------- */ 
     223    char        *pszNumber = CPLStrdup( nptr ); 
     224    double      dfValue; 
     225    int         nError; 
     226 
     227    CPLReplacePointByLocalePoint(pszNumber, point); 
    196228 
    197229    dfValue = strtod( pszNumber, endptr ); 
     
    264296/* -------------------------------------------------------------------- */ 
    265297 
    266     struct lconv *poLconv = localeconv(); 
    267298    char        *pszNumber = CPLStrdup( nptr ); 
    268299    double      dfValue; 
    269300    int         nError; 
    270301 
    271     if ( poLconv 
    272          && poLconv->decimal_point 
    273          && strlen(poLconv->decimal_point) > 0 ) 
    274     { 
    275         int     i = 0; 
    276         char    byPoint = poLconv->decimal_point[0]; 
    277  
    278         while ( pszNumber[i] ) 
    279         { 
    280             if ( pszNumber[i] == point ) 
    281             { 
    282                 pszNumber[i] = byPoint; 
    283                 break; 
    284             } 
    285             i++; 
    286         } 
    287     } 
     302    CPLReplacePointByLocalePoint(pszNumber, point); 
    288303 
    289304    dfValue = strtof( pszNumber, endptr );