bobzhang/p5/io does not have a README file

    CsvError

    pub suberror CsvError {
    CsvError(String)
    } derive(
    Debug
    )

    Errors in malformed CSV.

    XmlError

    pub suberror XmlError {
    XmlError(String)
    } derive(
    Debug
    )

    Errors in malformed XML.

    Column

    pub(all) enum Column {
    Index(Int)
    Title(String)
    }

    A column, by index or by title.

    Table

    pub struct Table {
    // private fields
    }

    A table of rows and titled columns (p5.Table).

    Table::add_column

    fn Table::add_column(self : Table, title? : String) -> Unit

    Adds a column (untitled by default).

    Table::add_row

    fn Table::add_row(self : Table, row? : TableRow) -> TableRow

    Adds a row (an empty one by default) and returns it.

    Table::clear_rows

    fn Table::clear_rows(self : Table) -> Unit

    Removes every row.

    Table::columns

    fn Table::columns(self : Table) -> Array[String?]

    Column titles (None for untitled columns).

    Table::find_row

    fn Table::find_row(self : Table, value : String, column : Column) -> TableRow?

    The first row whose cell in column equals value.

    Table::find_rows

    fn Table::find_rows(self : Table, value : String, column : Column) -> Array[TableRow]

    Every row whose cell in column equals value.

    Table::from_csv

    fn Table::from_csv(text : String, header? : Bool, separator? : Char) -> Table raise CsvError

    Builds a table from CSV text (with a header row when header).

    Table::get

    fn Table::get(self : Table, row : Int, column : Column) -> String

    A cell.

    Table::get_array

    fn Table::get_array(self : Table) -> Array[Array[String]]

    The rows as arrays of cells.

    Table::get_column

    fn Table::get_column(self : Table, column : Column) -> Array[String]

    All cells of a column.

    Table::get_column_count

    fn Table::get_column_count(self : Table) -> Int

    Number of columns.

    Table::get_num

    fn Table::get_num(self : Table, row : Int, column : Column) -> Double

    A cell as a number.

    Table::get_object

    fn Table::get_object(self : Table, header_column? : String) ->
    Json

    The rows as JSON objects keyed by column title, themselves keyed by the cell in header_column (or by row index), like p5's getObject.

    Table::get_row

    fn Table::get_row(self : Table, index : Int) -> TableRow?

    The row at index.

    Table::get_row_count

    fn Table::get_row_count(self : Table) -> Int

    Number of rows.

    Table::get_rows

    fn Table::get_rows(self : Table) -> Array[TableRow]

    All rows.

    Table::get_string

    fn Table::get_string(self : Table, row : Int, column : Column) -> String

    A cell as a string.

    Table::match_row

    fn Table::match_row(self : Table, matches : (String) -> Bool, column : Column) -> TableRow?

    The first row whose cell in column satisfies matches (p5's matchRow takes a regular expression).

    Table::match_rows

    fn Table::match_rows(self : Table, matches : (String) -> Bool, column : Column) -> Array[TableRow]

    Every row whose cell in column satisfies matches.

    Table::new

    fn Table::new() -> Table

    Creates an empty table.

    Table::remove_column

    fn Table::remove_column(self : Table, column : Column) -> Unit

    Removes a column.

    Table::remove_row

    fn Table::remove_row(self : Table, index : Int) -> Unit

    Removes the row at index.

    Table::remove_tokens

    fn Table::remove_tokens(self : Table, chars : String, column? : Column) -> Unit

    Removes every occurrence of the characters in chars (in one column, or everywhere).

    Table::set

    fn Table::set(self : Table, row : Int, column : Column, value : String) -> Unit

    Sets a cell.

    Table::set_num

    fn Table::set_num(self : Table, row : Int, column : Column, value : Double) -> Unit

    Sets a cell to a number.

    Table::set_string

    fn Table::set_string(self : Table, row : Int, column : Column, value : String) -> Unit

    Sets a cell to a string.

    Table::to_csv

    fn Table::to_csv(self : Table, separator? : Char) -> String

    The table as CSV (with the header row when every column has a title).

    Table::trim

    fn Table::trim(self : Table, column? : Column) -> Unit

    Removes spaces (in one column, or everywhere), like p5's trim().

    TableRow

    pub struct TableRow {
    // private fields
    }

    A row of a Table.

    TableRow::cells

    fn TableRow::cells(self : TableRow) -> Array[String]

    The cells of the row.

    TableRow::get

    fn TableRow::get(self : TableRow, column : Column) -> String

    The cell in column (empty when out of range).

    TableRow::get_num

    fn TableRow::get_num(self : TableRow, column : Column) -> Double

    The cell parsed as a number (parseFloat); NaN when it isn't one.

    TableRow::get_string

    fn TableRow::get_string(self : TableRow, column : Column) -> String

    The cell as a string.

    TableRow::new

    fn TableRow::new(cells? : Array[String]) -> TableRow

    Creates a row from its cells.

    TableRow::set

    fn TableRow::set(self : TableRow, column : Column, value : String) -> Unit

    Sets a cell.

    TableRow::set_num

    fn TableRow::set_num(self : TableRow, column : Column, value : Double) -> Unit

    Sets a cell to a number.

    TableRow::set_string

    fn TableRow::set_string(self : TableRow, column : Column, value : String) -> Unit

    Sets a cell to a string.

    Xml

    pub struct Xml {
    // private fields
    }

    An XML element (p5.XML).

    Xml::add_child

    fn Xml::add_child(self : Xml, child : Xml) -> Unit

    Appends a child element.

    Xml::get_attribute_count

    fn Xml::get_attribute_count(self : Xml) -> Int

    Number of attributes.

    Xml::get_child

    fn Xml::get_child(self : Xml, index : Int) -> Xml?

    The child element at index.

    Xml::get_child_by_name

    fn Xml::get_child_by_name(self : Xml, name : String) -> Xml?

    The first child element with the given tag name.

    Xml::get_children

    fn Xml::get_children(self : Xml, name? : String) -> Array[Xml]

    Child elements, or every descendant with the given tag name (like getElementsByTagName).

    Xml::get_content

    fn Xml::get_content(self : Xml, default? : String) -> String?

    The text content, with runs of whitespace replaced by commas (as p5 does); default when empty.

    Xml::get_name

    fn Xml::get_name(self : Xml) -> String

    The tag name.

    Xml::get_num

    fn Xml::get_num(self : Xml, name : String, default? : Double) -> Double

    An attribute as a number (default when missing, empty or 0, like p5's Number(v) || default || 0).

    Xml::get_parent

    fn Xml::get_parent(self : Xml) -> Xml

    The parent element (the element itself for the root).

    Xml::get_string

    fn Xml::get_string(self : Xml, name : String, default? : String) -> String?

    An attribute as a string (default when missing or empty).

    Xml::has_attribute

    fn Xml::has_attribute(self : Xml, name : String) -> Bool

    Whether the attribute exists with a non-empty value (as in p5).

    Xml::has_children

    fn Xml::has_children(self : Xml) -> Bool

    Whether the element has child elements.

    Xml::list_attributes

    fn Xml::list_attributes(self : Xml) -> Array[String]

    Attribute names.

    Xml::list_children

    fn Xml::list_children(self : Xml) -> Array[String]

    The node names of all children ("#text" for text, like the DOM).

    Xml::new

    fn Xml::new(name? : String) -> Xml

    Creates an empty element (<root/> by default, as in p5).

    Xml::parse

    fn Xml::parse(text : String) -> Xml raise XmlError

    Parses an XML document and returns its root element.

    test {
    let x = @io.Xml::parse(
    "<animals><mammal id=\"0\" species=\"Panthera\">Goat</mammal></animals>",
    )
    inspect(x.get_name(), content="animals")
    let m = x.get_child_by_name("mammal").unwrap()
    inspect(m.get_content().unwrap_or(""), content="Goat")
    inspect(m.get_num("id"), content="0")
    inspect(
    x.serialize(),
    content="<animals><mammal id=\"0\" species=\"Panthera\">Goat</mammal></animals>",
    )
    }

    Xml::remove_child

    fn Xml::remove_child(self : Xml, index : Int) -> Unit

    Removes the child element at index.

    Xml::remove_child_by_name

    fn Xml::remove_child_by_name(self : Xml, name : String) -> Unit

    Removes the first child element with the given name.

    Xml::serialize

    fn Xml::serialize(self : Xml) -> String

    The element as XML text (like XMLSerializer).

    Xml::set_attribute

    fn Xml::set_attribute(self : Xml, name : String, value : String) -> Unit

    Sets an attribute.

    Xml::set_content

    fn Xml::set_content(self : Xml, content : String) -> Unit

    Replaces the content with text (only when there are no child elements, as in p5).

    Xml::set_name

    fn Xml::set_name(self : Xml, name : String) -> Unit

    Renames the element.

    XmlNode

    pub(all) enum XmlNode {
    Element(Xml)
    Text(String)
    CData(String)
    Comment(String)
    }

    A node in an XML tree.

    parse_csv

    fn parse_csv(csv : String, separator? : Char, delimiter? : Char) -> Array[Array[String]] raise CsvError

    Parses CSV into rows of fields. delimiter quotes fields (doubled to escape it); separator separates them.

    test {
    debug_inspect(
    @io.parse_csv("a,\"b,c\",\"d\"\"e\"\n1,2,3\n"),
    content=(
    #|[["a", "b,c", "d\"e"], ["1", "2", "3"]]
    ),
    )
    }

    parse_float

    fn parse_float(s : String) -> Double

    JavaScript parseFloat: the longest numeric prefix, NaN when none.

    stringify_csv

    fn stringify_csv(rows : ArrayView[Array[String]], separator? : Char, delimiter? : Char, eof? : Bool) -> String

    Serializes rows as CSV, quoting fields that contain the delimiter, the separator or a line break. Every row ends with \n (unless eof is false, then the last one doesn't).