| 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 ) |
|---|
| | 148 | static 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) |
|---|
| | 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 | */ |
|---|
| | 215 | double 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); |
|---|