Re-work some more c_str() usage.

Many of these are converting ByteString => c_str => ByteStringView, since
the ByteStringView ctor is implicit. This is unfortunate, since that
involves a strlen() which the ByteString already knows if we use
AsStringView() instead.

This changed one test result where we can now return the string
"\0" instead of "" -- since strlen no longer eats the NUL. This
seems consistent, say, with String.fromCharCode().

Change-Id: I17f68d1a1f4b352960208f9148e68ab4c4d78bd2
Reviewed-on: https://pdfium-review.googlesource.com/35590
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index ff8d4bb..f8beccb 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -214,10 +214,7 @@
           return false;
         break;
       }
-      CPDF_Encryptor encryptor(
-          GetCryptoHandler(), objnum,
-          pdfium::make_span(reinterpret_cast<const uint8_t*>(str.c_str()),
-                            str.GetLength()));
+      CPDF_Encryptor encryptor(GetCryptoHandler(), objnum, str.AsRawSpan());
       ByteString content = PDF_EncodeString(
           ByteString(encryptor.GetSpan().data(), encryptor.GetSpan().size()),
           bHex);
@@ -506,12 +503,12 @@
       else
         str = ByteString::Format("%d %d\r\n", i, j - i);
 
-      if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
+      if (!m_Archive->WriteString(str.AsStringView()))
         return -1;
 
       while (i < j) {
         str = ByteString::Format("%010d 00000 n\r\n", m_ObjectOffsets[i++]);
-        if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
+        if (!m_Archive->WriteString(str.AsStringView()))
           return -1;
       }
       if (i > dwLastObjNum)
@@ -540,13 +537,13 @@
       else
         str = ByteString::Format("%d %d\r\n", objnum, j - i);
 
-      if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
+      if (!m_Archive->WriteString(str.AsStringView()))
         return -1;
 
       while (i < j) {
         objnum = m_NewObjNumArray[i++];
         str = ByteString::Format("%010d 00000 n\r\n", m_ObjectOffsets[objnum]);
-        if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
+        if (!m_Archive->WriteString(str.AsStringView()))
           return -1;
       }
     }
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 386ea95..3f9f303 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -405,7 +405,7 @@
     return;
 
   ByteString csTitle = pInfoDict->GetStringFor("Title");
-  wsTitle = WideString::FromLocal(csTitle.c_str());
+  wsTitle = WideString::FromLocal(csTitle.AsStringView());
 }
 
 void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc,
diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp
index aa612f0..c17c146 100644
--- a/fpdfsdk/pwl/cpwl_appstream.cpp
+++ b/fpdfsdk/pwl/cpwl_appstream.cpp
@@ -1949,8 +1949,7 @@
   }
   pStreamDict->SetMatrixFor("Matrix", widget_->GetMatrix());
   pStreamDict->SetRectFor("BBox", widget_->GetRotatedRect());
-  pStream->SetDataAndRemoveFilter((uint8_t*)(sContents.c_str()),
-                                  sContents.GetLength());
+  pStream->SetDataAndRemoveFilter(sContents.raw_str(), sContents.GetLength());
 }
 
 void CPWL_AppStream::Remove(const ByteString& sAPType) {
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp
index 8a53ebc..49db204 100644
--- a/fxjs/cjs_annot.cpp
+++ b/fxjs/cjs_annot.cpp
@@ -81,8 +81,8 @@
 CJS_Return CJS_Annot::get_name(CJS_Runtime* pRuntime) {
   if (!m_pAnnot)
     return CJS_Return(JSMessage::kBadObjectError);
-  return CJS_Return(
-      pRuntime->NewString(ToBAAnnot(m_pAnnot.Get())->GetAnnotName().c_str()));
+  return CJS_Return(pRuntime->NewString(
+      ToBAAnnot(m_pAnnot.Get())->GetAnnotName().AsStringView()));
 }
 
 CJS_Return CJS_Annot::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
@@ -101,8 +101,8 @@
   return CJS_Return(pRuntime->NewString(
       WideString::FromLocal(CPDF_Annot::AnnotSubtypeToString(
                                 ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype())
-                                .c_str())
-          .c_str()));
+                                .AsStringView())
+          .AsStringView()));
 }
 
 CJS_Return CJS_Annot::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index 61eb632..36a1212 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -176,9 +176,9 @@
   if (!pFormFillEnv)
     return CJS_Return(JSMessage::kBadObjectError);
 
