Change CXFA_TextProvider::GetEmbeddedObj() to take a string view

Take a string view instead of a string, since that is what
GetEmbeddedObj() needs internally. In turn, change its only caller to
create a string view and operate on the view instead of modifying the
actual string.

Change-Id: Ie8d2de2ca6e7291d0ade2abcd9d8b9ed7ce1084e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/145974
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index f0395b6..da817f4 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -546,12 +546,13 @@
     return std::nullopt;
   }
 
-  WideString wsAttr = pElement->GetAttribute(L"xfa:embed");
-  if (wsAttr.IsEmpty()) {
+  WideString embed_attr = pElement->GetAttribute(L"xfa:embed");
+  WideStringView embed_attr_view = embed_attr.AsStringView();
+  if (embed_attr_view.IsEmpty()) {
     return std::nullopt;
   }
-  if (wsAttr.Front() == L'#') {
-    wsAttr.Delete(0);
+  if (embed_attr_view.Front() == L'#') {
+    embed_attr_view = embed_attr_view.Substr(1);
   }
 
   WideString ws =
@@ -566,7 +567,7 @@
     return std::nullopt;
   }
 
-  return pTextProvider->GetEmbeddedObj(wsAttr);
+  return pTextProvider->GetEmbeddedObj(embed_attr_view);
 }
 
 CXFA_TextParser::Context* CXFA_TextParser::GetParseContextFromMap(
diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp
index 29a750d..ada67c0 100644
--- a/xfa/fxfa/cxfa_textprovider.cpp
+++ b/xfa/fxfa/cxfa_textprovider.cpp
@@ -141,7 +141,7 @@
 }
 
 std::optional<WideString> CXFA_TextProvider::GetEmbeddedObj(
-    const WideString& wsAttr) const {
+    WideStringView embed_attr) const {
   if (type_ != Type::kText) {
     return std::nullopt;
   }
@@ -150,13 +150,12 @@
   CXFA_Document* document = node_->GetDocument();
   CXFA_Node* pIDNode = nullptr;
   if (pParent) {
-    pIDNode = document->GetNodeByID(pParent, wsAttr.AsStringView());
+    pIDNode = document->GetNodeByID(pParent, embed_attr);
   }
 
   if (!pIDNode) {
-    pIDNode =
-        document->GetNodeByID(ToNode(document->GetXFAObject(XFA_HASHCODE_Form)),
-                              wsAttr.AsStringView());
+    pIDNode = document->GetNodeByID(
+        ToNode(document->GetXFAObject(XFA_HASHCODE_Form)), embed_attr);
   }
   if (!pIDNode || !pIDNode->IsWidgetReady()) {
     return std::nullopt;
diff --git a/xfa/fxfa/cxfa_textprovider.h b/xfa/fxfa/cxfa_textprovider.h
index a998701..aff6b6b 100644
--- a/xfa/fxfa/cxfa_textprovider.h
+++ b/xfa/fxfa/cxfa_textprovider.h
@@ -38,7 +38,7 @@
   CXFA_Para* GetParaIfExists();
   CXFA_Font* GetFontIfExists();
   bool IsCheckButtonAndAutoWidth() const;
-  std::optional<WideString> GetEmbeddedObj(const WideString& wsAttr) const;
+  std::optional<WideString> GetEmbeddedObj(WideStringView embed_attr) const;
 
  private:
   CXFA_TextProvider(CXFA_Node* pNode, Type eType);