@@ -1784,6 +1784,8 @@ char* _str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
1784
1784
size_t length = strlen (s );
1785
1785
char * s_copy = malloc (length + 1 );
1786
1786
char * dst = s_copy ;
1787
+ // Skip leading whitespace.
1788
+ while (isspace_ascii (* p )) p ++ ;
1787
1789
// Copy Leading sign
1788
1790
if (* p == '+' || * p == '-' ) {
1789
1791
* dst ++ = * p ++ ;
@@ -1798,10 +1800,25 @@ char* _str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
1798
1800
* dst ++ = '.' ;
1799
1801
p ++ ;
1800
1802
}
1801
- // Copy the remainder of the string as is.
1802
- strncpy (dst , p , length + 1 - (p - s ));
1803
+ // Copy fractional part after decimal (if any)
1804
+ while (isdigit_ascii (* p )) {
1805
+ * dst ++ = * p ++ ;
1806
+ }
1807
+ // Copy exponent if any
1808
+ if (toupper_ascii (* p ) == toupper_ascii ('E' )) {
1809
+ * dst ++ = * p ++ ;
1810
+ // Copy leading exponent sign (if any)
1811
+ if (* p == '+' || * p == '-' ) {
1812
+ * dst ++ = * p ++ ;
1813
+ }
1814
+ // Copy exponent digits
1815
+ while (isdigit_ascii (* p )) {
1816
+ * dst ++ = * p ++ ;
1817
+ }
1818
+ }
1819
+ * dst ++ = '\0' ; // terminate
1803
1820
if (endpos != NULL )
1804
- * endpos = (char * )( s + length ) ;
1821
+ * endpos = (char * )p ;
1805
1822
return s_copy ;
1806
1823
}
1807
1824
@@ -1839,6 +1856,11 @@ double round_trip(const char *p, char **q, char decimal, char sci, char tsep,
1839
1856
1840
1857
PyGILState_Release (gstate );
1841
1858
free (pc );
1859
+ if (skip_trailing && q != NULL && * q != p ) {
1860
+ while (isspace_ascii (* * q )) {
1861
+ (* q )++ ;
1862
+ }
1863
+ }
1842
1864
return r ;
1843
1865
}
1844
1866
0 commit comments