#include #include #include #include "RTF.h" namespace rtf { std::string escapeString(std::string s) { bool needsQuoting = false; const unsigned l = s.size(); for (unsigned i = 0; (i < l) && needsQuoting; i++) { switch(s[i]) { case '\\': case '{': case '}': needsQuoting = true; break; } } if (!needsQuoting) { return s; } std::string result; for (unsigned i = 0; i < l; i++) { switch(s[i]) { case '\\': result += "\\\\"; break; case '{': result += "\\{"; break; case '}': result += "\\}"; break; case ' ': // See the comments in startBold() to understand this case! result += " {}"; break; default: result += s[i]; } } return result; } bool Color::operator <(Color const &other) const { if (_red < other._red) { return true; } else if (_red > other._red) { return false; } else if (_green < other._green) { return true; } else if (_green > other._green) { return false; } else { return _blue < other._blue; } } bool Color::operator ==(Color const &other) const { return (_red == other._red) && (_green == other._green) && (_blue == other._blue); } Color::operator std::string() const { return "\\red" + itoa(_red) + "\\green" + itoa(_green) + "\\blue" + itoa(_blue); } Color red(255, 0, 0); Color green(0, 128, 0); int ColorTable::getColorIndex(Color c) { int &result = _byColor[c]; if (!result) { result = _byColor.size(); _byIndex.push_back(c); } return result; } ColorTable::operator std::string() const { std::string result = "{\\colortbl ;"; for (std::vector< Color >::const_iterator it = _byIndex.begin(); it != _byIndex.end(); it++) { result += *it; result += ";"; } return result + "}"; } }