Exemplo n.º 1
0
void SQDbgServer::Attribute(const SQChar *name,const SQChar *value)
{
	XMLElementState *self = &xmlstate[_xmlcurrentement];
	assert(!self->haschildren); //cannot have attributes if already has children
	const SQChar *escval = escape_xml(value);
	_scratchstring.resize(5+scstrlen(name)+scstrlen(escval));
	scsprintf(&_scratchstring[0],_SC(" %s=\"%s\""),name,escval);
	SendChunk(&_scratchstring[0]);
}
Exemplo n.º 2
0
std::string
create_xml_node_name(const char *name,
                     const char **atts) {
  int i;
  std::string node_name = std::string("<") + name;
  for (i = 0; (NULL != atts[i]) && (NULL != atts[i + 1]); i += 2)
    node_name += std::string(" ") + atts[i] + "=\"" +
      escape_xml(atts[i + 1]) + "\"";
  node_name += ">";

  return node_name;
}
static void
xml_ofend(void *state, char *fname, bool isnull)
{
	pgspParserContext *ctx = (pgspParserContext *)state;
	word_table *p;
	char *s;

	p =	search_word_table(propfields, fname, ctx->mode);
	s = (p ? p->longname : fname);
	
	appendStringInfoString(ctx->dest, "</");
	appendStringInfoString(ctx->dest, escape_xml(hyphenate_words(ctx, s)));
	appendStringInfoChar(ctx->dest, '>');
}
static void
xml_scalar(void *state, char *token, JsonTokenType tokentype)
{
	pgspParserContext *ctx = (pgspParserContext *)state;
	const char *s = token;

	if (ctx->valconverter)
		s = ctx->valconverter(token, PGSP_JSON_XMLIZE);

	if (tokentype == JSON_TOKEN_STRING)
		s = escape_xml(s);

	appendStringInfoString(ctx->dest, s);
	ctx->last_elem_is_object = false;
}
static void
xml_ofstart(void *state, char *fname, bool isnull)
{
	word_table *p;
	pgspParserContext *ctx = (pgspParserContext *)state;
	char *s;

	p = search_word_table(propfields, fname, ctx->mode);
	if (!p)
	{
		ereport(DEBUG1,
				(errmsg("Short JSON parser encoutered unknown field name: \"%s\".", fname),
				 errdetail_log("INPUT: \"%s\"", ctx->org_string)));
	}		
	s = (p ? p->longname : fname);

	/*
	 * save current process context
	 * There's no problem if P_Plan appears recursively.
	 */
	if (p && (p->tag == P_Plan || p->tag == P_Triggers))
		ctx->processing = p->tag;

	appendStringInfoChar(ctx->dest, '\n');
	appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP);

	ctx->valconverter = NULL;

	appendStringInfoChar(ctx->dest, '<');
	appendStringInfoString(ctx->dest, escape_xml(hyphenate_words(ctx, s)));
	appendStringInfoChar(ctx->dest, '>');
	ctx->valconverter = (p ? p->converter : NULL);

	/*
	 * If the object field name is Plan or Triggers, the value should be an
	 * array and the items are tagged by other than "Item". "Item"s appear
	 * only in Output field.
	 */
	if (p && (p->tag == P_Plans || p->tag == P_Triggers))
		ctx->not_item = bms_add_member(ctx->not_item, ctx->level + 1);
	else
		ctx->not_item = bms_del_member(ctx->not_item, ctx->level + 1);
}
Exemplo n.º 6
0
sk_sp<SkPDFObject> SkPDFMetadata::MakeXMPObject(
        const SkDocument::PDFMetadata& metadata,
        const UUID& doc,
        const UUID& instance) {
    static const char templateString[] =
            "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
            "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"\n"
            " x:xmptk=\"Adobe XMP Core 5.4-c005 78.147326, "
            "2012/08/23-13:03:03\">\n"
            "<rdf:RDF "
            "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
            "<rdf:Description rdf:about=\"\"\n"
            " xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"\n"
            " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
            " xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\"\n"
            " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"\n"
            " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
            "<pdfaid:part>2</pdfaid:part>\n"
            "<pdfaid:conformance>B</pdfaid:conformance>\n"
            "%s"  // ModifyDate
            "%s"  // CreateDate
            "%s"  // xmp:CreatorTool
            "<dc:format>application/pdf</dc:format>\n"
            "%s"  // dc:title
            "%s"  // dc:description
            "%s"  // author
            "%s"  // keywords
            "<xmpMM:DocumentID>uuid:%s</xmpMM:DocumentID>\n"
            "<xmpMM:InstanceID>uuid:%s</xmpMM:InstanceID>\n"
            "%s"  // pdf:Producer
            "%s"  // pdf:Keywords
            "</rdf:Description>\n"
            "</rdf:RDF>\n"
            "</x:xmpmeta>\n"  // Note:  the standard suggests 4k of padding.
            "<?xpacket end=\"w\"?>\n";

    SkString creationDate;
    SkString modificationDate;
    if (metadata.fCreation.fEnabled) {
        SkString tmp;
        metadata.fCreation.fDateTime.toISO8601(&tmp);
        SkASSERT(0 == count_xml_escape_size(tmp));
        // YYYY-mm-ddTHH:MM:SS[+|-]ZZ:ZZ; no need to escape
        creationDate = SkStringPrintf("<xmp:CreateDate>%s</xmp:CreateDate>\n",
                                      tmp.c_str());
    }
    if (metadata.fModified.fEnabled) {
        SkString tmp;
        metadata.fModified.fDateTime.toISO8601(&tmp);
        SkASSERT(0 == count_xml_escape_size(tmp));
        modificationDate = SkStringPrintf(
                "<xmp:ModifyDate>%s</xmp:ModifyDate>\n", tmp.c_str());
    }
    SkString title =
            escape_xml(metadata.fTitle,
                       "<dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">",
                       "</rdf:li></rdf:Alt></dc:title>\n");
    SkString author =
            escape_xml(metadata.fAuthor, "<dc:creator><rdf:Bag><rdf:li>",
                       "</rdf:li></rdf:Bag></dc:creator>\n");
    // TODO: in theory, XMP can support multiple authors.  Split on a delimiter?
    SkString subject = escape_xml(
            metadata.fSubject,
            "<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">",
            "</rdf:li></rdf:Alt></dc:description>\n");
    SkString keywords1 =
            escape_xml(metadata.fKeywords, "<dc:subject><rdf:Bag><rdf:li>",
                       "</rdf:li></rdf:Bag></dc:subject>\n");
    SkString keywords2 = escape_xml(metadata.fKeywords, "<pdf:Keywords>",
                                    "</pdf:Keywords>\n");
    // TODO: in theory, keywords can be a list too.

    SkString producer("<pdf:Producer>" SKPDF_PRODUCER "</pdf:Producer>\n");
    if (!metadata.fProducer.isEmpty()) {
        // TODO: register a developer prefix to make
        // <skia:SKPDF_CUSTOM_PRODUCER_KEY> a real XML tag.
        producer = escape_xml(
                metadata.fProducer, "<pdf:Producer>",
                "</pdf:Producer>\n<!-- <skia:" SKPDF_CUSTOM_PRODUCER_KEY ">"
                SKPDF_PRODUCER "</skia:" SKPDF_CUSTOM_PRODUCER_KEY "> -->\n");
    }

    SkString creator = escape_xml(metadata.fCreator, "<xmp:CreatorTool>",
                                  "</xmp:CreatorTool>\n");
    SkString documentID = uuid_to_string(doc);  // no need to escape
    SkASSERT(0 == count_xml_escape_size(documentID));
    SkString instanceID = uuid_to_string(instance);
    SkASSERT(0 == count_xml_escape_size(instanceID));
    return sk_make_sp<PDFXMLObject>(SkStringPrintf(
            templateString, modificationDate.c_str(), creationDate.c_str(),
            creator.c_str(), title.c_str(), subject.c_str(), author.c_str(),
            keywords1.c_str(), documentID.c_str(), instanceID.c_str(),
            producer.c_str(), keywords2.c_str()));
}
Exemplo n.º 7
0
static int
S_render_node(cmark_node *node, cmark_event_type ev_type,
              struct render_state *state, long options)
{
	cmark_strbuf *xml = state->xml;
	bool literal = false;
	cmark_delim_type delim;
	bool entering = (ev_type == CMARK_EVENT_ENTER);

