From 6fe7d2174a47107578da912299c93b4dfb9f2add Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 6 Apr 2016 10:51:14 -0700 Subject: Make CFX_WideString::FromUTF8() take a CFX_ByteStringC argument. Methods that take string arguments and do not persist them should take *StringC types as argument rather than discrete ptr/len args. Avoids a number of implicit casts from CFX_ByteString to char*. BUG= Review URL: https://codereview.chromium.org/1861183002 --- core/fxcrt/fx_basic_wstring.cpp | 7 +++---- core/fxcrt/include/fx_string.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index cd60036acd..627573fa7d 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -372,13 +372,12 @@ CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str, } // static -CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) { - if (!str || 0 == len) { +CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) { + if (str.IsEmpty()) return CFX_WideString(); - } CFX_UTF8Decoder decoder; - for (FX_STRSIZE i = 0; i < len; i++) { + for (FX_STRSIZE i = 0; i < str.GetLength(); i++) { decoder.Input(str[i]); } return decoder.GetResult(); diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index f5b431e62c..7595795011 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -508,7 +508,7 @@ class CFX_WideString { static CFX_WideString FromCodePage(const CFX_ByteString& str, uint16_t codepage); - static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); + static CFX_WideString FromUTF8(const CFX_ByteStringC& str); static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); static FX_STRSIZE WStringLength(const unsigned short* str); -- cgit v1.2.3