MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / clean

Function clean

src/OpenFOAM/primitives/strings/fileName/fileName.C:78–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78bool Foam::fileName::clean()
79{
80 // The top slash - we are never allowed to go above it
81 string::size_type top = this->find('/');
82
83 // No slashes - nothing to do
84 if (top == string::npos)
85 {
86 return false;
87 }
88
89 // Start with the '/' found:
90 char prev = '/';
91 string::size_type nChar = top+1;
92 string::size_type maxLen = this->size();
93
94 for
95 (
96 string::size_type src = nChar;
97 src < maxLen;
98 )
99 {
100 char c = operator[](src++);
101
102 if (prev == '/')
103 {
104 // Repeated '/' - skip it
105 if (c == '/')
106 {
107 continue;
108 }
109
110 // Could be '/./' or '/../'
111 if (c == '.')
112 {
113 // Found trailing '/.' - skip it
114 if (src >= maxLen)
115 {
116 continue;
117 }
118
119
120 // Peek at the next character
121 char c1 = operator[](src);
122
123 // Found '/./' - skip it
124 if (c1 == '/')
125 {
126 src++;
127 continue;
128 }
129
130 // It is '/..' or '/../'
131 if (c1 == '.' && (src+1 >= maxLen || operator[](src+1) == '/'))
132 {
133 string::size_type parent;
134
135 // Backtrack to find the parent directory

Callers 1

fileName.CFile · 0.85

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected