Use span<> in CXFA_TextParser::GetTabstops().
Also add a missing const in string_view_template.h to fix
compilation issue.
Change-Id: Ieb22dc80197d969833b11534a83ff7da0643a7a2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52650
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h
index 6cf80db..df9e36f 100644
--- a/core/fxcrt/string_view_template.h
+++ b/core/fxcrt/string_view_template.h
@@ -47,7 +47,7 @@
: m_Span(reinterpret_cast<const UnsignedType*>(ptr), len) {}
explicit constexpr StringViewTemplate(
- const pdfium::span<CharType>& other) noexcept
+ const pdfium::span<const CharType>& other) noexcept
: m_Span(reinterpret_cast<const UnsignedType*>(other.data()),
other.size()) {}
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index d989f2c..53a5858 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -554,15 +554,13 @@
return false;
}
- int32_t iLength = wsValue.GetLength();
- const wchar_t* pTabStops = wsValue.c_str();
- int32_t iCur = 0;
- int32_t iLast = 0;
+ pdfium::span<const wchar_t> spTabStops = wsValue.AsSpan();
+ size_t iCur = 0;
+ size_t iLast = 0;
WideString wsAlign;
TabStopStatus eStatus = TabStopStatus::None;
- wchar_t ch;
- while (iCur < iLength) {
- ch = pTabStops[iCur];
+ while (iCur < spTabStops.size()) {
+ wchar_t ch = spTabStops[iCur];
switch (eStatus) {
case TabStopStatus::None:
if (ch <= ' ') {
@@ -574,10 +572,10 @@
break;
case TabStopStatus::Alignment:
if (ch == ' ') {
- wsAlign = WideStringView(pTabStops + iLast, iCur - iLast);
+ wsAlign = WideStringView(spTabStops.subspan(iLast, iCur - iLast));
eStatus = TabStopStatus::StartLeader;
iCur++;
- while (iCur < iLength && pTabStops[iCur] <= ' ')
+ while (iCur < spTabStops.size() && spTabStops[iCur] <= ' ')
iCur++;
iLast = iCur;
} else {
@@ -589,8 +587,8 @@
eStatus = TabStopStatus::Location;
} else {
int32_t iCount = 0;
- while (iCur < iLength) {
- ch = pTabStops[iCur];
+ while (iCur < spTabStops.size()) {
+ ch = spTabStops[iCur];
iCur++;
if (ch == '(') {
iCount++;
@@ -600,7 +598,7 @@
break;
}
}
- while (iCur < iLength && pTabStops[iCur] <= ' ')
+ while (iCur < spTabStops.size() && spTabStops[iCur] <= ' ')
iCur++;
iLast = iCur;
@@ -610,7 +608,8 @@
case TabStopStatus::Location:
if (ch == ' ') {
uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringView(), true);
- CXFA_Measurement ms(WideStringView(pTabStops + iLast, iCur - iLast));
+ CXFA_Measurement ms(
+ WideStringView(spTabStops.subspan(iLast, iCur - iLast)));
float fPos = ms.ToUnit(XFA_Unit::Pt);
pTabstopContext->Append(dwHashCode, fPos);
wsAlign.clear();
@@ -625,7 +624,8 @@
if (!wsAlign.IsEmpty()) {
uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringView(), true);
- CXFA_Measurement ms(WideStringView(pTabStops + iLast, iCur - iLast));
+ CXFA_Measurement ms(
+ WideStringView(spTabStops.subspan(iLast, iCur - iLast)));
float fPos = ms.ToUnit(XFA_Unit::Pt);
pTabstopContext->Append(dwHashCode, fPos);
}