Commit 8d2947c 1 parent dffd573 commit 8d2947c Copy full SHA for 8d2947c
File tree 3 files changed +28
-0
lines changed
include/public/deephaven/dhcore/utility
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,16 @@ TimePointToEpochMillis(
187
187
TimePointToStr (
188
188
std::chrono::time_point<std::chrono::system_clock> time_point);
189
189
190
+ /* *
191
+ * This is a method that simply invokes std::filesystem::path(path).filename().string().
192
+ * We put it here because it is sometimes useful, to provide functionality
193
+ * similar to the POSIX basename() call. We deliberately do not inline it
194
+ * because is generates a surprising amount of code.
195
+ * @param path The path
196
+ * @return The basename of the path, as returned by std::filesystem::path(path).filename().string()
197
+ */
198
+ std::string Basename (std::string_view path);
199
+
190
200
template <class T > [[nodiscard]] std::string
191
201
TypeName (const T& t) {
192
202
return demangle (typeid (t).name ());
Original file line number Diff line number Diff line change 3
3
*/
4
4
#include " deephaven/dhcore/utility/utility.h"
5
5
6
+ #include < filesystem>
6
7
#include < ostream>
7
8
#include < string>
8
9
#include < vector>
@@ -144,6 +145,10 @@ TimePointToStr(
144
145
return EpochMillisToStr (TimePointToEpochMillis (time_point));
145
146
}
146
147
148
+ std::string Basename (std::string_view path) {
149
+ return std::filesystem::path (path).filename ().string ();
150
+ }
151
+
147
152
#ifdef __GNUG__
148
153
std::string demangle (const char *name) {
149
154
int status = -1 ;
Original file line number Diff line number Diff line change 5
5
#include " deephaven/dhcore/utility/utility.h"
6
6
7
7
using deephaven::dhcore::utility::Base64Encode;
8
+ using deephaven::dhcore::utility::Basename;
8
9
using deephaven::dhcore::utility::EpochMillisToStr;
9
10
using deephaven::dhcore::utility::ObjectId;
10
11
@@ -28,4 +29,16 @@ TEST_CASE("ObjectId", "[utility]") {
28
29
auto id = ObjectId (" hello" , reinterpret_cast <void *>(p));
29
30
CHECK (id == " hello(0xdeadbeef)" );
30
31
}
32
+
33
+ TEST_CASE (" Basename" , " [utility]" ) {
34
+ #ifdef __linux__
35
+ CHECK (" file.txt" == Basename (" /home/kosak/file.txt" ));
36
+ CHECK (Basename (" /home/kosak/" ).empty ());
37
+ #endif
38
+
39
+ #ifdef _WIN32
40
+ CHECK (" file.txt" == Basename (R"( C:\Users\kosak\file.txt)" ));
41
+ CHECK (Basename (R"( C:\Users\kosak\)" ).empty ());
42
+ #endif
43
+ }
31
44
} // namespace deephaven::client::tests
You can’t perform that action at this time.
0 commit comments