-  WideString platfrom = pFormFillEnv->GetPlatform();
-  if (!platfrom.IsEmpty())
-    return CJS_Return(pRuntime->NewString(platfrom.c_str()));
+  WideString platform = pFormFillEnv->GetPlatform();
+  if (!platform.IsEmpty())
+    return CJS_Return(pRuntime->NewString(platform.AsStringView()));
 #endif
   return CJS_Return(pRuntime->NewString(JS_STR_PLATFORM));
 }
@@ -196,7 +196,7 @@
 
   WideString language = pFormFillEnv->GetLanguage();
   if (!language.IsEmpty())
-    return CJS_Return(pRuntime->NewString(language.c_str()));
+    return CJS_Return(pRuntime->NewString(language.AsStringView()));
 #endif
   return CJS_Return(pRuntime->NewString(JS_STR_LANGUAGE));
 }
@@ -572,7 +572,7 @@
   return CJS_Return(pRuntime->NewString(
       WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
                               nLengthBytes / sizeof(uint16_t))
-          .c_str()));
+          .AsStringView()));
 }
 
 CJS_Return CJS_App::get_media(CJS_Runtime* pRuntime) {
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 74304bb..b22d31b 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -279,7 +279,7 @@
   CPDF_FormField* pField = pPDFForm->GetField(nIndex, WideString());
   if (!pField)
     return CJS_Return(JSMessage::kBadObjectError);
-  return CJS_Return(pRuntime->NewString(pField->GetFullName().c_str()));
+  return CJS_Return(pRuntime->NewString(pField->GetFullName().AsStringView()));
 }
 
 CJS_Return CJS_Document::importAnFDF(
@@ -719,8 +719,8 @@
   CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
   if (!pDictionary)
     return CJS_Return(JSMessage::kBadObjectError);
-  return CJS_Return(
-      pRuntime->NewString(pDictionary->GetUnicodeTextFor(propName).c_str()));
+  return CJS_Return(pRuntime->NewString(
+      pDictionary->GetUnicodeTextFor(propName).AsStringView()));
 }
 
 CJS_Return CJS_Document::setPropertyInternal(CJS_Runtime* pRuntime,
@@ -889,7 +889,7 @@
   if (!m_pFormFillEnv)
     return CJS_Return(JSMessage::kBadObjectError);
   return CJS_Return(
-      pRuntime->NewString(m_pFormFillEnv->JS_docGetFilePath().c_str()));
+      pRuntime->NewString(m_pFormFillEnv->JS_docGetFilePath().AsStringView()));
 }
 
 CJS_Return CJS_Document::set_URL(CJS_Runtime* pRuntime,
@@ -898,7 +898,7 @@
 }
 
 CJS_Return CJS_Document::get_base_URL(CJS_Runtime* pRuntime) {
-  return CJS_Return(pRuntime->NewString(m_cwBaseURL.c_str()));
+  return CJS_Return(pRuntime->NewString(m_cwBaseURL.AsStringView()));
 }
 
 CJS_Return CJS_Document::set_base_URL(CJS_Runtime* pRuntime,
@@ -950,7 +950,8 @@
   if (!m_pFormFillEnv)
     return CJS_Return(JSMessage::kBadObjectError);
   return CJS_Return(pRuntime->NewString(
-      CJS_App::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()).c_str()));
+      CJS_App::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath())
+          .AsStringView()));
 }
 
 CJS_Return CJS_Document::set_path(CJS_Runtime* pRuntime,
@@ -1269,7 +1270,7 @@
 
   if (bStrip)
     swRet.Trim();
-  return CJS_Return(pRuntime->NewString(swRet.c_str()));
+  return CJS_Return(pRuntime->NewString(swRet.AsStringView()));
 }
 
 CJS_Return CJS_Document::getPageNthWordQuads(
diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp
index 397d8b8..c10f885 100644
--- a/fxjs/cjs_event.cpp
+++ b/fxjs/cjs_event.cpp
@@ -51,10 +51,9 @@
 
 CJS_Return CJS_Event::get_change(CJS_Runtime* pRuntime) {
   ASSERT(pRuntime->GetCurrentEventContext());
-
   CJS_EventHandler* pEvent =
       pRuntime->GetCurrentEventContext()->GetEventHandler();
-  return CJS_Return(pRuntime->NewString(pEvent->Change().c_str()));
+  return CJS_Return(pRuntime->NewString(pEvent->Change().AsStringView()));
 }
 
 CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime,
@@ -73,11 +72,10 @@
 
 CJS_Return CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
   ASSERT(pRuntime->GetCurrentEventContext());
-
   CJS_EventHandler* pEvent =
       pRuntime->GetCurrentEventContext()->GetEventHandler();
 
-  return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().c_str()));
+  return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
 }
 
 CJS_Return CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