	if (entering) {
		indent(state);
		cmark_strbuf_printf(xml, "<%s",
		                    cmark_node_get_type_string(node));

		if (options & CMARK_OPT_SOURCEPOS && node->start_line != 0) {
			cmark_strbuf_printf(xml, " sourcepos=\"%d:%d-%d:%d\"",
			                    node->start_line,
			                    node->start_column,
			                    node->end_line,
			                    node->end_column);
		}

		literal = false;

		switch (node->type) {
		case CMARK_NODE_TEXT:
		case CMARK_NODE_CODE:
		case CMARK_NODE_HTML:
		case CMARK_NODE_INLINE_HTML:
			cmark_strbuf_puts(xml, ">");
			escape_xml(xml, node->as.literal.data,
			           node->as.literal.len);
			cmark_strbuf_puts(xml, "</");
			cmark_strbuf_puts(xml,
			                  cmark_node_get_type_string(node));
			literal = true;
			break;
		case CMARK_NODE_LIST:
			switch (cmark_node_get_list_type(node)) {
			case CMARK_ORDERED_LIST:
				cmark_strbuf_puts(xml, " type=\"ordered\"");
				cmark_strbuf_printf(xml, " start=\"%d\"",
				                    cmark_node_get_list_start(node));
				delim = cmark_node_get_list_delim(node);
				if (delim == CMARK_PAREN_DELIM) {
					cmark_strbuf_puts(xml,
					                  " delim=\"paren\"");
				} else if (delim == CMARK_PERIOD_DELIM) {
					cmark_strbuf_puts(xml,
					                  " delim=\"period\"");
				}
				break;
			case CMARK_BULLET_LIST:
				cmark_strbuf_puts(xml, " type=\"bullet\"");
				break;
			default:
				break;
			}
			cmark_strbuf_printf(xml, " tight=\"%s\"",
			                    (cmark_node_get_list_tight(node) ?
			                     "true" : "false"));
			break;
		case CMARK_NODE_HEADER:
			cmark_strbuf_printf(xml, " level=\"%d\"",
			                    node->as.header.level);
			break;
		case CMARK_NODE_CODE_BLOCK:
			if (node->as.code.info.len > 0) {
				cmark_strbuf_puts(xml, " info=\"");
				escape_xml(xml, node->as.code.info.data,
				           node->as.code.info.len);
				cmark_strbuf_putc(xml, '"');
			}
			cmark_strbuf_puts(xml, ">");
			escape_xml(xml, node->as.code.literal.data,
			           node->as.code.literal.len);
			cmark_strbuf_puts(xml, "</");
			cmark_strbuf_puts(xml,
			                  cmark_node_get_type_string(node));
			literal = true;
			break;
		case CMARK_NODE_LINK:
		case CMARK_NODE_IMAGE:
			cmark_strbuf_puts(xml, " destination=\"");
			escape_xml(xml, node->as.link.url, -1);
			cmark_strbuf_putc(xml, '"');
			cmark_strbuf_puts(xml, " title=\"");
			escape_xml(xml, node->as.link.title, -1);
			cmark_strbuf_putc(xml, '"');
			break;
		default:
			break;
		}
		if (node->first_child) {
			state->indent += 2;
		} else if (!literal) {
			cmark_strbuf_puts(xml, " /");
		}
		cmark_strbuf_puts(xml, ">\n");


	} else if (node->first_child) {
		state->indent -= 2;
		indent(state);
		cmark_strbuf_printf(xml, "</%s>\n",
		                    cmark_node_get_type_string(node));
	}

