Skip to content

Commit 468d83d

Browse files
committed
Avoid using raw pointer in BaseName func
1 parent 86cfacc commit 468d83d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ enum LogSeverity {
117117
int GetMinLogLevel();
118118
void SetMinLogLevel(int v);
119119

120-
inline const char *BaseName(const char *path) {
120+
inline absl::string_view BaseName(absl::string_view path) {
121121
#ifdef OS_WIN
122-
const char *p = strrchr(path, '\\');
122+
const size_t pos = path.find_last_of('\\');
123123
#else
124-
const char *p = strrchr(path, '/');
124+
const size_t pos = path.find_last_of('/');
125125
#endif
126-
if (p == nullptr) return path;
127-
return p + 1;
126+
return pos == absl::string_view::npos ? path : path.substr(pos + 1);
128127
}
128+
129129
} // namespace logging
130130
} // namespace sentencepiece
131131

0 commit comments

Comments
 (0)