| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cctype> | 10 #include <cctype> |
| 11 | 11 |
| 12 #include "core/fxcrt/include/fx_basic.h" | 12 #include "core/fxcrt/include/fx_basic.h" |
| 13 #include "third_party/base/numerics/safe_math.h" | 13 #include "third_party/base/numerics/safe_math.h" |
| 14 | 14 |
| 15 template class CFX_StringDataTemplate<FX_CHAR>; | 15 template class CFX_StringDataTemplate<FX_CHAR>; |
| 16 template class CFX_StringCTemplate<FX_CHAR>; |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 int Buffer_itoa(char* buf, int i, uint32_t flags) { | 20 int Buffer_itoa(char* buf, int i, uint32_t flags) { |
| 20 if (i == 0) { | 21 if (i == 0) { |
| 21 buf[0] = '0'; | 22 buf[0] = '0'; |
| 22 return 1; | 23 return 1; |
| 23 } | 24 } |
| 24 char buf1[32]; | 25 char buf1[32]; |
| 25 int buf_pos = 31; | 26 int buf_pos = 31; |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 TrimLeft(CFX_ByteStringC(chTarget)); | 925 TrimLeft(CFX_ByteStringC(chTarget)); |
| 925 } | 926 } |
| 926 | 927 |
| 927 void CFX_ByteString::TrimLeft() { | 928 void CFX_ByteString::TrimLeft() { |
| 928 TrimLeft("\x09\x0a\x0b\x0c\x0d\x20"); | 929 TrimLeft("\x09\x0a\x0b\x0c\x0d\x20"); |
| 929 } | 930 } |
| 930 | 931 |
| 931 uint32_t CFX_ByteString::GetID(FX_STRSIZE start_pos) const { | 932 uint32_t CFX_ByteString::GetID(FX_STRSIZE start_pos) const { |
| 932 return AsStringC().GetID(start_pos); | 933 return AsStringC().GetID(start_pos); |
| 933 } | 934 } |
| 934 uint32_t CFX_ByteStringC::GetID(FX_STRSIZE start_pos) const { | |
| 935 if (m_Length == 0) { | |
| 936 return 0; | |
| 937 } | |
| 938 if (start_pos < 0 || start_pos >= m_Length) { | |
| 939 return 0; | |
| 940 } | |
| 941 uint32_t strid = 0; | |
| 942 if (start_pos + 4 > m_Length) { | |
| 943 for (FX_STRSIZE i = 0; i < m_Length - start_pos; i++) { | |
| 944 strid = strid * 256 + m_Ptr[start_pos + i]; | |
| 945 } | |
| 946 strid = strid << ((4 - m_Length + start_pos) * 8); | |
| 947 } else { | |
| 948 for (int i = 0; i < 4; i++) { | |
| 949 strid = strid * 256 + m_Ptr[start_pos + i]; | |
| 950 } | |
| 951 } | |
| 952 return strid; | |
| 953 } | |
| 954 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) { | 935 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) { |
| 955 buf[0] = '0'; | 936 buf[0] = '0'; |
| 956 buf[1] = '\0'; | 937 buf[1] = '\0'; |
| 957 if (d == 0.0f) { | 938 if (d == 0.0f) { |
| 958 return 1; | 939 return 1; |
| 959 } | 940 } |
| 960 FX_BOOL bNegative = FALSE; | 941 FX_BOOL bNegative = FALSE; |
| 961 if (d < 0) { | 942 if (d < 0) { |
| 962 bNegative = TRUE; | 943 bNegative = TRUE; |
| 963 d = -d; | 944 d = -d; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 fraction %= scale; | 976 fraction %= scale; |
| 996 scale /= 10; | 977 scale /= 10; |
| 997 } | 978 } |
| 998 return buf_size; | 979 return buf_size; |
| 999 } | 980 } |
| 1000 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 981 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 1001 FX_CHAR buf[32]; | 982 FX_CHAR buf[32]; |
| 1002 FX_STRSIZE len = FX_ftoa(d, buf); | 983 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1003 return CFX_ByteString(buf, len); | 984 return CFX_ByteString(buf, len); |
| 1004 } | 985 } |
| OLD | NEW |