rm5248 commented on a change in pull request #75:
URL: https://github.com/apache/logging-log4cxx/pull/75#discussion_r756953860
##########
File path: src/main/cpp/locationinfo.cpp
##########
@@ -35,6 +41,21 @@ const LocationInfo& LocationInfo::getLocationUnavailable()
return unavailable;
}
+/**
+ * filter short file name
+ * @param fileName
+ * @return shortFileName
+ */
+const std::string filterFileName(const char* const fileName){
+ std::string fullFileName(fileName);
+ std::size_t found = fullFileName.rfind(SHORT_FILENAME_SPLIT_CHAR);
+ if (found != std::string::npos) {
+ return fullFileName.substr(found + 1);
+ } else {
+ return std::string(fileName);
+ }
Review comment:
As per Thorsten's comments, this should probably do more of a `const
char*` thing. We can be somewhat clever here - since we know that the actual
filename is going to be at the end of the filename, we just need to walk the
string until we get to the end. Something like this should work:
```
const char* begin = fileName;
size_t pos = 0;
while( fileName[pos] != 0 ){
if( fileName[pos] == SHORT_FILENAME_SPLIT_CHAR &&
fileName[pos+1] != 0 ){
begin = fileName + pos + 1;
}
pos++;
}
return begin;
```
This also means that we don't _have_ to add a new member variable(this could
be the implementation of `getShortFileName`), but adding a new member variable
is probably good(I think with C++17 we can actually make this `constexpr` to
evaluate at compile-time, but we would need to add a check for that).
--
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]