Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.ion.internal.stage4_s

IonErrorCode singleThreadJsonImpl(size_t nMax, SymbolTable, TapeHolder)(scope const(char)[] text, ref SymbolTable table, ref TapeHolder tapeHolder, out size_t tapeLength)
if (nMax % 64 == 0 && nMax);
Examples:
static ubyte[] jsonToIonTest(scope const(char)[] text)
@trusted pure
{
    import mir.ion.exception: ionException;
    import mir.ion.internal.data_holder;
    import mir.ion.symbol_table;

    enum nMax = 128u;

    IonSymbolTable table;
    table.initialize;
    auto tapeHolder = IonDataHolder!(nMax * 4)(nMax * 4);
    size_t tapeLength;

    if (auto error = singleThreadJsonImpl!nMax(text, table, tapeHolder, tapeLength))
        throw error.ionException;

    return tapeHolder.data[0 .. tapeLength].dup;
}

import mir.ion.value;

assert(IonValue(jsonToIonTest("12345")).describe.get!IonUInt.get!ulong == 12345);
assert(IonValue(jsonToIonTest("-12345")).describe.get!IonNInt.get!long == -12345);
assert(IonValue(jsonToIonTest("-12.345")).describe.get!IonDecimal.get!double == -12.345);
assert(IonValue(jsonToIonTest("\t \r\n-12345e-3 text_after_whitespaces \t\r\n")).describe.get!IonFloat.get!double == -12.345);
assert(IonValue(jsonToIonTest(" -12345e-3 ")).describe.get!IonFloat.get!double == -12.345);
assert(IonValue(jsonToIonTest("   null{text_after_operators:{},[]")).describe.get!(typeof(null)) is null);
assert(IonValue(jsonToIonTest("true ")).describe.get!IonBool == true);
assert(IonValue(jsonToIonTest("  false")).describe.get!IonBool == false);
assert(IonValue(jsonToIonTest(` "string"{text_after_operators:{},[]`)).describe.get!IonString.data == "string");

enum str = "iwfpwqocbpwoewouivhqpeobvnqeon wlekdnfw;lefqoeifhq[woifhdq[owifhq[owiehfq[woiehf[  oiehwfoqwewefiqweopurefhqweoifhqweofihqeporifhq3eufh38hfoidf";
auto data = jsonToIonTest(`"` ~ str ~ `"`);
assert(IonValue(jsonToIonTest(`"` ~ str ~ `"`)).describe.get!IonString.data == str);

assert(IonValue(jsonToIonTest(`"hey \uD801\uDC37tee"`)).describe.get!IonString.data == "hey 𐐷tee");
assert(IonValue(jsonToIonTest(`[]`)).describe.get!IonList.data.length == 0);
assert(IonValue(jsonToIonTest(`{}`)).describe.get!IonStruct.data.length == 0);

assert(jsonToIonTest(" [ {}, true , \t\r\nfalse, null, \"string\", 12.3 ]") ==
    cast(ubyte[])"\xbe\x8e\xd0\x11\x10\x0f\x86\x73\x74\x72\x69\x6e\x67\x52\xc1\x7b");

data = jsonToIonTest(` { "a": "b",  "key": ["array", {"a": "c" } ] } `);
assert(data == cast(ubyte[])"\xde\x8f\x8a\x81b\x8b\xba\x85array\xd3\x8a\x81c");

data = jsonToIonTest(
`{
    "tags":[
        "russian",
        "novel",
        "19th century"
    ]
}`);