@@ -256,7 +254,6 @@
 
 CJS_Return CJS_Event::get_target(CJS_Runtime* pRuntime) {
   ASSERT(pRuntime->GetCurrentEventContext());
-
   CJS_EventHandler* pEvent =
       pRuntime->GetCurrentEventContext()->GetEventHandler();
   return CJS_Return(pEvent->Target_Field()->ToV8Object());
@@ -269,10 +266,9 @@
 
 CJS_Return CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
   ASSERT(pRuntime->GetCurrentEventContext());
-
   CJS_EventHandler* pEvent =
       pRuntime->GetCurrentEventContext()->GetEventHandler();
-  return CJS_Return(pRuntime->NewString(pEvent->TargetName().c_str()));
+  return CJS_Return(pRuntime->NewString(pEvent->TargetName().AsStringView()));
 }
 
 CJS_Return CJS_Event::set_target_name(CJS_Runtime* pRuntime,
@@ -304,7 +300,7 @@
   if (!pEvent->m_pValue)
     return CJS_Return(JSMessage::kBadObjectError);
 
-  return CJS_Return(pRuntime->NewString(pEvent->Value().c_str()));
+  return CJS_Return(pRuntime->NewString(pEvent->Value().AsStringView()));
 }
 
 CJS_Return CJS_Event::set_value(CJS_Runtime* pRuntime,
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index e9aa777..8483586 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -890,7 +890,8 @@
     return CJS_Return(JSMessage::kObjectTypeError);
   }
 
-  return CJS_Return(pRuntime->NewString(pFormField->GetDefaultValue().c_str()));
+  return CJS_Return(
+      pRuntime->NewString(pFormField->GetDefaultValue().AsStringView()));
 }
 
 CJS_Return CJS_Field::set_default_value(CJS_Runtime* pRuntime,
@@ -1092,7 +1093,7 @@
       CPDF_FormControl* pFormControl = pFormField->GetControl(i);
       pRuntime->PutArrayElement(
           ExportValuesArray, i,
-          pRuntime->NewString(pFormControl->GetExportValue().c_str()));
+          pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
     }
   } else {
     if (m_nFormControlIndex >= pFormField->CountControls())
@@ -1105,7 +1106,7 @@
 
     pRuntime->PutArrayElement(
         ExportValuesArray, 0,
-        pRuntime->NewString(pFormControl->GetExportValue().c_str()));
+        pRuntime->NewString(pFormControl->GetExportValue().AsStringView()));
   }
   return CJS_Return(ExportValuesArray);
 }
