From b6b01cb2cbaf6b38736f4dfebb9b6cdc243960f9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 20 Jun 2018 16:10:13 +0000 Subject: 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 Commit-Queue: Tom Sepez --- core/fpdfapi/edit/cpdf_creator.cpp | 13 ++--- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 2 +- fpdfsdk/pwl/cpwl_appstream.cpp | 3 +- fxjs/cjs_annot.cpp | 8 +-- fxjs/cjs_app.cpp | 10 ++-- fxjs/cjs_document.cpp | 15 +++--- fxjs/cjs_event.cpp | 12 ++--- fxjs/cjs_field.cpp | 58 ++++++++++++---------- fxjs/cjs_global.cpp | 2 +- fxjs/cjs_icon.cpp | 2 +- fxjs/cjs_publicmethods.cpp | 19 +++---- fxjs/cjs_util.cpp | 2 +- .../javascript/util_bytetochar_expected.txt | 2 +- xfa/fde/cfde_texteditengine.cpp | 2 +- xfa/fgas/font/cfgas_fontmgr.cpp | 2 +- 15 files changed, 75 insertions(+), 77 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index ff8d4bb82f..f8beccbad3 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -214,10 +214,7 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum, return false; break; } - CPDF_Encryptor encryptor( - GetCryptoHandler(), objnum, - pdfium::make_span(reinterpret_cast(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 @@ int32_t CPDF_Creator::WriteDoc_Stage3() { 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 @@ int32_t CPDF_Creator::WriteDoc_Stage3() { 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 386ea95f5e..3f9f3038fe 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -405,7 +405,7 @@ void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, WideString& wsTitle) { 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 aa612f0c07..c17c146d20 100644 --- a/fpdfsdk/pwl/cpwl_appstream.cpp +++ b/fpdfsdk/pwl/cpwl_appstream.cpp @@ -1949,8 +1949,7 @@ void CPWL_AppStream::Write(const ByteString& sAPType, } 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 8a53ebc048..49db20475a 100644 --- a/fxjs/cjs_annot.cpp +++ b/fxjs/cjs_annot.cpp @@ -81,8 +81,8 @@ CJS_Return CJS_Annot::set_hidden(CJS_Runtime* pRuntime, 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 vp) { @@ -101,8 +101,8 @@ CJS_Return CJS_Annot::get_type(CJS_Runtime* pRuntime) { 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 vp) { diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index 61eb632939..36a1212715 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -176,9 +176,9 @@ CJS_Return CJS_App::get_platform(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_App::get_language(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_App::response(CJS_Runtime* pRuntime, return CJS_Return(pRuntime->NewString( WideString::FromUTF16LE(reinterpret_cast(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 74304bba1d..b22d31b0b4 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -279,7 +279,7 @@ CJS_Return CJS_Document::getNthFieldName( 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 @@ CJS_Return CJS_Document::getPropertyInternal(CJS_Runtime* pRuntime, 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 @@ CJS_Return CJS_Document::get_URL(CJS_Runtime* pRuntime) { 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::set_URL(CJS_Runtime* pRuntime, } 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 @@ CJS_Return CJS_Document::get_path(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Document::getPageNthWord( 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 397d8b890c..c10f8858a9 100644 --- a/fxjs/cjs_event.cpp +++ b/fxjs/cjs_event.cpp @@ -51,10 +51,9 @@ CJS_Event::~CJS_Event() = default; 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::set_change(CJS_Runtime* pRuntime, 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::set_source(CJS_Runtime* pRuntime, 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::set_target(CJS_Runtime* pRuntime, 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 @@ CJS_Return CJS_Event::get_value(CJS_Runtime* pRuntime) { 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 e9aa777df8..84835866ea 100644 --- a/fxjs/cjs_field.cpp +++ b/fxjs/cjs_field.cpp @@ -890,7 +890,8 @@ CJS_Return CJS_Field::get_default_value(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_export_values(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_export_values(CJS_Runtime* pRuntime) { pRuntime->PutArrayElement( ExportValuesArray, 0, - pRuntime->NewString(pFormControl->GetExportValue().c_str())); + pRuntime->NewString(pFormControl->GetExportValue().AsStringView())); } return CJS_Return(ExportValuesArray); } @@ -1420,7 +1421,7 @@ CJS_Return CJS_Field::get_name(CJS_Runtime* pRuntime) { 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 vp) { @@ -1903,8 +1904,8 @@ CJS_Return CJS_Field::get_style(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_text_font(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_user_name(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) { 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 @@ CJS_Return CJS_Field::get_value_as_string(CJS_Runtime* pRuntime) { (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 @@ CJS_Return CJS_Field::buttonGetCaption( 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 @@ CJS_Return CJS_Field::getItemAt( 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 977d916492..e9b2a4b8f0 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -248,7 +248,7 @@ CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime, 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::New(pRuntime->GetIsolate(), pData->pData)); diff --git a/fxjs/cjs_icon.cpp b/fxjs/cjs_icon.cpp index 9cf20feb73..3c293ea969 100644 --- a/fxjs/cjs_icon.cpp +++ b/fxjs/cjs_icon.cpp @@ -30,7 +30,7 @@ CJS_Icon::CJS_Icon(v8::Local pObject, CJS_Runtime* pRuntime) 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 vp) { diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 4630445a35..2bc68fa6d3 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -336,13 +336,13 @@ v8::Local CJS_PublicMethods::AF_MakeArrayFromList( 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 @@ CJS_Return CJS_PublicMethods::AFMergeChange( 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 @@ CJS_Return CJS_PublicMethods::AFMakeNumber( NormalizeDecimalMarkW(&ws); v8::Local 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 @@ CJS_Return CJS_PublicMethods::AFExtractNums( 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 576a85b999..fec727302d 100644 --- a/fxjs/cjs_util.cpp +++ b/fxjs/cjs_util.cpp @@ -387,7 +387,7 @@ CJS_Return CJS_Util::byteToChar( return CJS_Return(JSMessage::kValueError); WideString wStr(static_cast(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 df15ee7226..487b89c523 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 71b413c35f..ce9d0a576c 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp @@ -238,7 +238,7 @@ size_t CFDE_TextEditEngine::CountCharsExceedingSize(const WideString& text, 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 abd5aa716a..59d4563c29 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -492,7 +492,7 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() { continue; WideString wsFaceName = - WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); + WideString::FromLocal(pFontMapper->GetFaceName(i).AsStringView()); RegisterFaces(pFontStream, &wsFaceName); } -- cgit v1.2.3