cprover
get_base_name.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: CM Wintersteiger
6 
7 Date:
8 
9 \*******************************************************************/
10 
11 
12 #include "get_base_name.h"
13 
17 std::string get_base_name(const std::string &in, bool strip_suffix)
18 {
19  size_t r=std::string::npos;
20  if(strip_suffix)
21  r=in.rfind('.', in.length()-1);
22  if(r==std::string::npos)
23  r=in.length();
24 
25  size_t f=in.rfind('/', in.length()-1);
26  if(f==std::string::npos)
27  f=0;
28 
29  size_t fw=in.rfind('\\', in.length()-1);
30  if(fw==std::string::npos)
31  fw=0;
32 
33  f = (fw>f)?fw:f;
34 
35  if(in[f]=='/' || in[f]=='\\')
36  f++;
37  return in.substr(f, r-f);
38 }
static int8_t r
Definition: irep_hash.h:59
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension