From b7973bb5a0ad2f83a71362d601a928964559004a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 17 Apr 2018 16:41:28 +0000 Subject: Reland "Return pdfium::span from WideString::GetBuffer()."" This reverts commit 0d32b8fda53e02c1036d39f7290d4f59f2b58ca4. Restore behaviour on trunk. TBR: dsinclair@chromium.org Change-Id: Ia867f09ae9d2885595c4d9b300a058431dfd84f2 Reviewed-on: https://pdfium-review.googlesource.com/30811 Reviewed-by: Tom Sepez Commit-Queue: Tom Sepez --- xfa/fxfa/cxfa_textlayout.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'xfa/fxfa/cxfa_textlayout.cpp') diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index e066380f77..67b9ca4cb1 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -911,21 +911,23 @@ void CXFA_TextLayout::ProcessText(WideString& wsText) { if (iLen == 0) return; - wchar_t* psz = wsText.GetBuffer(iLen); int32_t iTrimLeft = 0; - wchar_t wch = 0, wPrev = 0; - for (int32_t i = 0; i < iLen; i++) { - wch = psz[i]; - if (wch < 0x20) - wch = 0x20; - if (wch == 0x20 && wPrev == 0x20) - continue; - - wPrev = wch; - psz[iTrimLeft++] = wch; + { + // Span's lifetime must end before ReleaseBuffer() below. + pdfium::span psz = wsText.GetBuffer(iLen); + wchar_t wPrev = 0; + for (int32_t i = 0; i < iLen; i++) { + wchar_t wch = psz[i]; + if (wch < 0x20) + wch = 0x20; + if (wch == 0x20 && wPrev == 0x20) + continue; + + wPrev = wch; + psz[iTrimLeft++] = wch; + } } - wsText.ReleaseBuffer(iLen); - wsText = wsText.Left(iTrimLeft); + wsText.ReleaseBuffer(iTrimLeft); } void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, -- cgit v1.2.3