OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxcrt/include/fx_basic.h" | 7 #include "core/fxcrt/include/fx_basic.h" |
8 #include "core/fxcrt/include/fx_ext.h" | 8 #include "core/fxcrt/include/fx_ext.h" |
9 | 9 |
10 #include <cctype> | 10 #include <cctype> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 90 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
91 int count = m_DataList.GetSize(); | 91 int count = m_DataList.GetSize(); |
92 for (int i = 0; i < count; i++) { | 92 for (int i = 0; i < count; i++) { |
93 pList[i].FreeData(); | 93 pList[i].FreeData(); |
94 } | 94 } |
95 m_DataList.RemoveAll(); | 95 m_DataList.RemoveAll(); |
96 } | 96 } |
97 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { | 97 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { |
98 if (strc.Find('.') == -1) { | 98 if (strc.Find('.') == -1) { |
99 bInteger = TRUE; | 99 bInteger = TRUE; |
100 int cc = 0, integer = 0; | 100 int cc = 0; |
101 const FX_CHAR* str = strc.c_str(); | 101 int integer = 0; |
102 int len = strc.GetLength(); | 102 FX_STRSIZE len = strc.GetLength(); |
103 FX_BOOL bNegative = FALSE; | 103 bool bNegative = false; |
104 if (str[0] == '+') { | 104 if (strc[0] == '+') { |
105 cc++; | 105 cc++; |
106 } else if (str[0] == '-') { | 106 } else if (strc[0] == '-') { |
107 bNegative = TRUE; | 107 bNegative = true; |
108 cc++; | 108 cc++; |
109 } | 109 } |
110 while (cc < len && std::isdigit(str[cc])) { | 110 while (cc < len && std::isdigit(strc[cc])) { |
111 // TODO(dsinclair): This is not the right way to handle overflow. | 111 // TODO(dsinclair): This is not the right way to handle overflow. |
112 integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]); | 112 integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); |
113 if (integer < 0) | 113 if (integer < 0) |
114 break; | 114 break; |
115 cc++; | 115 cc++; |
116 } | 116 } |
117 if (bNegative) { | 117 if (bNegative) { |
118 integer = -integer; | 118 integer = -integer; |
119 } | 119 } |
120 *(int*)pData = integer; | 120 *(int*)pData = integer; |
121 } else { | 121 } else { |
122 bInteger = FALSE; | 122 bInteger = FALSE; |
123 *(FX_FLOAT*)pData = FX_atof(strc); | 123 *(FX_FLOAT*)pData = FX_atof(strc); |
124 } | 124 } |
125 } | 125 } |
126 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { | 126 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { |
127 if (strc.GetLength() == 0) { | 127 if (strc.IsEmpty()) |
128 return 0.0; | 128 return 0.0; |
129 } | 129 |
130 int cc = 0; | 130 int cc = 0; |
131 FX_BOOL bNegative = FALSE; | 131 bool bNegative = false; |
132 const FX_CHAR* str = strc.c_str(); | |
133 int len = strc.GetLength(); | 132 int len = strc.GetLength(); |
134 if (str[0] == '+') { | 133 if (strc[0] == '+') { |
135 cc++; | 134 cc++; |
136 } else if (str[0] == '-') { | 135 } else if (strc[0] == '-') { |
137 bNegative = TRUE; | 136 bNegative = TRUE; |
138 cc++; | 137 cc++; |
139 } | 138 } |
140 while (cc < len) { | 139 while (cc < len) { |
141 if (str[cc] != '+' && str[cc] != '-') { | 140 if (strc[cc] != '+' && strc[cc] != '-') { |
142 break; | 141 break; |
143 } | 142 } |
144 cc++; | 143 cc++; |
145 } | 144 } |
146 FX_FLOAT value = 0; | 145 FX_FLOAT value = 0; |
147 while (cc < len) { | 146 while (cc < len) { |
148 if (str[cc] == '.') { | 147 if (strc[cc] == '.') { |
149 break; | 148 break; |
150 } | 149 } |
151 value = value * 10 + FXSYS_toDecimalDigit(str[cc]); | 150 value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); |
152 cc++; | 151 cc++; |
153 } | 152 } |
154 static const FX_FLOAT fraction_scales[] = { | 153 static const FX_FLOAT fraction_scales[] = { |
155 0.1f, 0.01f, 0.001f, 0.0001f, | 154 0.1f, 0.01f, 0.001f, 0.0001f, |
156 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, | 155 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, |
157 0.000000001f, 0.0000000001f, 0.00000000001f}; | 156 0.000000001f, 0.0000000001f, 0.00000000001f}; |
158 int scale = 0; | 157 int scale = 0; |
159 if (cc < len && str[cc] == '.') { | 158 if (cc < len && strc[cc] == '.') { |
160 cc++; | 159 cc++; |
161 while (cc < len) { | 160 while (cc < len) { |
162 value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]); | 161 value += fraction_scales[scale] * FXSYS_toDecimalDigit(strc.CharAt(cc)); |
163 scale++; | 162 scale++; |
164 if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) { | 163 if (scale == FX_ArraySize(fraction_scales)) |
165 break; | 164 break; |
166 } | |
167 cc++; | 165 cc++; |
168 } | 166 } |
169 } | 167 } |
170 return bNegative ? -value : value; | 168 return bNegative ? -value : value; |
171 } | 169 } |
172 | 170 |
173 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 | 171 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 |
174 void FXSYS_snprintf(char* str, | 172 void FXSYS_snprintf(char* str, |
175 size_t size, | 173 size_t size, |
176 _Printf_format_string_ const char* fmt, | 174 _Printf_format_string_ const char* fmt, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i, | 356 d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i, |
359 g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h, | 357 g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h, |
360 g * m.c + h * m.f + i * m.i); | 358 g * m.c + h * m.f + i * m.i); |
361 } | 359 } |
362 | 360 |
363 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) { | 361 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) { |
364 return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c, | 362 return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c, |
365 d * v.a + e * v.b + f * v.c, | 363 d * v.a + e * v.b + f * v.c, |
366 g * v.a + h * v.b + i * v.c); | 364 g * v.a + h * v.b + i * v.c); |
367 } | 365 } |
OLD | NEW |