westonpace commented on code in PR #35440:
URL: https://github.com/apache/arrow/pull/35440#discussion_r1243013062
##########
cpp/src/arrow/filesystem/path_util.cc:
##########
@@ -66,6 +67,28 @@ std::vector<std::string> SplitAbstractPath(const
std::string& path, char sep) {
return parts;
}
+std::string SliceAbstractPath(const std::string& s, int offset, int length,
char sep) {
+ if (offset < 0 || length < 0) {
+ return "";
+ }
+ std::vector<std::string> components = SplitAbstractPath(s, sep);
+ std::stringstream combined;
+ if (offset >= static_cast<int>(components.size())) {
+ return "";
+ }
+ int end = length;
Review Comment:
Actually, this should be `length + offset`. I've fixed it.
##########
cpp/src/arrow/filesystem/path_util.h:
##########
@@ -38,9 +38,17 @@ constexpr char kSep = '/';
ARROW_EXPORT
std::vector<std::string> SplitAbstractPath(const std::string& path, char sep =
kSep);
-// Return the extension of the file
+// Slice the individual components of an abstract path and combine them
+//
+// If offset or length are negative then an empty string is returned
+// If offset is >= the number of components then an empty string is returned
+// If offset + length is >= the number of components then length is truncated
ARROW_EXPORT
-std::string GetAbstractPathExtension(const std::string& s);
+std::string SliceAbstractPath(const std::string& path, int offset, int length,
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]