lemon/lgf_writer.h
changeset 198 e80e08222fdf
parent 192 7bf5f97d574f
child 201 9757e3d9bfeb
equal deleted inserted replaced
9:3669c8d9bd87 10:e6f745a489b6
   223 	}
   223 	}
   224 	return (_graph.direction(val) ? '+' : '-') + it->second;
   224 	return (_graph.direction(val) ? '+' : '-') + it->second;
   225       }
   225       }
   226     };
   226     };
   227 
   227 
   228     bool isWhiteSpace(char c) {
   228     inline bool isWhiteSpace(char c) {
   229       return c == ' ' || c == '\t' || c == '\v' || 
   229       return c == ' ' || c == '\t' || c == '\v' || 
   230         c == '\n' || c == '\r' || c == '\f'; 
   230         c == '\n' || c == '\r' || c == '\f'; 
   231     }
   231     }
   232 
   232 
   233     bool isEscaped(char c) {
   233     inline bool isEscaped(char c) {
   234       return c == '\\' || c == '\"' || c == '\'' || 
   234       return c == '\\' || c == '\"' || c == '\'' || 
   235 	c == '\a' || c == '\b';
   235 	c == '\a' || c == '\b';
   236     }
   236     }
   237 
   237 
   238     static void writeEscape(std::ostream& os, char c) {
   238     inline static void writeEscape(std::ostream& os, char c) {
   239       switch (c) {
   239       switch (c) {
   240       case '\\':
   240       case '\\':
   241 	os << "\\\\";
   241 	os << "\\\\";
   242 	return;
   242 	return;
   243       case '\"':
   243       case '\"':
   274 	}
   274 	}
   275 	return;
   275 	return;
   276       }     
   276       }     
   277     }
   277     }
   278 
   278 
   279     bool requireEscape(const std::string& str) {
   279     inline bool requireEscape(const std::string& str) {
   280       if (str.empty() || str[0] == '@') return true;
   280       if (str.empty() || str[0] == '@') return true;
   281       std::istringstream is(str);
   281       std::istringstream is(str);
   282       char c;
   282       char c;
   283       while (is.get(c)) {
   283       while (is.get(c)) {
   284 	if (isWhiteSpace(c) || isEscaped(c)) {
   284 	if (isWhiteSpace(c) || isEscaped(c)) {
   286 	}
   286 	}
   287       }
   287       }
   288       return false;
   288       return false;
   289     }
   289     }
   290     
   290     
   291     std::ostream& writeToken(std::ostream& os, const std::string& str) {
   291     inline std::ostream& writeToken(std::ostream& os, const std::string& str) {
   292 
   292 
   293       if (requireEscape(str)) {
   293       if (requireEscape(str)) {
   294 	os << '\"';
   294 	os << '\"';
   295 	for (std::string::const_iterator it = str.begin(); 
   295 	for (std::string::const_iterator it = str.begin(); 
   296 	     it != str.end(); ++it) {
   296 	     it != str.end(); ++it) {