diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-19 08:39:38 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-19 08:39:38 +0100 |
commit | b8b4335dba57e1c6159b77d5cb7bbe91318664b4 (patch) | |
tree | 4ded35f4bafa33f8d5f23a684133470b118d35a1 | |
parent | 2f2f29391012949385631e5bee7c35fed71392dd (diff) | |
download | lanes-b8b4335dba57e1c6159b77d5cb7bbe91318664b4.tar.gz lanes-b8b4335dba57e1c6159b77d5cb7bbe91318664b4.tar.bz2 lanes-b8b4335dba57e1c6159b77d5cb7bbe91318664b4.zip |
Simplified lane base library string parsing
-rw-r--r-- | src/state.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/state.cpp b/src/state.cpp index c8f1ef8..6c49694 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -253,23 +253,17 @@ namespace state { | |||
253 | }; | 253 | }; |
254 | while (!_libs.empty()) { | 254 | while (!_libs.empty()) { |
255 | // remove prefix not part of a name | 255 | // remove prefix not part of a name |
256 | auto _nameStart{ std::find_if(std::cbegin(_libs), std::cend(_libs), isLibNameChar) }; | 256 | _libs = std::string_view{ std::find_if(std::cbegin(_libs), std::cend(_libs), isLibNameChar), _libs.end() }; |
257 | if (_nameStart == _libs.end()) { | 257 | // extract a single name |
258 | break; | 258 | auto const _libNameEnd{ std::find_if(std::cbegin(_libs), std::cend(_libs), [&isLibNameChar](char const _c) { return !isLibNameChar(_c); }) }; |
259 | } | 259 | std::string_view const _libName{ _libs.begin(), _libNameEnd }; |
260 | auto const _prefixLen{ std::distance(_libs.begin(), _nameStart) }; | 260 | if (_libName.empty()) { |
261 | |||
262 | auto const _nameEnd{ std::find_if(_nameStart, std::cend(_libs), [&isLibNameChar](char const _c) { return !isLibNameChar(_c); }) }; | ||
263 | // advance to the end of the character sequence composing the name | ||
264 | auto const _nameLen{ std::distance(_nameStart, _nameEnd) }; | ||
265 | if (_nameLen == 0) { | ||
266 | break; | 261 | break; |
267 | } | 262 | } |
268 | // open library | 263 | // open library |
269 | std::string_view const _libName{ _libs.substr(static_cast<size_t>(_prefixLen), static_cast<size_t>(_nameLen)) }; | ||
270 | Open1Lib(_L, _libName); | 264 | Open1Lib(_L, _libName); |
271 | // advance to next item (can't do this earlier as it invalidates iterators) | 265 | // advance to next item |
272 | _libs.remove_prefix(static_cast<size_t>(_prefixLen + _nameLen)); | 266 | _libs = std::string_view{ _libNameEnd, _libs.end() }; |
273 | } | 267 | } |
274 | lua_gc(_L, LUA_GCRESTART, 0); | 268 | lua_gc(_L, LUA_GCRESTART, 0); |
275 | 269 | ||