<commit_before>#pragma once
#include <string>
#include <map>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include "../common.hpp"
#include "./propset/DocumentSummary.hpp"

namespace oless {

	class OLESSExtensionInfo : public common::ExtensionInfo {
	protected:
		virtual std::string buildBaseJson() const override {
			std::ostringstream str;
			str << common::ExtensionInfo::buildBaseJson();
			if (this->paths.size() > 0) {
				str << ", \"Paths\": [";
				for (auto i = this->paths.begin(); i != this->paths.end(); i++) {
					if (i != this->paths.begin()) str << ",";
					str << "\"" << (i)->c_str() << "\"";
				}
				str << "]";
			}
			if (this->properties.size() > 0) {
				str << ",\"properties\": [";
				for (auto n = this->properties.begin(); n != this->properties.end(); n++) {
					if (n != this->properties.begin()) str << ",";
					std::string key = n->first;
					std::vector<propset::Property*> props = n->second;

					str << "{\"Group\":\"" << key << "\",\"properties\": [";

					for (auto i = props.begin(); i != props.end(); i++) {
						if (i != props.begin()) str << ",";
						str << (*i)->ToJson();
					}
					str << "]}";
				}
				str << "]";
			}
			return str.str();
		}
		virtual std::string buildBaseXml() const override{
			std::ostringstream str;
			str << common::ExtensionInfo::buildBaseXml();
			if (this->paths.size() > 0) {
				str << "<Paths>";
				for (auto i = this->paths.begin(); i != this->paths.end(); i++) {
					if (i != this->paths.begin()) str << ",";
					str << "<Path>" << (i)->c_str() << "</Path>";
				}
				str << "</Paths>";
			}
			if (this->properties.size() > 0) {
				str << "<properties>";
				for (auto n = this->properties.begin(); n != this->properties.end(); n++) {
					std::string key = n->first;
					std::vector<propset::Property*> props = n->second;

					str << "<Group>";
					str << "<Name>" << key << "</Name>";
					str << "<properties>";
					for (auto i = props.begin(); i != props.end(); i++) {
						str << (*i)->ToXML();
					}
					str << "</properties>";
					str << "</Group>";
				}
				str << "</properties>";
			}
			return str.str();
		}
	public:
		std::vector<std::string> paths;
		std::map<std::string, std::vector<propset::Property*>> properties;		
		OLESSExtensionInfo() {
			this->Extension = "oless";
			this->VersionName = "OLE Structured Storage";
		}

		virtual std::string ToJson() const override {
			std::ostringstream str;
			str << "{";
			str << this->buildBaseJson();			
			str << "}";
			return str.str();<commit_msg>bugfix - JSON & XML Escaping oless stream & storage names<commit_after>#pragma once
#include <string>
#include <map>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include "../common.hpp"
#include "./propset/DocumentSummary.hpp"

namespace oless {

	class OLESSExtensionInfo : public common::ExtensionInfo {
	protected:
		virtual std::string buildBaseJson() const override {
			std::ostringstream str;
			str << common::ExtensionInfo::buildBaseJson();
			if (this->paths.size() > 0) {
				str << ", \"Paths\": [";
				for (auto i = this->paths.begin(); i != this->paths.end(); i++) {
					if (i != this->paths.begin()) str << ",";
					str << "\"" << common::JsonEscape((i)->c_str()) << "\"";
				}
				str << "]";
			}
			if (this->properties.size() > 0) {
				str << ",\"properties\": [";
				for (auto n = this->properties.begin(); n != this->properties.end(); n++) {
					if (n != this->properties.begin()) str << ",";
					std::string key = n->first;
					std::vector<propset::Property*> props = n->second;

					str << "{\"Group\":\"" << common::JsonEscape(key) << "\",\"properties\": [";

					for (auto i = props.begin(); i != props.end(); i++) {
						if (i != props.begin()) str << ",";
						str << (*i)->ToJson();
					}
					str << "]}";
				}
				str << "]";
			}
			return str.str();
		}
		virtual std::string buildBaseXml() const override{
			std::ostringstream str;
			str << common::ExtensionInfo::buildBaseXml();
			if (this->paths.size() > 0) {
				str << "<Paths>";
				for (auto i = this->paths.begin(); i != this->paths.end(); i++) {
					if (i != this->paths.begin()) str << ",";
					str << "<Path>" << common::XmlEscape((i)->c_str()) << "</Path>";
				}
				str << "</Paths>";
			}
			if (this->properties.size() > 0) {
				str << "<properties>";
				for (auto n = this->properties.begin(); n != this->properties.end(); n++) {
					std::string key = n->first;
					std::vector<propset::Property*> props = n->second;

					str << "<Group>";
					str << "<Name>" << common::XmlEscape(key) << "</Name>";
					str << "<properties>";
					for (auto i = props.begin(); i != props.end(); i++) {
						str << (*i)->ToXML();
					}
					str << "</properties>";
					str << "</Group>";
				}
				str << "</properties>";
			}
			return str.str();
		}
	public:
		std::vector<std::string> paths;
		std::map<std::string, std::vector<propset::Property*>> properties;		
		OLESSExtensionInfo() {
			this->Extension = "oless";
			this->VersionName = "OLE Structured Storage";
		}

		virtual std::string ToJson() const override {
			std::ostringstream str;
			str << "{";
			str << this->buildBaseJson();			
			str << "}";
			return str.str();
{'fraction_non_alphanumeric': 0.23923904688701, 'fraction_numerical': 0.0015372790161414297, 'mean_word_length': 2.961187214611872, 'pattern_counts': {'":': 8, '<': 191, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008214', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1711, 'n_words': 394}