@@ -1420,7 +1421,7 @@
   if (FieldArray.empty())
     return CJS_Return(JSMessage::kBadObjectError);
 
-  return CJS_Return(pRuntime->NewString(m_FieldName.c_str()));
+  return CJS_Return(pRuntime->NewString(m_FieldName.AsStringView()));
 }
 
 CJS_Return CJS_Field::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
@@ -1903,8 +1904,8 @@
       csBCaption = "check";
       break;
   }
-  return CJS_Return(
-      pRuntime->NewString(WideString::FromLocal(csBCaption.c_str()).c_str()));
+  return CJS_Return(pRuntime->NewString(
+      WideString::FromLocal(csBCaption.AsStringView()).AsStringView()));
 }
 
 CJS_Return CJS_Field::set_style(CJS_Runtime* pRuntime,
@@ -1993,7 +1994,8 @@
     return CJS_Return(JSMessage::kBadObjectError);
 
   return CJS_Return(pRuntime->NewString(
-      WideString::FromLocal(pFont->GetBaseFont().c_str()).c_str()));
+      WideString::FromLocal(pFont->GetBaseFont().AsStringView())
+          .AsStringView()));
 }
 
 CJS_Return CJS_Field::set_text_font(CJS_Runtime* pRuntime,
@@ -2074,7 +2076,7 @@
     return CJS_Return(JSMessage::kBadObjectError);
 
   return CJS_Return(
-      pRuntime->NewString(FieldArray[0]->GetAlternateName().c_str()));
+      pRuntime->NewString(FieldArray[0]->GetAlternateName().AsStringView()));
 }
 
 CJS_Return CJS_Field::set_user_name(CJS_Runtime* pRuntime,
@@ -2098,7 +2100,7 @@
       return CJS_Return(JSMessage::kObjectTypeError);
     case FormFieldType::kComboBox:
     case FormFieldType::kTextField:
-      ret = pRuntime->NewString(pFormField->GetValue().c_str());
+      ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
       break;
     case FormFieldType::kListBox: {
       if (pFormField->CountSelectedItems() > 1) {
@@ -2107,17 +2109,17 @@
         int iIndex;
         for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
           iIndex = pFormField->GetSelectedIndex(i);
-          ElementValue =
-              pRuntime->NewString(pFormField->GetOptionValue(iIndex).c_str());
+          ElementValue = pRuntime->NewString(
+              pFormField->GetOptionValue(iIndex).AsStringView());
           if (wcslen(pRuntime->ToWideString(ElementValue).c_str()) == 0) {
-            ElementValue =
-                pRuntime->NewString(pFormField->GetOptionLabel(iIndex).c_str());
+            ElementValue = pRuntime->NewString(
+                pFormField->GetOptionLabel(iIndex).AsStringView());
           }
           pRuntime->PutArrayElement(ValueArray, i, ElementValue);
         }
         ret = ValueArray;
       } else {
-        ret = pRuntime->NewString(pFormField->GetValue().c_str());
+        ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
       }
       break;
     }
@@ -2127,7 +2129,7 @@
       for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
         if (pFormField->GetControl(i)->IsChecked()) {
           ret = pRuntime->NewString(
-              pFormField->GetControl(i)->GetExportValue().c_str());
+              pFormField->GetControl(i)->GetExportValue().AsStringView());
           bFind = true;
           break;
         }
@@ -2138,7 +2140,7 @@
       break;
     }
     default:
-      ret = pRuntime->NewString(pFormField->GetValue().c_str());
+      ret = pRuntime->NewString(pFormField->GetValue().AsStringView());
       break;
   }
   return CJS_Return(pRuntime->MaybeCoerceToNumber(ret));
@@ -2245,7 +2247,7 @@
     for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
       if (pFormField->GetControl(i)->IsChecked()) {
         return CJS_Return(pRuntime->NewString(
-            pFormField->GetControl(i)->GetExportValue().c_str()));
+            pFormField->GetControl(i)->GetExportValue().AsStringView()));
       }
     }
     return CJS_Return(pRuntime->NewString(L"Off"));
@@ -2255,7 +2257,7 @@
       (pFormField->CountSelectedItems() > 1)) {
     return CJS_Return(pRuntime->NewString(L""));
   }
-  return CJS_Return(pRuntime->NewString(pFormField->GetValue().c_str()));
+  return CJS_Return(pRuntime->NewString(pFormField->GetValue().AsStringView()));
 }
 
 CJS_Return CJS_Field::set_value_as_string(CJS_Runtime* pRuntime,
@@ -2305,13 +2307,15 @@
 
   if (nface == 0) {
     return CJS_Return(
-        pRuntime->NewString(pFormControl->GetNormalCaption().c_str()));
-  } else if (nface == 1) {
+        pRuntime->NewString(pFormControl->GetNormalCaption().AsStringView()));
+  }
+  if (nface == 1) {
     return CJS_Return(
-        pRuntime->NewString(pFormControl->GetDownCaption().c_str()));
-  } else if (nface == 2) {
+        pRuntime->NewString(pFormControl->GetDownCaption().AsStringView()));
+  }
+  if (nface == 2) {
     return CJS_Return(
-        pRuntime->NewString(pFormControl->GetRolloverCaption().c_str()));
+        pRuntime->NewString(pFormControl->GetRolloverCaption().AsStringView()));
   }
   return CJS_Return(JSMessage::kValueError);
 }
@@ -2496,13 +2500,13 @@
     if (bExport) {
       WideString strval = pFormField->GetOptionValue(nIdx);
       if (strval.IsEmpty()) {
-        return CJS_Return(
-            pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
+        return CJS_Return(pRuntime->NewString(
+            pFormField->GetOptionLabel(nIdx).AsStringView()));
       }
-      return CJS_Return(pRuntime->NewString(strval.c_str()));
+      return CJS_Return(pRuntime->NewString(strval.AsStringView()));
     }
     return CJS_Return(
-        pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
+        pRuntime->NewString(pFormField->GetOptionLabel(nIdx).AsStringView()));
   }
   return CJS_Return(JSMessage::kObjectTypeError);
 }
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 977d916..e9b2a4b 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -248,7 +248,7 @@
       return CJS_Return(pRuntime->NewBoolean(pData->bData));
     case JS_GlobalDataType::STRING:
       return CJS_Return(pRuntime->NewString(
-          WideString::FromLocal(pData->sData.c_str()).c_str()));
+          WideString::FromLocal(pData->sData.AsStringView()).AsStringView()));
     case JS_GlobalDataType::OBJECT:
       return CJS_Return(
           v8::Local<v8::Object>::New(pRuntime->GetIsolate(), pData->pData));
diff --git a/fxjs/cjs_icon.cpp b/fxjs/cjs_icon.cpp
index 9cf20fe..3c293ea 100644
--- a/fxjs/cjs_icon.cpp
+++ b/fxjs/cjs_icon.cpp
@@ -30,7 +30,7 @@
 CJS_Icon::~CJS_Icon() = default;
 
 CJS_Return CJS_Icon::get_name(CJS_Runtime* pRuntime) {
-  return CJS_Return(pRuntime->NewString(m_swIconName.c_str()));
+  return CJS_Return(pRuntime->NewString(m_swIconName.AsStringView()));
 }
 
 CJS_Return CJS_Icon::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 4630445..2bc68fa 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -336,13 +336,13 @@
     if (!pTemp) {
       pRuntime->PutArrayElement(
           StrArray, nIndex,
-          pRuntime->NewString(StrTrim(ByteString(p)).c_str()));
+          pRuntime->NewString(StrTrim(ByteString(p)).AsStringView()));
       break;
     }
 
     pRuntime->PutArrayElement(
         StrArray, nIndex,
-        pRuntime->NewString(StrTrim(ByteString(p, pTemp - p)).c_str()));
+        pRuntime->NewString(StrTrim(ByteString(p, pTemp - p)).AsStringView()));
 
     nIndex++;
     p = ++pTemp;
