Merge pull request #9434
Some checks failed
ci/gh-actions/cli / build-ubuntu (ubuntu-20.04) (push) Has been cancelled
ci/gh-actions/cli / build-ubuntu (ubuntu-22.04) (push) Has been cancelled
ci/gh-actions/cli / libwallet-ubuntu (push) Has been cancelled
ci/gh-actions/cli / build-macos (push) Has been cancelled
ci/gh-actions/cli / build-windows (push) Has been cancelled
ci/gh-actions/cli / source-archive (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:aarch64-apple-darwin11 name:Cross-Mac aarch64 packages:cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev python3-setuptools-git]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:aarch64-linux-gnu name:ARM v8 packages:python3 gperf g++-aarch64-linux-gnu]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:arm-linux-gnueabihf name:ARM v7 packages:python3 gperf g++-arm-linux-gnueabihf]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:i686-pc-linux-gnu name:i686 Linux packages:gperf cmake g++-multilib python3-zmq]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:i686-w64-mingw32 name:i686 Win packages:python3 g++-mingw-w64-i686]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:riscv64-linux-gnu name:RISCV 64bit packages:python3 gperf g++-riscv64-linux-gnu]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:x86_64-apple-darwin11 name:Cross-Mac x86_64 packages:cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev python3-setuptools-git]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:x86_64-unknown-freebsd name:x86_64 Freebsd packages:clang-8 gperf cmake python3-zmq libdbus-1-dev libharfbuzz-dev]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:x86_64-unknown-linux-gnu name:x86_64 Linux packages:gperf cmake python3-zmq libdbus-1-dev libharfbuzz-dev]) (push) Has been cancelled
ci/gh-actions/depends / ${{ matrix.toolchain.name }} (map[host:x86_64-w64-mingw32 name:Win64 packages:cmake python3 g++-mingw-w64-x86-64]) (push) Has been cancelled
ci/gh-actions/cli / test-ubuntu (push) Has been cancelled

7cb69fa epee: string_tools: keep full path in cut_off_extension (tobtoht)
c7d4bf4 epee: string_tools: remove dot from get_extension (tobtoht)
This commit is contained in:
luigi1111 2024-08-14 14:19:55 -04:00
commit b089f9ee69
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
2 changed files with 22 additions and 2 deletions

View file

@ -201,13 +201,18 @@ namespace string_tools
std::string get_extension(const std::string& str)
{
return boost::filesystem::path(str).extension().string();
std::string ext_with_dot = boost::filesystem::path(str).extension().string();
if (ext_with_dot.empty())
return {};
return ext_with_dot.erase(0, 1);
}
//----------------------------------------------------------------------------
std::string cut_off_extension(const std::string& str)
{
return boost::filesystem::path(str).stem().string();
return boost::filesystem::path(str).replace_extension("").string();
}
#ifdef _WIN32

View file

@ -1427,6 +1427,21 @@ TEST(StringTools, GetIpInt32)
EXPECT_EQ(htonl(0xff0aff00), ip);
}
TEST(StringTools, GetExtension)
{
EXPECT_EQ(std::string{}, epee::string_tools::get_extension(""));
EXPECT_EQ(std::string{}, epee::string_tools::get_extension("."));
EXPECT_EQ(std::string{"keys"}, epee::string_tools::get_extension("wallet.keys"));
EXPECT_EQ(std::string{"3"}, epee::string_tools::get_extension("1.2.3"));
}
TEST(StringTools, CutOffExtension)
{
EXPECT_EQ(std::string{}, epee::string_tools::cut_off_extension(""));
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet"));
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet.keys"));
}
TEST(NetUtils, IPv4NetworkAddress)
{
static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");