From 1d30d4b2225be7f152de94b007d81a5d7b7a1c3a Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 29 Jun 2016 22:28:53 -0400 Subject: associated array instead of json --- src/sdp/ao_header_extract_native.d | 78 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/sdp/ao_header_extract_native.d') diff --git a/src/sdp/ao_header_extract_native.d b/src/sdp/ao_header_extract_native.d index 2f86d89..7bcf965 100644 --- a/src/sdp/ao_header_extract_native.d +++ b/src/sdp/ao_header_extract_native.d @@ -1,5 +1,5 @@ /+ - extract native/orig header return json + extract native/orig header return associative array +/ template SiSUheaderExtractNative() { private import @@ -9,17 +9,17 @@ template SiSUheaderExtractNative() { std.conv : to; private import ao_rgx; - struct HeaderDocMetadataAndMakeNativeToJson { + struct HeaderDocMetadataAndMakeNativeToAA { mixin SiSUregisters; mixin SiSUrgxInitFlags; mixin RgxInit; auto rgx = Rgx(); enum State { off, on } string hm, hs; - auto header_metadata_and_make_jsonstr( + auto header_metadata_and_make_aa( string header, - JSONValue[string] dochead_meta, - JSONValue[string] dochead_make + string[string][string] dochead_meta, + string[string][string] dochead_make ) in { } body { @@ -39,13 +39,13 @@ template SiSUheaderExtractNative() { if (auto m = match(line, rgx.native_header_main)) { if (!empty(m.captures[2])) { if (hm == "creator") { - dochead_meta[hm]["author"].str = + dochead_meta[hm]["author"] = to!string(m.captures[2]); } else if (hm == "title") { - dochead_meta[hm]["main"].str = + dochead_meta[hm]["main"] = to!string(m.captures[2]); } else if (hm == "publisher") { - dochead_meta[hm]["name"].str = + dochead_meta[hm]["name"] = to!string(m.captures[2]); } } @@ -53,12 +53,12 @@ template SiSUheaderExtractNative() { if (!empty(s.captures[2])) { auto hs = to!string(s.captures[1]); if ((hm == "make" ) - && (dochead_make[hm].type() == JSON_TYPE.OBJECT)) { + && (dochead_make[hm])) { switch (hm) { case "make": if (match(hs, rgx.native_subhead_make)) { - if (dochead_make[hm][hs].type() == JSON_TYPE.STRING) { - dochead_make[hm][hs].str = to!string(s.captures[2]); + if (dochead_make[hm][hs]) { + dochead_make[hm][hs] = to!string(s.captures[2]); } } else { writeln("not a valid header type:", hm, ":", hs); @@ -69,12 +69,12 @@ template SiSUheaderExtractNative() { default: break; } - } else if (dochead_meta[hm].type() == JSON_TYPE.OBJECT) { + } else if (dochead_meta[hm]) { switch (hm) { case "creator": if (match(hs, rgx.native_subhead_creator)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -86,11 +86,11 @@ template SiSUheaderExtractNative() { case "title": if (match(hs, rgx.native_subhead_title)) { if ((hs == "subtitle") - && (dochead_meta[hm]["sub"].type() == JSON_TYPE.STRING)) { - dochead_meta[hm]["sub"].str = + && (dochead_meta[hm]["sub"])) { + dochead_meta[hm]["sub"] = to!string(s.captures[2]); - } else if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + } else if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -101,8 +101,8 @@ template SiSUheaderExtractNative() { break; case "rights": if (match(hs, rgx.native_subhead_rights)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -113,8 +113,8 @@ template SiSUheaderExtractNative() { break; case "date": if (match(hs, rgx.native_subhead_date)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -125,8 +125,8 @@ template SiSUheaderExtractNative() { break; case "original": if (match(hs, rgx.native_subhead_original)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -137,8 +137,8 @@ template SiSUheaderExtractNative() { break; case "classify": if (match(hs, rgx.native_subhead_classify)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -149,8 +149,8 @@ template SiSUheaderExtractNative() { break; case "identifier": if (match(hs, rgx.native_subhead_identifier)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -161,8 +161,8 @@ template SiSUheaderExtractNative() { break; case "notes": if (match(hs, rgx.native_subhead_notes)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -173,8 +173,8 @@ template SiSUheaderExtractNative() { break; case "publisher": if (match(hs, rgx.native_subhead_publisher)) { - if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - dochead_meta[hm][hs].str = + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = to!string(s.captures[2]); } } else { @@ -187,8 +187,8 @@ template SiSUheaderExtractNative() { destroy(hm); destroy(hs); // if (match(hs, rgx.native_subhead_links)) { - // if (dochead_meta[hm][hs].type() == JSON_TYPE.STRING) { - // dochead_meta[hm][hs].str = to!string(s.captures[2]); + // if (dochead_meta[hm][hs]) { + // dochead_meta[hm][hs] = to!string(s.captures[2]); // } // } else { // writeln("not a valid header type:", hm, ":", hs); @@ -264,7 +264,7 @@ template SiSUheaderExtractNative() { an_object.remove("is"); an_object.remove("attrib"); } - private auto headerNativeToJSON(in char[] src_header) { + private auto headerNativeToAA(in char[] src_header) { auto type = flags_type_init; type = [ "header" : State.off, @@ -273,9 +273,9 @@ template SiSUheaderExtractNative() { ]; string[string] an_object; int[string] line_occur; - auto dochead_make = parseJSON(make_jsonstr).object; - auto dochead_meta = parseJSON(meta_jsonstr).object; - auto set_header = HeaderDocMetadataAndMakeNativeToJson(); + auto dochead_make = make_aa; + auto dochead_meta = meta_aa; + auto set_header = HeaderDocMetadataAndMakeNativeToAA(); char[][] source_header_arr = split(cast(char[]) src_header, rgx.line_delimiter); foreach(header_line; source_header_arr) { @@ -295,7 +295,7 @@ template SiSUheaderExtractNative() { if (header_line.length == 0) { /+ header_make instructions (current line empty) +/ auto dochead_metadata_and_make = - set_header.header_metadata_and_make_jsonstr(strip(an_object["obj"]), dochead_meta, dochead_make); + set_header.header_metadata_and_make_aa(strip(an_object["obj"]), dochead_meta, dochead_make); static assert(!isTypeTuple!(dochead_metadata_and_make)); dochead_meta = dochead_metadata_and_make[0]; dochead_make = dochead_metadata_and_make[1]; -- cgit v1.2.3