/*- * Copyright (c) 2004 Jacques A. Vidrine * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include #include #include #include #include #include #include #include #include #include using namespace vuxml; namespace { const char *predefined_[] = #if defined(XMLESCAPE_ALL_PREDEFINED) { "<", "<", ">", ">", "&", "&", "'", "'", "\"", """, 0 } #else { "<", "<", "&", "&", "\"", """, 0 } #endif ; static std::map predefined; struct PredefinedInitializer { PredefinedInitializer() { const char **p; for (p = predefined_; *p != 0 && *(p+1) != 0; p += 2) predefined[**p] = *(p+1); } }; static PredefinedInitializer predefinedInitializer; struct isPredefinedCharacter : public std::unary_function { std::string &esc_; std::map::const_iterator end_; isPredefinedCharacter(std::string &esc) : esc_(esc), end_(predefined.end()) {} bool operator()(char c) { std::map::const_iterator p = predefined.find(c); if (p != end_) esc_ = p->second; return (p != end_); } }; } std::string vuxml::xmlescape(const std::string &s) { std::string out; std::string esc; isPredefinedCharacter pred(esc); std::string::const_iterator q, p; std::string::const_iterator end = s.end(); for (q = s.begin(); (p = std::find_if(q, end, pred)) != end; q = p+1) { if (q != p) out.append(q, p); out.append(esc); } out.append(q, end); return out; } #if defined(TEST) #include int main(int ac, char *av[]) { std::cout << vuxml::xmlescape(av[1]) << '\n'; return 0; } #endif namespace { class Killspace : public std::unary_function { public: Killspace(std::string &result) : space_(true), result_(result) {} void operator()(char c) { if (!isspace(c)) { space_ = false; result_ += c; } else if (!space_) { space_ = true; result_ += ' '; } } private: bool space_; std::string &result_; }; } std::string vuxml::killspace(const std::string &s) { std::string x; std::for_each(s.begin(), s.end(), Killspace(x)); return x; } std::ostream & vuxml::Logger::log() { return std::cerr; } const char VersionRange::infinity[] = "-Infinity-"; const char VersionRange::zero[] = "-Zero-"; bool VersionRange::contains(const std::string &version) const { int cmp; if (lo != VersionRange::zero) { cmp = version_cmp(version.c_str(), lo.c_str()); if (!(cmp > 0 || (lo_closed && cmp == 0))) return false; } if (hi != VersionRange::infinity) { cmp = version_cmp(version.c_str(), hi.c_str()); if (!(cmp < 0 || (hi_closed && cmp == 0))) return false; } return true; } Entry::Entry() {} Entry::~Entry() {} const std::string &Entry::vid() const { return vid_; } void Entry::setVid(const std::string &vid) { vid_ = vid; } const std::string &Entry::topic() const { return topic_; } void Entry::setTopic(const std::string &text) { topic_ = text; } const std::string &Entry::description() const { return description_; } void Entry::setDescription(const std::string &text) { description_ = text; } void Entry::appendDescription(const std::string &text) { description_ += text; } const std::string &Entry::discoveryDate() const { return discovery_; } void Entry::setDiscoveryDate(const std::string &date) { discovery_ = date; } const std::string &Entry::entryDate() const { return entry_; } void Entry::setEntryDate(const std::string &date) { entry_ = date; } const std::string &Entry::modifiedDate() const { return modified_; } void Entry::setModifiedDate(const std::string &date) { modified_ = date; } const std::vector &Entry::references() const { return references_; } void Entry::addReference(const Reference &reference) { references_.push_back(reference); } void Entry::addReference(const std::string &type, const std::string &text) { references_.push_back(Reference(type, text)); } const std::vector &Entry::affected() const { return affected_; } void Entry::addAffectedSet() { affected_.resize(affected_.size()+1); } void Entry::addAffectedName(const std::string &name) { AffectedSet &as = affected_.back(); as.names.push_back(name); } void Entry::addAffectedRange(const VersionRange &range) { AffectedSet &as = affected_.back(); as.ranges.push_back(range); } EntryProcessor::EntryProcessor() {} EntryProcessor::~EntryProcessor() {} void EntryProcessor::start() {} void EntryProcessor::end() {}