diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-21 12:53:15 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-21 13:53:26 +0200 |
commit | 2d9291b9433c9645b0870525211f74bfb1151555 (patch) | |
tree | 53cb623e805899ea01e4ee65fd7c5eac27dd1934 /unoidl | |
parent | 9ac36f0ecba806b51e6d1cb4cf8d92fe062508f4 (diff) |
use more string_view in unoidl,codemaker
Change-Id: Ibc0624a662c98ef1308a3bb0c7c082935a89a25c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133252
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unoidl')
-rw-r--r-- | unoidl/source/legacyprovider.cxx | 5 | ||||
-rw-r--r-- | unoidl/source/legacyprovider.hxx | 2 | ||||
-rw-r--r-- | unoidl/source/sourcefileprovider.cxx | 5 | ||||
-rw-r--r-- | unoidl/source/sourcefileprovider.hxx | 2 | ||||
-rw-r--r-- | unoidl/source/sourceprovider-parser.y | 4 | ||||
-rw-r--r-- | unoidl/source/sourcetreeprovider.cxx | 3 | ||||
-rw-r--r-- | unoidl/source/sourcetreeprovider.hxx | 2 | ||||
-rw-r--r-- | unoidl/source/unoidl-read.cxx | 44 | ||||
-rw-r--r-- | unoidl/source/unoidl-write.cxx | 2 | ||||
-rw-r--r-- | unoidl/source/unoidl.cxx | 7 | ||||
-rw-r--r-- | unoidl/source/unoidlprovider.cxx | 41 | ||||
-rw-r--r-- | unoidl/source/unoidlprovider.hxx | 2 |
12 files changed, 62 insertions, 57 deletions
diff --git a/unoidl/source/legacyprovider.cxx b/unoidl/source/legacyprovider.cxx index ab99fcf59dd1..577febd9c1b0 100644 --- a/unoidl/source/legacyprovider.cxx +++ b/unoidl/source/legacyprovider.cxx @@ -813,11 +813,12 @@ rtl::Reference< MapCursor > LegacyProvider::createRootCursor() const { return new Cursor(&manager_, ucr_, ucr_); } -rtl::Reference< Entity > LegacyProvider::findEntity(OUString const & name) +rtl::Reference< Entity > LegacyProvider::findEntity(std::u16string_view name) const { + OUString s(name); return ucr_.isValid() - ? readEntity(&manager_, ucr_, ucr_, name.replace('.', '/'), true) + ? readEntity(&manager_, ucr_, ucr_, s.replace('.', '/'), true) : rtl::Reference< Entity >(); } diff --git a/unoidl/source/legacyprovider.hxx b/unoidl/source/legacyprovider.hxx index caa1b38c84a4..8c22dbe0451c 100644 --- a/unoidl/source/legacyprovider.hxx +++ b/unoidl/source/legacyprovider.hxx @@ -26,7 +26,7 @@ public: virtual rtl::Reference< MapCursor > createRootCursor() const override; // throws FileFormatException: - virtual rtl::Reference< Entity > findEntity(OUString const & name) + virtual rtl::Reference< Entity > findEntity(std::u16string_view name) const override; private: diff --git a/unoidl/source/sourcefileprovider.cxx b/unoidl/source/sourcefileprovider.cxx index 983b7d3c3403..e487fcf47590 100644 --- a/unoidl/source/sourcefileprovider.cxx +++ b/unoidl/source/sourcefileprovider.cxx @@ -15,6 +15,7 @@ #include "sourcefileprovider.hxx" #include "sourceprovider-scanner.hxx" +#include <o3tl/string_view.hxx> namespace unoidl::detail { @@ -105,12 +106,12 @@ rtl::Reference<MapCursor> SourceFileProvider::createRootCursor() const { return new Cursor(rootMap_); } -rtl::Reference<Entity> SourceFileProvider::findEntity(OUString const & name) +rtl::Reference<Entity> SourceFileProvider::findEntity(std::u16string_view name) const { std::map< OUString, rtl::Reference<Entity> > const * map = &rootMap_; for (sal_Int32 i = 0;;) { - OUString id(name.getToken(0, '.', i)); + OUString id(o3tl::getToken(name, 0, '.', i)); std::map< OUString, rtl::Reference<Entity> >::const_iterator j( map->find(id)); if (j == map->end()) { diff --git a/unoidl/source/sourcefileprovider.hxx b/unoidl/source/sourcefileprovider.hxx index 52fd32f3c735..6e586294a0c4 100644 --- a/unoidl/source/sourcefileprovider.hxx +++ b/unoidl/source/sourcefileprovider.hxx @@ -28,7 +28,7 @@ public: virtual rtl::Reference<MapCursor> createRootCursor() const override; // throws FileFormatException: - virtual rtl::Reference<Entity> findEntity(OUString const& name) const override; + virtual rtl::Reference<Entity> findEntity(std::u16string_view name) const override; private: virtual ~SourceFileProvider() noexcept override; diff --git a/unoidl/source/sourceprovider-parser.y b/unoidl/source/sourceprovider-parser.y index 2c076f08ac70..a6f9722c9d9e 100644 --- a/unoidl/source/sourceprovider-parser.y +++ b/unoidl/source/sourceprovider-parser.y @@ -400,7 +400,7 @@ Found findEntity( + t)); return FOUND_ERROR; } - OUString tmpl(typeNucleus.copy(0, i)); + std::u16string_view tmpl(typeNucleus.subView(0, i)); do { ++i; // skip '<' or ',' sal_Int32 j = i; @@ -3509,7 +3509,7 @@ primaryExpr: YYERROR; } if (ent != nullptr) { - OUString id(name.copy(i + 1)); + std::u16string_view id(name.subView(i + 1)); // No need to check for enum members here, as they cannot be // referenced in expressions by qualified name (TODO: is that true?): if (ent->entity.is()) { diff --git a/unoidl/source/sourcetreeprovider.cxx b/unoidl/source/sourcetreeprovider.cxx index fea67405cd54..2f115bef44bf 100644 --- a/unoidl/source/sourcetreeprovider.cxx +++ b/unoidl/source/sourcetreeprovider.cxx @@ -231,9 +231,10 @@ rtl::Reference<MapCursor> SourceTreeProvider::createRootCursor() const { return new Cursor(manager_, uri_); } -rtl::Reference<Entity> SourceTreeProvider::findEntity(OUString const & name) +rtl::Reference<Entity> SourceTreeProvider::findEntity(std::u16string_view _name) const { + OUString name(_name); std::map< OUString, rtl::Reference<Entity> >::iterator ci( cache_.find(name)); if (ci != cache_.end()) { diff --git a/unoidl/source/sourcetreeprovider.hxx b/unoidl/source/sourcetreeprovider.hxx index 37bd6baa1286..9b2d6fd55cb9 100644 --- a/unoidl/source/sourcetreeprovider.hxx +++ b/unoidl/source/sourcetreeprovider.hxx @@ -28,7 +28,7 @@ public: virtual rtl::Reference<MapCursor> createRootCursor() const override; // throws FileFormatException: - virtual rtl::Reference<Entity> findEntity(OUString const& name) const override; + virtual rtl::Reference<Entity> findEntity(std::u16string_view name) const override; private: virtual ~SourceTreeProvider() noexcept override; diff --git a/unoidl/source/unoidl-read.cxx b/unoidl/source/unoidl-read.cxx index fcf541612ec5..794bd0b473e7 100644 --- a/unoidl/source/unoidl-read.cxx +++ b/unoidl/source/unoidl-read.cxx @@ -84,26 +84,26 @@ OUString getArgumentUri(sal_uInt32 argument) { return abs; } -OUString decomposeType( - OUString const & type, std::size_t * rank, +std::u16string_view decomposeType( + std::u16string_view type, std::size_t * rank, std::vector<OUString> * typeArguments, bool * entity) { assert(rank != nullptr); assert(typeArguments != nullptr); assert(entity != nullptr); - OUString nucl(type); + std::u16string_view nucl(type); *rank = 0; typeArguments->clear(); - while (nucl.startsWith("[]", &nucl)) { + while (o3tl::starts_with(nucl, u"[]", &nucl)) { ++*rank; } - sal_Int32 i = nucl.indexOf('<'); - if (i != -1) { - OUString tmpl(nucl.copy(0, i)); + size_t i = nucl.find('<'); + if (i != std::u16string_view::npos) { + std::u16string_view tmpl(nucl.substr(0, i)); do { ++i; // skip '<' or ',' - sal_Int32 j = i; - for (sal_Int32 level = 0; j != nucl.getLength(); ++j) { + size_t j = i; + for (sal_Int32 level = 0; j != nucl.size(); ++j) { sal_Unicode c = nucl[j]; if (c == ',') { if (level == 0) { @@ -118,22 +118,22 @@ OUString decomposeType( --level; } } - if (j != nucl.getLength()) { - typeArguments->push_back(nucl.copy(i, j - i)); + if (j != nucl.size()) { + typeArguments->push_back(OUString(nucl.substr(i, j - i))); } i = j; - } while (i != nucl.getLength() && nucl[i] != '>'); - assert(i == nucl.getLength() - 1 && nucl[i] == '>'); + } while (i != nucl.size() && nucl[i] != '>'); + assert(i == nucl.size() - 1 && nucl[i] == '>'); assert(!typeArguments->empty()); nucl = tmpl; } - assert(!nucl.isEmpty()); - *entity = nucl != "void" && nucl != "boolean" && nucl != "byte" - && nucl != "short" && nucl != "unsigned short" && nucl != "long" - && nucl != "unsigned long" && nucl != "hyper" - && nucl != "unsigned hyper" && nucl != "float" && nucl != "double" - && nucl != "char" && nucl != "string" && nucl != "type" - && nucl != "any"; + assert(!nucl.empty()); + *entity = nucl != u"void" && nucl != u"boolean" && nucl != u"byte" + && nucl != u"short" && nucl != u"unsigned short" && nucl != u"long" + && nucl != u"unsigned long" && nucl != u"hyper" + && nucl != u"unsigned hyper" && nucl != u"float" && nucl != u"double" + && nucl != u"char" && nucl != u"string" && nucl != u"type" + && nucl != u"any"; assert(*entity || typeArguments->empty()); return nucl; } @@ -204,7 +204,7 @@ void insertEntityDependencies( void insertTypeDependency( rtl::Reference<unoidl::Manager> const & manager, std::map<OUString, Entity>::iterator const & iterator, - OUString const & type) + std::u16string_view type) { std::size_t rank; std::vector<OUString> args; @@ -520,7 +520,7 @@ void writeAnnotationsPublished( writePublished(entity); } -void writeType(OUString const & type) { +void writeType(std::u16string_view type) { std::size_t rank; std::vector<OUString> args; bool entity; diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx index 5ddd98468359..dafca970c246 100644 --- a/unoidl/source/unoidl-write.cxx +++ b/unoidl/source/unoidl-write.cxx @@ -394,7 +394,7 @@ void mapEntities( std::map< OUString, Item >::iterator k(map2->find(id)); if (k == map2->end()) { rtl::Reference< unoidl::Entity > ent2( - manager->findEntity(t.copy(0, j - 1))); + manager->findEntity(t.subView(0, j - 1))); assert(ent2.is()); k = map2->insert(std::make_pair(id, Item(ent2))).first; } diff --git a/unoidl/source/unoidl.cxx b/unoidl/source/unoidl.cxx index 749f9afe4f25..5dfce2348d0c 100644 --- a/unoidl/source/unoidl.cxx +++ b/unoidl/source/unoidl.cxx @@ -164,7 +164,7 @@ ServiceBasedSingletonEntity::~ServiceBasedSingletonEntity() noexcept {} Provider::~Provider() noexcept {} -rtl::Reference< Provider > Manager::addProvider(OUString const & uri) { +rtl::Reference< Provider > Manager::addProvider(std::u16string_view uri) { rtl::Reference< Provider > p(loadProvider(uri)); assert(p.is()); { @@ -174,7 +174,7 @@ rtl::Reference< Provider > Manager::addProvider(OUString const & uri) { return p; } -rtl::Reference< Entity > Manager::findEntity(OUString const & name) const { +rtl::Reference< Entity > Manager::findEntity(std::u16string_view name) const { //TODO: caching? (here or in cppuhelper::TypeManager?) osl::MutexGuard g(mutex_); for (auto & i: providers_) { @@ -194,7 +194,8 @@ rtl::Reference< MapCursor > Manager::createCursor(OUString const & name) Manager::~Manager() noexcept {} -rtl::Reference< Provider > Manager::loadProvider(OUString const & uri) { +rtl::Reference< Provider > Manager::loadProvider(std::u16string_view _uri) { + OUString uri(_uri); osl::DirectoryItem item; if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) { osl::FileStatus status(osl_FileStatus_Mask_Type); diff --git a/unoidl/source/unoidlprovider.cxx b/unoidl/source/unoidlprovider.cxx index e7816afdb2be..de158f10b1b2 100644 --- a/unoidl/source/unoidlprovider.cxx +++ b/unoidl/source/unoidlprovider.cxx @@ -27,6 +27,7 @@ #include <sal/types.h> #include <salhelper/simplereferenceobject.hxx> #include <unoidl/unoidl.hxx> +#include <o3tl/string_view.hxx> #include "unoidlprovider.hxx" @@ -203,18 +204,18 @@ bool isIdentifier(std::u16string_view type, bool scoped) { } void checkTypeName( - rtl::Reference< MappedFile > const & file, OUString const & type) + rtl::Reference< MappedFile > const & file, std::u16string_view type) { - OUString nucl(type); + std::u16string_view nucl(type); bool args = false; - while (nucl.startsWith("[]", &nucl)) {} - sal_Int32 i = nucl.indexOf('<'); - if (i != -1) { - OUString tmpl(nucl.copy(0, i)); + while (o3tl::starts_with(nucl, u"[]", &nucl)) {} + size_t i = nucl.find('<'); + if (i != std::u16string_view::npos) { + std::u16string_view tmpl(nucl.substr(0, i)); do { ++i; // skip '<' or ',' - sal_Int32 j = i; - for (sal_Int32 level = 0; j != nucl.getLength(); ++j) { + size_t j = i; + for (size_t level = 0; j != nucl.size(); ++j) { sal_Unicode c = nucl[j]; if (c == ',') { if (level == 0) { @@ -229,20 +230,20 @@ void checkTypeName( --level; } } - if (j != nucl.getLength()) { - checkTypeName(file, nucl.copy(i, j - i)); + if (j != nucl.size()) { + checkTypeName(file, nucl.substr(i, j - i)); args = true; } i = j; - } while (i != nucl.getLength() && nucl[i] != '>'); - if (i != nucl.getLength() - 1 || nucl[i] != '>' || !args) { - tmpl.clear(); // bad input + } while (i != nucl.size() && nucl[i] != '>'); + if (i != nucl.size() - 1 || nucl[i] != '>' || !args) { + tmpl = {}; // bad input } nucl = tmpl; } if (isSimpleType(nucl) ? args : !isIdentifier(nucl, true)) { throw FileFormatException( - file->uri, "UNOIDL format: bad type \"" + type + "\""); + file->uri, OUString::Concat("UNOIDL format: bad type \"") + type + "\""); } } @@ -507,7 +508,7 @@ Compare compare( sal_uInt32 findInMap( rtl::Reference< MappedFile > const & file, MapEntry const * mapBegin, - sal_uInt32 mapSize, OUString const & name, sal_Int32 nameOffset, + sal_uInt32 mapSize, std::u16string_view name, sal_Int32 nameOffset, sal_Int32 nameLength) { if (mapSize == 0) { @@ -1348,21 +1349,21 @@ rtl::Reference< MapCursor > UnoidlProvider::createRootCursor() const { rtl::Reference<UnoidlModuleEntity>(), map_); } -rtl::Reference< Entity > UnoidlProvider::findEntity(OUString const & name) const +rtl::Reference< Entity > UnoidlProvider::findEntity(std::u16string_view name) const { NestedMap map(map_); bool cgroup = false; for (sal_Int32 i = 0;;) { - sal_Int32 j = name.indexOf('.', i); - if (j == -1) { - j = name.getLength(); + size_t j = name.find('.', i); + if (j == std::u16string_view::npos) { + j = name.size(); } sal_Int32 off = findInMap( file_, map.map.begin, map.map.size, name, i, j - i); if (off == 0) { return rtl::Reference< Entity >(); } - if (j == name.getLength()) { + if (j == name.size()) { return cgroup ? rtl::Reference< Entity >() : readEntity(file_, off, std::set(map.trace)); diff --git a/unoidl/source/unoidlprovider.hxx b/unoidl/source/unoidlprovider.hxx index 734f8592b814..244bd26f3513 100644 --- a/unoidl/source/unoidlprovider.hxx +++ b/unoidl/source/unoidlprovider.hxx @@ -41,7 +41,7 @@ public: virtual rtl::Reference< MapCursor > createRootCursor() const override; // throws FileFormatException: - virtual rtl::Reference< Entity > findEntity(OUString const & name) + virtual rtl::Reference< Entity > findEntity(std::u16string_view name) const override; private: |