修复strlen无法编译问题

Signed-off-by: liumingxiang1 <liumingxiang1@huawei.com>
This commit is contained in:
liumingxiang1 2024-10-24 10:40:44 +08:00
parent fe90427424
commit 5afe7daa58
4 changed files with 5 additions and 6 deletions

View File

@ -169,7 +169,7 @@ napi_value JsParagraphBuilder::OnAddText(napi_env env, napi_callback_info info)
}
std::string text = "";
if (ConvertFromJsValue(env, argv[0], text)) {
if (!IsUtf8(text.c_str())) {
if (!IsUtf8(text.c_str(), text.size())) {
TEXT_LOGE("Invalid utf-8 text");
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
}

View File

@ -432,7 +432,7 @@ void OH_Drawing_TypographyHandlerAddText(OH_Drawing_TypographyCreate* handler, c
if (!text || !handler) {
LOGE("null text");
return;
} else if (!IsUtf8(text)) {
} else if (!IsUtf8(text, strlen(text))) {
LOGE("text is not utf-8");
return;
}

View File

@ -19,7 +19,7 @@
namespace OHOS {
namespace Rosen {
bool IsUtf8(const char* text);
bool IsUtf8(const char* text, int len);
}
} // namespace OHOS

View File

@ -12,15 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string>
#include <cstdint>
#include "utils/string_util.h"
namespace OHOS {
namespace Rosen {
bool IsUtf8(const char* text)
bool IsUtf8(const char* text, int len)
{
int len = strlen(text);
int n;
int i = 0;
while (i < len) {