| 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> // For offsetof(). | 7 #include <stddef.h> |
| 8 |
| 8 #include <cctype> | 9 #include <cctype> |
| 9 | 10 |
| 10 #include "core/include/fxcrt/fx_basic.h" | 11 #include "core/include/fxcrt/fx_basic.h" |
| 11 #include "third_party/base/numerics/safe_math.h" | 12 #include "third_party/base/numerics/safe_math.h" |
| 12 | 13 |
| 13 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { | 14 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) { |
| 14 if (i == 0) { | 15 if (i == 0) { |
| 15 buf[0] = '0'; | 16 buf[0] = '0'; |
| 16 return 1; | 17 return 1; |
| 17 } | 18 } |
| 18 char buf1[32]; | 19 char buf1[32]; |
| 19 int buf_pos = 31; | 20 int buf_pos = 31; |
| 20 FX_DWORD u = i; | 21 FX_DWORD u = i; |
| 21 if ((flags & FXFORMAT_SIGNED) && i < 0) { | 22 if ((flags & FXFORMAT_SIGNED) && i < 0) { |
| 22 u = -i; | 23 u = -i; |
| 23 } | 24 } |
| 24 int base = 10; | 25 int base = 10; |
| 25 const FX_CHAR* string = "0123456789abcdef"; | 26 const FX_CHAR* str = "0123456789abcdef"; |
| 26 if (flags & FXFORMAT_HEX) { | 27 if (flags & FXFORMAT_HEX) { |
| 27 base = 16; | 28 base = 16; |
| 28 if (flags & FXFORMAT_CAPITAL) { | 29 if (flags & FXFORMAT_CAPITAL) { |
| 29 string = "0123456789ABCDEF"; | 30 str = "0123456789ABCDEF"; |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 while (u != 0) { | 33 while (u != 0) { |
| 33 buf1[buf_pos--] = string[u % base]; | 34 buf1[buf_pos--] = str[u % base]; |
| 34 u = u / base; | 35 u = u / base; |
| 35 } | 36 } |
| 36 if ((flags & FXFORMAT_SIGNED) && i < 0) { | 37 if ((flags & FXFORMAT_SIGNED) && i < 0) { |
| 37 buf1[buf_pos--] = '-'; | 38 buf1[buf_pos--] = '-'; |
| 38 } | 39 } |
| 39 int len = 31 - buf_pos; | 40 int len = 31 - buf_pos; |
| 40 for (int ii = 0; ii < len; ii++) { | 41 for (int ii = 0; ii < len; ii++) { |
| 41 buf[ii] = buf1[ii + buf_pos + 1]; | 42 buf[ii] = buf1[ii + buf_pos + 1]; |
| 42 } | 43 } |
| 43 return len; | 44 return len; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const CFX_ByteString& CFX_ByteString::operator+=(const FX_CHAR* lpsz) { | 196 const CFX_ByteString& CFX_ByteString::operator+=(const FX_CHAR* lpsz) { |
| 196 if (lpsz) { | 197 if (lpsz) { |
| 197 ConcatInPlace(FXSYS_strlen(lpsz), lpsz); | 198 ConcatInPlace(FXSYS_strlen(lpsz), lpsz); |
| 198 } | 199 } |
| 199 return *this; | 200 return *this; |
| 200 } | 201 } |
| 201 const CFX_ByteString& CFX_ByteString::operator+=(char ch) { | 202 const CFX_ByteString& CFX_ByteString::operator+=(char ch) { |
| 202 ConcatInPlace(1, &ch); | 203 ConcatInPlace(1, &ch); |
| 203 return *this; | 204 return *this; |
| 204 } | 205 } |
| 205 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& string) { | 206 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& str) { |
| 206 if (!string.m_pData) { | 207 if (!str.m_pData) { |
| 207 return *this; | 208 return *this; |
| 208 } | 209 } |
| 209 ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); | 210 ConcatInPlace(str.m_pData->m_nDataLength, str.m_pData->m_String); |
| 210 return *this; | 211 return *this; |
| 211 } | 212 } |
| 212 const CFX_ByteString& CFX_ByteString::operator+=( | 213 const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { |
| 213 const CFX_ByteStringC& string) { | 214 if (str.IsEmpty()) { |
| 214 if (string.IsEmpty()) { | |
| 215 return *this; | 215 return *this; |
| 216 } | 216 } |
| 217 ConcatInPlace(string.GetLength(), string.GetCStr()); | 217 ConcatInPlace(str.GetLength(), str.GetCStr()); |
| 218 return *this; | 218 return *this; |
| 219 } | 219 } |
| 220 bool CFX_ByteString::Equal(const char* ptr) const { | 220 bool CFX_ByteString::Equal(const char* ptr) const { |
| 221 if (!m_pData) { | 221 if (!m_pData) { |
| 222 return !ptr || ptr[0] == '\0'; | 222 return !ptr || ptr[0] == '\0'; |
| 223 } | 223 } |
| 224 if (!ptr) { | 224 if (!ptr) { |
| 225 return m_pData->m_nDataLength == 0; | 225 return m_pData->m_nDataLength == 0; |
| 226 } | 226 } |
| 227 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && | 227 return FXSYS_strlen(ptr) == m_pData->m_nDataLength && |
| (...skipping 851 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 |