diff options
author | Noel Grandin <noel@peralex.com> | 2021-06-15 21:12:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-06-17 14:32:11 +0200 |
commit | 0771ac00acc8730f77db76b901724f1513a32723 (patch) | |
tree | 8af934c3f11e452bc8ef8941fd284cdc9cdbab5c /unotools | |
parent | 0d97abc8ef890b2e2ead34c449f2a140e22dd5ee (diff) |
use string_view in the Translate API
Change-Id: I0bb0ea9d39ed623928060ffd3f2e2bc36ba33209
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117272
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/i18n/resmgr.cxx | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/unotools/source/i18n/resmgr.cxx b/unotools/source/i18n/resmgr.cxx index ef525cf48ca5..cdca420e2636 100644 --- a/unotools/source/i18n/resmgr.cxx +++ b/unotools/source/i18n/resmgr.cxx @@ -116,11 +116,11 @@ static int IgnoringCrtReportHook(int reportType, wchar_t *message, int * /* retu namespace Translate { - std::locale Create(const char* pPrefixName, const LanguageTag& rLocale) + std::locale Create(std::string_view aPrefixName, const LanguageTag& rLocale) { static std::unordered_map<OString, std::locale> aCache; OString sIdentifier = rLocale.getGlibcLocaleString(u".UTF-8").toUtf8(); - OString sUnique = sIdentifier + pPrefixName; + OString sUnique = sIdentifier + aPrefixName; auto aFind = aCache.find(sUnique); if (aFind != aCache.end()) return aFind->second; @@ -146,11 +146,11 @@ namespace Translate gen.add_messages_path(sPath.getStr()); #if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID // allow gettext to find these .mo files e.g. so gtk dialogs can use them - bindtextdomain(pPrefixName, sPath.getStr()); + bindtextdomain(aPrefixName.data(), sPath.getStr()); // tdf#131069 gtk, and anything sane, always wants utf-8 strings as output - bind_textdomain_codeset(pPrefixName, "UTF-8"); + bind_textdomain_codeset(aPrefixName.data(), "UTF-8"); #endif - gen.add_messages_domain(pPrefixName); + gen.add_messages_domain(aPrefixName.data()); #if defined(_WIN32) && defined(DBG_UTIL) // With a newer C++ debug runtime (in an --enable-dbgutil build), passing an invalid locale @@ -197,28 +197,29 @@ namespace Translate return aRet; } - OUString get(const char* pContextAndId, const std::locale &loc) + OUString get(std::string_view sContextAndId, const std::locale &loc) { - OString sContext; - const char *pId = strchr(pContextAndId, '\004'); - if (!pId) - pId = pContextAndId; + std::string_view sContext; + std::string_view sId; + const char *p = strchr(sContextAndId.data(), '\004'); + if (!p) + sId = sContextAndId; else { - sContext = OString(pContextAndId, pId - pContextAndId); - ++pId; - assert(!strchr(pId, '\004') && "should be using nget, not get"); + sContext = std::string_view(sContextAndId.data(), p - sContextAndId.data()); + sId = sContextAndId.substr(p - sContextAndId.data() + 1); + assert(!strchr(sId.data(), '\004') && "should be using nget, not get"); } //if it's a key id locale, generate it here if (std::use_facet<boost::locale::info>(loc).language() == "qtz") { - OString sKeyId(genKeyId(OString(pContextAndId).replace('\004', '|'))); - return OUString::fromUtf8(sKeyId) + u"\u2016" + createFromUtf8(pId, strlen(pId)); + OString sKeyId(genKeyId(OString(sContextAndId).replace('\004', '|'))); + return OUString::fromUtf8(sKeyId) + u"\u2016" + createFromUtf8(sId.data(), sId.size()); } //otherwise translate it - const std::string ret = boost::locale::pgettext(sContext.getStr(), pId, loc); + const std::string ret = boost::locale::pgettext(sContext.data(), sId.data(), loc); OUString result(ExpandVariables(createFromUtf8(ret.data(), ret.size()))); if (comphelper::LibreOfficeKit::isActive()) @@ -231,9 +232,9 @@ namespace Translate return result; } - OUString nget(const char* pContextAndIds, int n, const std::locale &loc) + OUString nget(std::string_view aContextAndIds, int n, const std::locale &loc) { - OString sContextIdId(pContextAndIds); + OString sContextIdId(aContextAndIds); std::vector<OString> aContextIdId; sal_Int32 nIndex = 0; do |