File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -201,13 +201,18 @@ namespace string_tools
201
201
202
202
std::string get_extension (const std::string& str)
203
203
{
204
- return boost::filesystem::path (str).extension ().string ();
204
+ std::string ext_with_dot = boost::filesystem::path (str).extension ().string ();
205
+
206
+ if (ext_with_dot.empty ())
207
+ return {};
208
+
209
+ return ext_with_dot.erase (0 , 1 );
205
210
}
206
211
207
212
// ----------------------------------------------------------------------------
208
213
std::string cut_off_extension (const std::string& str)
209
214
{
210
- return boost::filesystem::path (str).stem ( ).string ();
215
+ return boost::filesystem::path (str).replace_extension ( " " ).string ();
211
216
}
212
217
213
218
#ifdef _WIN32
Original file line number Diff line number Diff line change @@ -1427,6 +1427,21 @@ TEST(StringTools, GetIpInt32)
1427
1427
EXPECT_EQ (htonl (0xff0aff00 ), ip);
1428
1428
}
1429
1429
1430
+ TEST (StringTools, GetExtension)
1431
+ {
1432
+ EXPECT_EQ (std::string{}, epee::string_tools::get_extension (" " ));
1433
+ EXPECT_EQ (std::string{}, epee::string_tools::get_extension (" ." ));
1434
+ EXPECT_EQ (std::string{" keys" }, epee::string_tools::get_extension (" wallet.keys" ));
1435
+ EXPECT_EQ (std::string{" 3" }, epee::string_tools::get_extension (" 1.2.3" ));
1436
+ }
1437
+
1438
+ TEST (StringTools, CutOffExtension)
1439
+ {
1440
+ EXPECT_EQ (std::string{}, epee::string_tools::cut_off_extension (" " ));
1441
+ EXPECT_EQ (std::string{" /home/user/Monero/wallets/wallet" }, epee::string_tools::cut_off_extension (" /home/user/Monero/wallets/wallet" ));
1442
+ EXPECT_EQ (std::string{" /home/user/Monero/wallets/wallet" }, epee::string_tools::cut_off_extension (" /home/user/Monero/wallets/wallet.keys" ));
1443
+ }
1444
+
1430
1445
TEST (NetUtils, IPv4NetworkAddress)
1431
1446
{
1432
1447
static_assert (epee::net_utils::ipv4_network_address::get_type_id () == epee::net_utils::address_type::ipv4, " bad ipv4 type id" );
You can’t perform that action at this time.
0 commit comments