	return 1;
}
Exemplo n.º 8
0
SkPDFObject* SkPDFMetadata::createXMPObject(const UUID& doc,
                                            const UUID& instance) const {
    static const char templateString[] =
            "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
            "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"\n"
            " x:xmptk=\"Adobe XMP Core 5.4-c005 78.147326, "
            "2012/08/23-13:03:03\">\n"
            "<rdf:RDF "
            "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
            "<rdf:Description rdf:about=\"\"\n"
            " xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"\n"
            " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
            " xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\"\n"
            " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"\n"
            " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
            "<pdfaid:part>2</pdfaid:part>\n"
            "<pdfaid:conformance>B</pdfaid:conformance>\n"
            "%s"  // ModifyDate
            "%s"  // CreateDate
            "%s"  // MetadataDate
            "%s"  // xmp:CreatorTool
            "<dc:format>application/pdf</dc:format>\n"
            "%s"  // dc:title
            "%s"  // dc:description
            "%s"  // author
            "%s"  // keywords
            "<xmpMM:DocumentID>uuid:%s</xmpMM:DocumentID>\n"
            "<xmpMM:InstanceID>uuid:%s</xmpMM:InstanceID>\n"
            "<pdf:Producer>Skia/PDF</pdf:Producer>\n"
            "%s"  // pdf:Keywords
            "</rdf:Description>\n"
            "</rdf:RDF>\n"
            "</x:xmpmeta>\n"  // Note:  the standard suggests 4k of padding.
            "<?xpacket end=\"w\"?>\n";

    SkString creationDate;
    SkString modificationDate;
    SkString metadataDate;
    if (fCreation) {
        SkString tmp;
        fCreation->toISO8601(&tmp);
        SkASSERT(0 == count_xml_escape_size(tmp));
        // YYYY-mm-ddTHH:MM:SS[+|-]ZZ:ZZ; no need to escape
        creationDate = sk_string_printf("<xmp:CreateDate>%s</xmp:CreateDate>\n",
                                        tmp.c_str());
    }
    if (fModified) {
        SkString tmp;
        fModified->toISO8601(&tmp);
        SkASSERT(0 == count_xml_escape_size(tmp));
        modificationDate = sk_string_printf(
                "<xmp:ModifyDate>%s</xmp:ModifyDate>\n", tmp.c_str());
        metadataDate = sk_string_printf(
                "<xmp:MetadataDate>%s</xmp:MetadataDate>\n", tmp.c_str());
    }

    SkString title =
            escape_xml(get(fInfo, "Title"), "<dc:title><rdf:Alt><rdf:li>",
                       "</rdf:li></rdf:Alt></dc:title>\n");
    SkString author =
            escape_xml(get(fInfo, "Author"), "<dc:creator><rdf:Bag><rdf:li>",
                       "</rdf:li></rdf:Bag></dc:creator>\n");
    // TODO: in theory, XMP can support multiple authors.  Split on a delimiter?
    SkString subject = escape_xml(get(fInfo, "Subject"),
                                  "<dc:description><rdf:Alt><rdf:li>",
                                  "</rdf:li></rdf:Alt></dc:description>\n");
    SkString keywords1 =
            escape_xml(get(fInfo, "Keywords"), "<dc:subject><rdf:Bag><rdf:li>",
                       "</rdf:li></rdf:Bag></dc:subject>\n");
    SkString keywords2 = escape_xml(get(fInfo, "Keywords"), "<pdf:Keywords>",
                                    "</pdf:Keywords>\n");

    // TODO: in theory, keywords can be a list too.
    SkString creator = escape_xml(get(fInfo, "Creator"), "<xmp:CreatorTool>",
                                  "</xmp:CreatorTool>\n");
    SkString documentID = uuid_to_string(doc);  // no need to escape
    SkASSERT(0 == count_xml_escape_size(documentID));
    SkString instanceID = uuid_to_string(instance);
    SkASSERT(0 == count_xml_escape_size(instanceID));
    return new PDFXMLObject(sk_string_printf(
            templateString, modificationDate.c_str(), creationDate.c_str(),
            metadataDate.c_str(), creator.c_str(), title.c_str(),
            subject.c_str(), author.c_str(), keywords1.c_str(),
            documentID.c_str(), instanceID.c_str(), keywords2.c_str()));
}
Exemplo n.º 9
0
void LoadPuz(Puzzle * puz, const std::string & filename, void * /* dummy */)
{
    std::ifstream stream(filename.c_str(), std::ios::in | std::ios::binary);
    if (stream.fail())
        throw FileError(filename);
    istream_wrapper f(stream);

    const unsigned short c_primary = f.ReadShort();
    if (strcmp(f.ReadString(12).c_str(), "ACROSS&DOWN") != 0)
        throw FileTypeError("puz");

    const unsigned short c_cib = f.ReadShort();
    unsigned char c_masked[8];
    f.ReadCharArray(c_masked, 8);

    // Version is "[major].[minor]\0"
    // We can read puzzles of 1.[anything]
    std::string versionstr = f.ReadString(4);
    if (versionstr[0] != '1' || ! isdigit(versionstr[2]))
        throw LoadError("Unknown puz version.");

    const unsigned short version = 10 + versionstr[2] - 0x30;

    f.Skip(2); // 1 unknown short
    const unsigned short c_grid = f.ReadShort();
    f.Skip(2 * 6); // 6 noise shorts

    const unsigned char width  = f.ReadChar();
    const unsigned char height = f.ReadChar();

    const unsigned short num_clues = f.ReadShort();
    const unsigned short grid_type = f.ReadShort();
    const unsigned short grid_flag = f.ReadShort();

    puz->GetGrid().SetCksum(c_grid);
    puz->GetGrid().SetType(grid_type);
    puz->GetGrid().SetFlag(grid_flag);
    puz->GetGrid().SetSize(width, height);

    // Read user text and solution
    std::string solution = f.ReadString(width * height);
    std::string text     = f.ReadString(width * height);

    // Set the grid's solution and text
    std::string::iterator sol_it  = solution.begin();
    std::string::iterator text_it = text.begin();
    for (Square * square = puz->GetGrid().First();
         square != NULL;
         square = square->Next())
    {
        // Solution
        if (*sol_it == '.' || *sol_it == ':' && puz->IsDiagramless())
            square->SetSolution(puz::Square::Black);
        else if (*sol_it == '-')
            square->SetSolution(puz::Square::Blank);
        else
            square->SetSolution(decode_puz(std::string(1, *sol_it)));
        ++sol_it;

        // Text
        if (square->IsBlack() && ! puz->IsDiagramless())
            square->SetText(puz::Square::Black);
        else if (*text_it == '-' || *text_it == 0)
            square->SetText(puz::Square::Blank);
        else if (puz->IsDiagramless() && (*text_it == '.' || *text_it == ':'))
        {
            // Black squares in a diagramless puzzle.
            if (*text_it == '.')
                square->SetText(puz::Square::Black);
            else if (*text_it == ':')
                square->SetText(puz::Square::Blank);
        }
        else
        {
            square->SetText(decode_puz(std::string(1, *text_it)));
            if (islower(*text_it))
                square->AddFlag(FLAG_PENCIL);
        }
        ++text_it;
    }
    assert(sol_it == solution.end() && text_it == text.end());
    puz->NumberGrid();

    // General puzzle info
    puz->SetTitle(decode_puz(f.ReadString()));
    puz->SetAuthor(decode_puz(f.ReadString()));
    puz->SetCopyright(decode_puz(f.ReadString()));

    // Clues
    std::vector<string_t> clues;
    clues.reserve(num_clues);
    // Save unaltered clues for the checksums
    std::vector<std::string> cksum_clues;
    cksum_clues.reserve(num_clues);
    for (size_t i = 0; i < num_clues; ++i)
    {
        cksum_clues.push_back(f.ReadString());
        clues.push_back(escape_xml(decode_puz(cksum_clues.back())));
    }

    puz->SetAllClues(clues);

    // Notes
    std::string notes = f.ReadString();
    puz->SetNotes(escape_xml(decode_puz(notes)));

    puz->SetOk(true);

    // Try to load the extra sections (i.e. GEXT, LTIM, etc).
    try {
        LoadSections(puz, f);
    }
    catch (std::ios::failure &) {
        // EOF here doesn't matter.
    }


    // Don't even bother with the checksums, since we check the validity
    // of the puzzle anyways
}
Exemplo n.º 10
0
///////////////////////////////////////////////////////////////////////////////
//
// ToXMLString
//
///////////////////////////////////////////////////////////////////////////////
int TMarcRecord::ToXMLString(typestr &a_xml)
{
    a_xml = "<record";
    if (!mStateManager->GetOutputXMLRecordFormat().is_empty())
    {
        a_xml.append(" format=\"");
        a_xml.append(mStateManager->GetOutputXMLRecordFormat());
        a_xml.append_char('\"');
    }
    if (!mStateManager->GetOutputXMLRecordType().is_empty())
    {
        a_xml.append(" type=\"");
        a_xml.append(mStateManager->GetOutputXMLRecordType());
        a_xml.append_char('\"');
    }
    a_xml.append(">\n");

    a_xml.append("  <leader>");
    a_xml.append(escape_xml(itsLeader));
    a_xml.append("</leader>\n");

    TMarcField *field = itsFirstField;
    while (field)
    {
        const char *tag = field->GetTag();
        const char *marcdata = field->GetLib1();
        size_t lng = strlen(marcdata);
        bool have_ind = IsFieldWithIndicators(OUTPUT, tag, marcdata, lng);
        if (!have_ind)
        {
            a_xml.append("  <controlfield tag=\"");
            a_xml.append(tag);
            a_xml.append("\">");
            a_xml.append(escape_xml(marcdata));
            a_xml.append("</controlfield>\n");
        }
        else
        {
            char *indicators = field->GetIndicators();
            a_xml.append("  <datafield tag=\"");
            a_xml.append(escape_xml(tag));
            a_xml.append("\" ind1=\"");
            char ind1[2] = {indicators[0], '\0'};
            char ind2[2] = {indicators[1], '\0'};
            a_xml.append(*ind1 ? escape_xml(ind1) : " ");
            a_xml.append("\" ind2=\"");
            a_xml.append(*ind2 ? escape_xml(ind2) : " ");
            a_xml.append("\">\n");

            const char *p = strchr(marcdata, START_OF_FIELD);
            while (p)
            {
                char code = p[1];
                typestr subfield = p + 2;
                char *end = strchr(subfield.str(), START_OF_FIELD);
                if (end)
                    *end = '\0';

                a_xml.append("    <subfield code=\"");
                char codestr[2] = {code, '\0'};
                a_xml.append(escape_xml(codestr));
                a_xml.append("\">");
                a_xml.append(escape_xml(subfield));
                a_xml.append("</subfield>\n");

                p = strchr(p + 1, START_OF_FIELD);
            }

            a_xml.append("  </datafield>\n");
        }

        field = field->GetNextField();
    }
    a_xml.append("</record>\n");

    DelTree();

    return 0;
}