Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
data / data-csv-parseOpenRuns on Liberas

CSV parse

The records of text, delimited text after RFC 4180, each a list of its fields. Records are separated by CRLF, LF or a lone CR; a line break at the very end of text ends the last record and does not start one, so empty text has no records and every other line, even an empty one, is a record (an empty line is one empty field). Fields are separated by delimiter, any character but '"', CR and LF (those are an error). A field starting with '"' is quoted: it runs to the next '"' not doubled, '""' inside it is one '"', and it may hold delimiters and line breaks; after its closing quote must come delimiter, a line break or the end, else an error; a quoted field never closed is an error. Any other field runs to the next delimiter or line break and may not contain '"' (an error). Nothing is trimmed; a BOM is an ordinary character; records may have different numbers of fields. text is at most 1,048,576 UTF-8 bytes.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init data-csv-parse --lang rust
cd data-csv-parse && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
data-csv-parse.wit
package root:component;

world root {
  export liberas:data/csv-read@0.1.0;
}
package liberas:data@0.1.0 {
  interface csv-read {
    parse: func(text: string, delimiter: char) -> result<list<list<string>>, string>;
  }
}
Test vectors22›
data-csv-parse.cases.json
[
  {
    "args": {
      "text": "aaa,bbb,ccc\r\nzzz,yyy,xxx\r\n",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "aaa,bbb,ccc\r\nzzz,yyy,xxx",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\"aaa\",\"b\r\nbb\",\"ccc\"\r\nzzz,yyy,xxx",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\"aaa\",\"b\"\"bb\",\"ccc\"",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "a,b\n\nc\rd\r\n\r\n",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\n",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "a,",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": ",,\n,",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\"\"",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": " a , \"b\" ",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "x;y\t z;\"1;2\"",
      "delimiter": ";"
    }
  },
  {
    "args": {
      "text": "a\tb\tc\n1\t2",
      "delimiter": "\t"
    }
  },
  {
    "args": {
      "text": "a😀b😀\"😀\"",
      "delimiter": "😀"
    }
  },
  {
    "args": {
      "text": "a,b",
      "delimiter": "\u0001"
    }
  },
  {
    "args": {
      "text": "\"unterminated",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "a\"b,c",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\"a\"b,c",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "\"a\" ,c",
      "delimiter": ","
    }
  },
  {
    "args": {
      "text": "a,b",
      "delimiter": "\""
    }
  },
  {
    "args": {
      "text": "a,b",
      "delimiter": "\n"
    }
  },
  {
    "args": {
      "text": "a,b",
      "delimiter": "\r"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 22 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 3,500,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.