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> |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 nCount = 0; | 434 nCount = 0; |
435 } | 435 } |
436 if (nCount >= m_pData->m_nDataLength) { | 436 if (nCount >= m_pData->m_nDataLength) { |
437 return *this; | 437 return *this; |
438 } | 438 } |
439 CFX_WideString dest; | 439 CFX_WideString dest; |
440 AllocCopy(dest, nCount, 0); | 440 AllocCopy(dest, nCount, 0); |
441 return dest; | 441 return dest; |
442 } | 442 } |
443 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const { | 443 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const { |
| 444 if (!m_pData) |
| 445 return CFX_WideString(); |
| 446 |
444 return Mid(nFirst, m_pData->m_nDataLength - nFirst); | 447 return Mid(nFirst, m_pData->m_nDataLength - nFirst); |
445 } | 448 } |
446 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { | 449 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { |
447 if (!m_pData) { | 450 if (!m_pData) |
448 return CFX_WideString(); | 451 return CFX_WideString(); |
449 } | 452 |
450 if (nFirst < 0) { | 453 nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength); |
451 nFirst = 0; | 454 nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst); |
452 } | 455 if (nFirst == 0 && nCount == m_pData->m_nDataLength) |
453 if (nCount < 0) { | |
454 nCount = 0; | |
455 } | |
456 if (nFirst + nCount > m_pData->m_nDataLength) { | |
457 nCount = m_pData->m_nDataLength - nFirst; | |
458 } | |
459 if (nFirst > m_pData->m_nDataLength) { | |
460 nCount = 0; | |
461 } | |
462 if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { | |
463 return *this; | 456 return *this; |
464 } | 457 |
465 CFX_WideString dest; | 458 CFX_WideString dest; |
466 AllocCopy(dest, nCount, nFirst); | 459 AllocCopy(dest, nCount, nFirst); |
467 return dest; | 460 return dest; |
468 } | 461 } |
469 CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { | 462 CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { |
470 if (!m_pData) { | 463 if (!m_pData) { |
471 return CFX_WideString(); | 464 return CFX_WideString(); |
472 } | 465 } |
473 if (nCount < 0) { | 466 if (nCount < 0) { |
474 nCount = 0; | 467 nCount = 0; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 int dest_len = | 1034 int dest_len = |
1042 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); | 1035 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); |
1043 CFX_WideString wstr; | 1036 CFX_WideString wstr; |
1044 if (dest_len) { | 1037 if (dest_len) { |
1045 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); | 1038 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); |
1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); | 1039 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); |
1047 wstr.ReleaseBuffer(dest_len); | 1040 wstr.ReleaseBuffer(dest_len); |
1048 } | 1041 } |
1049 return wstr; | 1042 return wstr; |
1050 } | 1043 } |
OLD | NEW |