~chrisppy/hare-atom

cb360e4b55dbc67a35a8a15343ca8a1d800864a1 — Chris Palmer a month ago d34af38 main
Finish extension impl

Signed-off-by: Chris Palmer <chris@red-oxide.org>
2 files changed, 112 insertions(+), 6 deletions(-)

M format/atom/+test.ha
M format/atom/scan.ha
M format/atom/+test.ha => format/atom/+test.ha +22 -0
@@ 28,6 28,9 @@ use strings;
	const f = scan(&buf)!;
	defer finish(&f);

	zcmp("Feed Extensions",
		1z,
		len(f.extensions));
	scmp("Feed Updated",
		"2003-12-13T18:30:02Z",
		f.updated);


@@ 112,6 115,9 @@ use strings;
	zcmp("Feed Entries",
		1z,
		len(f.entries));
	zcmp("Entry 1 Extensions",
		0z,
		len(f.entries[0].extensions));
	scmp("Entry 1 Updated",
		"2003-12-13T18:30:02Z",
		f.entries[0].updated);


@@ 175,6 181,11 @@ use strings;
	const buf = bufio::fixed(strings::toutf8(
`<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<a:simple>test</a:simple>
	<a:complex xlmns="a" type="ext">
		<a:t a="b"/>
		<a:name>test</a:name>
	</a:complex>
	<title type="text">dive into mark</title>
	<subtitle type="text">A lot of effort went into making this effortless</subtitle>
	<updated>2005-07-31T12:29:29Z</updated>


@@ 202,6 213,11 @@ use strings;
		<email>f8dy@example.com</email>
	</contributor>
	<entry>
		<a:simple>test</a:simple>
		<a:complex xlmns="a" type="ext">
			<a:t a="b"/>
			<a:name>test</a:name>
		</a:complex>
		<title type="text">Atom draft-07 snapshot</title>
		<link rel="alternate" type="text/html" href="http://example.org/2005/04/02/atom"/>
		<link rel="enclosure" type="audio/mpeg" length="1337" href="http://example.org/audio/ph34r_my_podcast.mp3"/>


@@ 227,6 243,9 @@ use strings;
	const f = scan(&buf)!;
	defer finish(&f);

	zcmp("Feed Extensions",
		14z,
		len(f.extensions));
	scmp("Feed Updated",
		"2005-07-31T12:29:29Z",
		f.updated);


@@ 341,6 360,9 @@ use strings;
	zcmp("Feed Entries",
		1z,
		len(f.entries));
	zcmp("Entry 1 Extensions",
		13z,
		len(f.entries[0].extensions));
	scmp("Entry 1 Updated",
		"2005-07-31T12:29:29Z",
		f.entries[0].updated);

M format/atom/scan.ha => format/atom/scan.ha +90 -6
@@ 45,7 45,7 @@ fn scan_feed(p: *xml::parser) (feed | error) = {
		case let tok: xml::token =>
			match(tok) {
			case let e: xml::elementstart =>
				switch (e) {
				switch (strings::trim(e)) {
				case "id" =>
					const txt = scan_text(p)?;
					f.id = txt.0;


@@ 85,15 85,59 @@ fn scan_feed(p: *xml::parser) (feed | error) = {
				case "link" =>
					const l = scan_link(p)?;
					append(f.links, l);
				case =>
				case "" =>
					continue;
				case =>
					append(f.extensions, tok);
				};
			case let e: xml::elementend =>
				switch (e) {
				switch (strings::trim(e)) {
				case "feed" =>
					break;
				case "id" =>
					continue;
				case "updated" =>
					continue;
				case "logo" =>
					continue;
				case "icon" =>
					continue;
				case "title" =>
					continue;
				case "subtitle" =>
					continue;
				case "rights" =>
					continue;
				case "generator" =>
					continue;
				case "entry" =>
					continue;
				case "author" =>
					continue;
				case "contributor" =>
					continue;
				case "category" =>
					continue;
				case "link" =>
					continue;
				case "" =>
					continue;
				case =>
					append(f.extensions, tok);
				};
			case let txt: xml::text =>
				switch (strings::trim(txt)) {
				case "" =>
					continue;
				case =>
					append(f.extensions, tok);
				};
			case let at: xml::attribute =>
				switch (strings::trim(at.0)) {
				case "" =>
					continue;
				case =>
					append(f.extensions, tok);
				};
			case =>
				continue;


@@ 114,7 158,7 @@ fn scan_entry(p: *xml::parser) (entry | error) = {
		case let tok: xml::token =>
			match(tok) {
			case let e: xml::elementstart =>
				switch (e) {
				switch (strings::trim(e)) {
				case "id" =>
					const txt = scan_text(p)?;
					en.id = txt.0;


@@ 148,15 192,55 @@ fn scan_entry(p: *xml::parser) (entry | error) = {
				case "link" =>
					const l = scan_link(p)?;
					append(en.links, l);
				case =>
				case "" =>
					continue;
				case =>
					append(en.extensions, tok);
				};
			case let e: xml::elementend =>
				switch (e) {
				switch (strings::trim(e)) {
				case "entry" =>
					break;
				case "id" =>
					continue;
				case "updated" =>
					continue;
				case "published" =>
					continue;
				case "title" =>
					continue;
				case "rights" =>
					continue;
				case "summary" =>
					continue;
				case "content" =>
					continue;
				case "author" =>
					continue;
				case "contributor" =>
					continue;
				case "category" =>
					continue;
				case "link" =>
					continue;
				case "" =>
					continue;
				case =>
					append(en.extensions, tok);
				};
			case let txt: xml::text =>
				switch (strings::trim(txt)) {
				case "" =>
					continue;
				case =>
					append(en.extensions, tok);
				};
			case let at: xml::attribute =>
				switch (strings::trim(at.0)) {
				case "" =>
					continue;
				case =>
					append(en.extensions, tok);
				};
			case =>
				continue;