@@ -1525,11 +1525,11 @@
     swValue = pEventHandler->Value();
 
   if (pEventHandler->WillCommit())
-    return CJS_Return(pRuntime->NewString(swValue.c_str()));
+    return CJS_Return(pRuntime->NewString(swValue.AsStringView()));
 
   WideString merged =
       CalcMergedString(pEventHandler, swValue, pEventHandler->Change());
-  return CJS_Return(pRuntime->NewString(merged.c_str()));
+  return CJS_Return(pRuntime->NewString(merged.AsStringView()));
 }
 
 CJS_Return CJS_PublicMethods::AFParseDateEx(
@@ -1571,7 +1571,7 @@
   NormalizeDecimalMarkW(&ws);
 
   v8::Local<v8::Value> val =
-      pRuntime->MaybeCoerceToNumber(pRuntime->NewString(ws.c_str()));
+      pRuntime->MaybeCoerceToNumber(pRuntime->NewString(ws.AsStringView()));
   if (!val->IsNumber())
     return CJS_Return(pRuntime->NewNumber(0));
   return CJS_Return(val);
@@ -1734,14 +1734,15 @@
       sPart += wc;
     } else if (sPart.GetLength() > 0) {
       pRuntime->PutArrayElement(nums, nIndex,
-                                pRuntime->NewString(sPart.c_str()));
+                                pRuntime->NewString(sPart.AsStringView()));
       sPart.clear();
       nIndex++;
     }
   }
-  if (sPart.GetLength() > 0)
-    pRuntime->PutArrayElement(nums, nIndex, pRuntime->NewString(sPart.c_str()));
-
+  if (sPart.GetLength() > 0) {
+    pRuntime->PutArrayElement(nums, nIndex,
+                              pRuntime->NewString(sPart.AsStringView()));
+  }
   if (pRuntime->GetArrayLength(nums) > 0)
     return CJS_Return(nums);
   return CJS_Return(pRuntime->NewUndefined());
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 576a85b..fec7273 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -387,7 +387,7 @@
     return CJS_Return(JSMessage::kValueError);
 
   WideString wStr(static_cast<wchar_t>(arg));
-  return CJS_Return(pRuntime->NewString(wStr.c_str()));
+  return CJS_Return(pRuntime->NewString(wStr.AsStringView()));
 }
 
 // Ensure that sFormat contains at most one well-understood printf formatting
diff --git a/testing/resources/javascript/util_bytetochar_expected.txt b/testing/resources/javascript/util_bytetochar_expected.txt
index df15ee7..487b89c 100644
--- a/testing/resources/javascript/util_bytetochar_expected.txt
+++ b/testing/resources/javascript/util_bytetochar_expected.txt
@@ -1,4 +1,4 @@
-Alert: 0 => 
+Alert: 0 => 0
 Alert: 65 => 65
 Alert: 127 => 127
 Alert: 128 => 128
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 71b413c..ce9d0a5 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -238,7 +238,7 @@
   text_out->SetStyles(style);
 
   size_t length = text.GetLength();
-  WideStringView temp(text.c_str(), length);
+  WideStringView temp = text.AsStringView();
 
   float vertical_height = line_spacing_ * visible_line_count_;
   size_t chars_exceeding_size = 0;
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index abd5aa7..59d4563 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -492,7 +492,7 @@
       continue;
 
     WideString wsFaceName =
-        WideString::FromLocal(pFontMapper->GetFaceName(i).c_str());
+        WideString::FromLocal(pFontMapper->GetFaceName(i).AsStringView());
     RegisterFaces(pFontStream, &wsFaceName);
   }