MCPcopy Create free account
hub / github.com/MITK/MITK / InitFilePath

Method InitFilePath

Modules/CppMicroServices/src/usModuleResource.cpp:52–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50};
51
52void ModuleResourcePrivate::InitFilePath(const std::string& file)
53{
54 std::string normalizedFile = file;
55 if (normalizedFile.empty() || normalizedFile[0] != '/')
56 {
57 normalizedFile = '/' + normalizedFile;
58 }
59
60 std::string rawPath;
61 std::size_t index = normalizedFile.find_last_of('/');
62 if (index == std::string::npos)
63 {
64 fileName = normalizedFile;
65 }
66 else if (index < normalizedFile.size()-1)
67 {
68 fileName = normalizedFile.substr(index+1);
69 rawPath = normalizedFile.substr(0,index+1);
70 }
71 else
72 {
73 rawPath = normalizedFile;
74 }
75
76 // remove duplicate /
77 std::string::value_type lastChar = 0;
78 for (std::size_t i = 0; i < rawPath.size(); ++i)
79 {
80 if (rawPath[i] == '/' && lastChar == '/')
81 {
82 continue;
83 }
84 lastChar = rawPath[i];
85 path.push_back(lastChar);
86 }
87 if (path.empty())
88 {
89 path.push_back('/');
90 }
91}
92
93ModuleResource::ModuleResource()
94 : d(new ModuleResourcePrivate(nullptr))

Callers 1

ModuleResourceMethod · 0.80

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected