CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
get_base_name.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: CM Wintersteiger
6
7Date:
8
9\*******************************************************************/
10
11#include "get_base_name.h"
12
16std::string get_base_name(const std::string &in, bool strip_suffix)
17{
18#ifdef _WIN32
19 // Windows now allows both '/' and '\\'
20 const std::size_t slash_pos = in.find_last_of("\\/");
21#else
22 const std::size_t slash_pos = in.rfind('/');
23#endif
24
25 std::size_t start_pos =
26 (slash_pos == std::string::npos) ? 0 : slash_pos + 1;
27
28 std::size_t char_count = std::string::npos;
29
30 if(strip_suffix)
31 {
32 std::size_t dot_pos = in.rfind('.');
33 if(dot_pos != std::string::npos && dot_pos >= start_pos)
35 }
36
37 return std::string(in, start_pos, char_count);
38}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension