| 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 <cctype> | 9 #include <cctype> |
| 10 | 10 |
| 11 #include "core/fxcrt/include/fx_basic.h" | 11 #include "core/fxcrt/include/fx_basic.h" |
| 12 #include "third_party/base/numerics/safe_math.h" | 12 #include "third_party/base/numerics/safe_math.h" |
| 13 | 13 |
| 14 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { | 14 static int _Buffer_itoa(char* buf, int i, uint32_t flags) { |
| 15 if (i == 0) { | 15 if (i == 0) { |
| 16 buf[0] = '0'; | 16 buf[0] = '0'; |
| 17 return 1; | 17 return 1; |
| 18 } | 18 } |
| 19 char buf1[32]; | 19 char buf1[32]; |
| 20 int buf_pos = 31; | 20 int buf_pos = 31; |
| 21 FX_DWORD u = i; | 21 uint32_t u = i; |
| 22 if ((flags & FXFORMAT_SIGNED) && i < 0) { | 22 if ((flags & FXFORMAT_SIGNED) && i < 0) { |
| 23 u = -i; | 23 u = -i; |
| 24 } | 24 } |
| 25 int base = 10; | 25 int base = 10; |
| 26 const FX_CHAR* str = "0123456789abcdef"; | 26 const FX_CHAR* str = "0123456789abcdef"; |
| 27 if (flags & FXFORMAT_HEX) { | 27 if (flags & FXFORMAT_HEX) { |
| 28 base = 16; | 28 base = 16; |
| 29 if (flags & FXFORMAT_CAPITAL) { | 29 if (flags & FXFORMAT_CAPITAL) { |
| 30 str = "0123456789ABCDEF"; | 30 str = "0123456789ABCDEF"; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 while (u != 0) { | 33 while (u != 0) { |
| 34 buf1[buf_pos--] = str[u % base]; | 34 buf1[buf_pos--] = str[u % base]; |
| 35 u = u / base; | 35 u = u / base; |
| 36 } | 36 } |
| 37 if ((flags & FXFORMAT_SIGNED) && i < 0) { | 37 if ((flags & FXFORMAT_SIGNED) && i < 0) { |
| 38 buf1[buf_pos--] = '-'; | 38 buf1[buf_pos--] = '-'; |
| 39 } | 39 } |
| 40 int len = 31 - buf_pos; | 40 int len = 31 - buf_pos; |
| 41 for (int ii = 0; ii < len; ii++) { | 41 for (int ii = 0; ii < len; ii++) { |
| 42 buf[ii] = buf1[ii + buf_pos + 1]; | 42 buf[ii] = buf1[ii + buf_pos + 1]; |
| 43 } | 43 } |
| 44 return len; | 44 return len; |
| 45 } | 45 } |
| 46 CFX_ByteString CFX_ByteString::FormatInteger(int i, FX_DWORD flags) { | 46 CFX_ByteString CFX_ByteString::FormatInteger(int i, uint32_t flags) { |
| 47 char buf[32]; | 47 char buf[32]; |
| 48 return CFX_ByteStringC(buf, _Buffer_itoa(buf, i, flags)); | 48 return CFX_ByteStringC(buf, _Buffer_itoa(buf, i, flags)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 CFX_ByteString::StringData* CFX_ByteString::StringData::Create(int nLen) { | 52 CFX_ByteString::StringData* CFX_ByteString::StringData::Create(int nLen) { |
| 53 // |nLen| is currently declared as in |int|. TODO(palmer): It should be | 53 // |nLen| is currently declared as in |int|. TODO(palmer): It should be |
| 54 // a |size_t|, or at least unsigned. | 54 // a |size_t|, or at least unsigned. |
| 55 if (nLen == 0 || nLen < 0) { | 55 if (nLen == 0 || nLen < 0) { |
| 56 return NULL; | 56 return NULL; |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 (nDataLength + 1) * sizeof(FX_CHAR)); | 1005 (nDataLength + 1) * sizeof(FX_CHAR)); |
| 1006 m_pData->m_nDataLength = nDataLength; | 1006 m_pData->m_nDataLength = nDataLength; |
| 1007 } | 1007 } |
| 1008 } | 1008 } |
| 1009 void CFX_ByteString::TrimLeft(FX_CHAR chTarget) { | 1009 void CFX_ByteString::TrimLeft(FX_CHAR chTarget) { |
| 1010 TrimLeft(CFX_ByteStringC(chTarget)); | 1010 TrimLeft(CFX_ByteStringC(chTarget)); |
| 1011 } | 1011 } |
| 1012 void CFX_ByteString::TrimLeft() { | 1012 void CFX_ByteString::TrimLeft() { |
| 1013 TrimLeft("\x09\x0a\x0b\x0c\x0d\x20"); | 1013 TrimLeft("\x09\x0a\x0b\x0c\x0d\x20"); |
| 1014 } | 1014 } |
| 1015 FX_DWORD CFX_ByteString::GetID(FX_STRSIZE start_pos) const { | 1015 uint32_t CFX_ByteString::GetID(FX_STRSIZE start_pos) const { |
| 1016 return CFX_ByteStringC(*this).GetID(start_pos); | 1016 return CFX_ByteStringC(*this).GetID(start_pos); |
| 1017 } | 1017 } |
| 1018 FX_DWORD CFX_ByteStringC::GetID(FX_STRSIZE start_pos) const { | 1018 uint32_t CFX_ByteStringC::GetID(FX_STRSIZE start_pos) const { |
| 1019 if (m_Length == 0) { | 1019 if (m_Length == 0) { |
| 1020 return 0; | 1020 return 0; |
| 1021 } | 1021 } |
| 1022 if (start_pos < 0 || start_pos >= m_Length) { | 1022 if (start_pos < 0 || start_pos >= m_Length) { |
| 1023 return 0; | 1023 return 0; |
| 1024 } | 1024 } |
| 1025 FX_DWORD strid = 0; | 1025 uint32_t strid = 0; |
| 1026 if (start_pos + 4 > m_Length) { | 1026 if (start_pos + 4 > m_Length) { |
| 1027 for (FX_STRSIZE i = 0; i < m_Length - start_pos; i++) { | 1027 for (FX_STRSIZE i = 0; i < m_Length - start_pos; i++) { |
| 1028 strid = strid * 256 + m_Ptr[start_pos + i]; | 1028 strid = strid * 256 + m_Ptr[start_pos + i]; |
| 1029 } | 1029 } |
| 1030 strid = strid << ((4 - m_Length + start_pos) * 8); | 1030 strid = strid << ((4 - m_Length + start_pos) * 8); |
| 1031 } else { | 1031 } else { |
| 1032 for (int i = 0; i < 4; i++) { | 1032 for (int i = 0; i < 4; i++) { |
| 1033 strid = strid * 256 + m_Ptr[start_pos + i]; | 1033 strid = strid * 256 + m_Ptr[start_pos + i]; |
| 1034 } | 1034 } |
| 1035 } | 1035 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 fraction %= scale; | 1079 fraction %= scale; |
| 1080 scale /= 10; | 1080 scale /= 10; |
| 1081 } | 1081 } |
| 1082 return buf_size; | 1082 return buf_size; |
| 1083 } | 1083 } |
| 1084 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { | 1084 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) { |
| 1085 FX_CHAR buf[32]; | 1085 FX_CHAR buf[32]; |
| 1086 FX_STRSIZE len = FX_ftoa(d, buf); | 1086 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1087 return CFX_ByteString(buf, len); | 1087 return CFX_ByteString(buf, len); |
| 1088 } | 1088 } |
| OLD | NEW |