Path is a utility for working with paths
gitlab.com60 pointsby spyrja16 comments
bool balanced(const string& text, const string& open, const string& close) {
size_t length = text.size(), brackets = open.size();
assert(close.size() == brackets);
stack<char> buffer;
for (size_t index = 0; index < length; ++index) {
char ch = text[index];
for (size_t slot = 0; slot < brackets; ++slot) {
if (ch == open[slot])
buffer.push(ch);
else if (ch == close[slot]) {
if (buffer.empty() || buffer.top() != open[slot])
return false;
buffer.pop();
}
}
}
return buffer.empty();
} next = compile(read(buffer), cons("halt", NULL));
C doesn't guarantee the order in which arguments to a function are processed. Since 'cons' relies on 'read' being called first, the result is undefined behavior. (In fact I had to fix that before it would even "run" on my system.)