Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: core/fxcrt/fx_basic_util.cpp

Issue 2094453004: Use some FXSYS methods instead of duplicating (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fxcrt/include/fx_ext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
(...skipping 29 matching lines...) Expand all
40 if (bNegative) { 40 if (bNegative) {
41 integer = -integer; 41 integer = -integer;
42 } 42 }
43 *(int*)pData = integer.ValueOrDefault(0); 43 *(int*)pData = integer.ValueOrDefault(0);
44 } else { 44 } else {
45 bInteger = FALSE; 45 bInteger = FALSE;
46 *(FX_FLOAT*)pData = FX_atof(strc); 46 *(FX_FLOAT*)pData = FX_atof(strc);
47 } 47 }
48 } 48 }
49 49
50 static const FX_FLOAT fraction_scales[] = {
51 0.1f, 0.01f, 0.001f, 0.0001f,
52 0.00001f, 0.000001f, 0.0000001f, 0.00000001f,
53 0.000000001f, 0.0000000001f, 0.00000000001f};
54 int FXSYS_FractionalScaleCount() {
55 return FX_ArraySize(fraction_scales);
56 }
57
58 FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value) {
59 return fraction_scales[scale_factor] * value;
60 }
61
50 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { 62 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
51 if (strc.IsEmpty()) 63 if (strc.IsEmpty())
52 return 0.0; 64 return 0.0;
53 65
54 int cc = 0; 66 int cc = 0;
55 bool bNegative = false; 67 bool bNegative = false;
56 int len = strc.GetLength(); 68 int len = strc.GetLength();
57 if (strc[0] == '+') { 69 if (strc[0] == '+') {
58 cc++; 70 cc++;
59 } else if (strc[0] == '-') { 71 } else if (strc[0] == '-') {
60 bNegative = TRUE; 72 bNegative = TRUE;
61 cc++; 73 cc++;
62 } 74 }
63 while (cc < len) { 75 while (cc < len) {
64 if (strc[cc] != '+' && strc[cc] != '-') { 76 if (strc[cc] != '+' && strc[cc] != '-') {
65 break; 77 break;
66 } 78 }
67 cc++; 79 cc++;
68 } 80 }
69 FX_FLOAT value = 0; 81 FX_FLOAT value = 0;
70 while (cc < len) { 82 while (cc < len) {
71 if (strc[cc] == '.') { 83 if (strc[cc] == '.') {
72 break; 84 break;
73 } 85 }
74 value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); 86 value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc));
75 cc++; 87 cc++;
76 } 88 }
77 static const FX_FLOAT fraction_scales[] = {
78 0.1f, 0.01f, 0.001f, 0.0001f,
79 0.00001f, 0.000001f, 0.0000001f, 0.00000001f,
80 0.000000001f, 0.0000000001f, 0.00000000001f};
81 int scale = 0; 89 int scale = 0;
82 if (cc < len && strc[cc] == '.') { 90 if (cc < len && strc[cc] == '.') {
83 cc++; 91 cc++;
84 while (cc < len) { 92 while (cc < len) {
85 value += fraction_scales[scale] * FXSYS_toDecimalDigit(strc.CharAt(cc)); 93 value +=
94 FXSYS_FractionalScale(scale, FXSYS_toDecimalDigit(strc.CharAt(cc)));
86 scale++; 95 scale++;
87 if (scale == FX_ArraySize(fraction_scales)) 96 if (scale == FXSYS_FractionalScaleCount())
88 break; 97 break;
89 cc++; 98 cc++;
90 } 99 }
91 } 100 }
92 return bNegative ? -value : value; 101 return bNegative ? -value : value;
93 } 102 }
94 103
95 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 104 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900
96 void FXSYS_snprintf(char* str, 105 void FXSYS_snprintf(char* str,
97 size_t size, 106 size_t size,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 dstShift -= 8; 301 dstShift -= 8;
293 result |= *dataPtr++ << dstShift; 302 result |= *dataPtr++ << dstShift;
294 } 303 }
295 if (dstShift > 0) { 304 if (dstShift > 0) {
296 bitShift = 8 - dstShift; 305 bitShift = 8 - dstShift;
297 bitMask = (1 << dstShift) - 1; 306 bitMask = (1 << dstShift) - 1;
298 result |= *dataPtr++ >> bitShift & bitMask; 307 result |= *dataPtr++ >> bitShift & bitMask;
299 } 308 }
300 return result; 309 return result;
301 } 310 }
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/include/fx_ext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698