Use span in cxfa_itemlayoutprocessor.cpp's SeparateStringW() Also remove arg that is always passed as space and rename to indicate this fact. Change-Id: I795014ae9982d7e18e536ee1d55332fcba933603 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52655 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp index d0bfa10..ddae0cc 100644 --- a/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/layout/cxfa_itemlayoutprocessor.cpp
@@ -36,26 +36,22 @@ namespace { -std::vector<WideString> SeparateStringW(const wchar_t* pStr, - int32_t iStrLen, - wchar_t delimiter) { +std::vector<WideString> SeparateStringOnSpace( + pdfium::span<const wchar_t> spStr) { std::vector<WideString> ret; - if (!pStr) + if (spStr.empty()) return ret; - if (iStrLen < 0) - iStrLen = wcslen(pStr); - const wchar_t* pToken = pStr; - const wchar_t* pEnd = pStr + iStrLen; - while (true) { - if (pStr >= pEnd || delimiter == *pStr) { - ret.push_back(WideString(pToken, pStr - pToken)); - pToken = pStr + 1; - if (pStr >= pEnd) - break; + size_t nPos = 0; + size_t nToken = 0; + while (nPos < spStr.size()) { + if (spStr[nPos] == L' ') { + ret.emplace_back(WideStringView(spStr.subspan(nToken, nPos - nToken))); + nToken = nPos + 1; } - pStr++; + nPos++; } + ret.emplace_back(WideStringView(spStr.subspan(nToken, nPos - nToken))); return ret; } @@ -1160,9 +1156,7 @@ WideString wsColumnWidths = pLayoutNode->JSObject()->GetCData(XFA_Attribute::ColumnWidths); if (!wsColumnWidths.IsEmpty()) { - auto widths = SeparateStringW(wsColumnWidths.c_str(), - wsColumnWidths.GetLength(), L' '); - for (auto& width : widths) { + for (auto& width : SeparateStringOnSpace(wsColumnWidths.AsSpan())) { width.TrimLeft(L' '); if (width.IsEmpty()) continue;