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 --- fxjs/cjs_publicmethods.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'fxjs/cjs_publicmethods.cpp') 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()); -- cgit v1.2.3