summaryrefslogtreecommitdiff
path: root/nanosvg/fl_nanosvg.diff
blob: 891379a1d4b54991b810f522d690d785200733ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
1,10d0
< //
< // "$Id$"
< //
< 
< /* Modified by FLTK from original source file "nanosvg.h" to support compilation 
<  with Visual Studio 7:
<  remove the implementation of function nsvg__atof() that uses 
<  unsupported "long long" type and strtoll() function.
<  */
< 
1087a1078,1137
> // We roll our own string to float because the std library one uses locale and messes things up.
> static double nsvg__atof(const char* s)
> {
> 	char* cur = (char*)s;
> 	char* end = NULL;
> 	double res = 0.0, sign = 1.0;
> 	long long intPart = 0, fracPart = 0;
> 	char hasIntPart = 0, hasFracPart = 0;
> 
> 	// Parse optional sign
> 	if (*cur == '+') {
> 		cur++;
> 	} else if (*cur == '-') {
> 		sign = -1;
> 		cur++;
> 	}
> 
> 	// Parse integer part
> 	if (nsvg__isdigit(*cur)) {
> 		// Parse digit sequence
> 		intPart = (double)strtoll(cur, &end, 10);
> 		if (cur != end) {
> 			res = (double)intPart;
> 			hasIntPart = 1;
> 			cur = end;
> 		}
> 	}
> 
> 	// Parse fractional part.
> 	if (*cur == '.') {
> 		cur++; // Skip '.'
> 		if (nsvg__isdigit(*cur)) {
> 			// Parse digit sequence
> 			fracPart = strtoll(cur, &end, 10);
> 			if (cur != end) {
> 				res += (double)fracPart / pow(10.0, (double)(end - cur));
> 				hasFracPart = 1;
> 				cur = end;
> 			}
> 		}
> 	}
> 
> 	// A valid number should have integer or fractional part.
> 	if (!hasIntPart && !hasFracPart)
> 		return 0.0;
> 
> 	// Parse optional exponent
> 	if (*cur == 'e' || *cur == 'E') {
> 		int expPart = 0;
> 		cur++; // skip 'E'
> 		expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
> 		if (cur != end) {
> 			res *= pow(10.0, (double)expPart);
> 		}
> 	}
> 
> 	return res * sign;
> }
> 
> 
2876,2879d2925
< 
< //
< // End of "$Id$".
< //