Loading...
Searching...
No Matches
scatch.icc
Go to the documentation of this file.
#ifndef _RHEOLEF_SCATCH_ICC
#define _RHEOLEF_SCATCH_ICC
// utility included by rheostream.cc
// and shared by msh2geo.cc bamg2geo.cc and others utilities
// => avoid code redundancies
#include <iostream>
#include<sys/stat.h> // stat()
namespace rheolef {
using namespace std;
bool
file_exists (const string& filename)
{
struct stat s;
if (stat(filename.c_str(), &s) != 0) {
return false;
}
return true;
}
bool
scatch (istream& in, const string& ch, bool full_match)
{
// null string case
unsigned int l = ch.length();
if (l == 0) return true;
// check file
char c = '\0';
unsigned int state = 0;
const char *p = ch.c_str();
do {
in.get(c);
if (*p == '\n') {
// begining of stream <==> begining of a line, e.g.
// we look at "\nfield" while file starts
// with string "field"; it's ok
state++;
p++;
}
do {
if (*p == c) {
// advance in the string
state++;
p++;
} else if (state != 0 && ch[0] == c) {
// come back to the second position
state = 1;
p = ch.c_str() + 1;
} else if (state != 0) {
// come back to the begining of the string
state = 0;
p = ch.c_str();
}
}
while (state < l && in.get(c) && in.good());
// here: either state == l or end-of-file is reached
if (!full_match) return (state == l);
if (state != l) return false; // reaches end-of-file whithout finding the string
// here: state == l and we want a full match: check also that next char is a space, tab, end-of-line, or end-of-file
// => otherwise ambiguity with scatch("u") that reaches either "uh" or "u_exact"...!
c = in.peek();
if (!c || !in.good()) return true; // end-of-file just after the string: ok...
if (isspace(c)) return true; // nice! the expected situation
} while (true);
// stops when reaching either the string or end-of-file: the next statement is not reached
return false;
}
}// namespace rheolef
#endif // _RHEOLEF_SCATCH_ICC
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::scatch
bool scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
Definition scatch.icc:44
rheolef::file_exists
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition scatch.icc:34
std
STL namespace.
p
Definition sphere.icc:25