/*
 * Copyright (c) 2011-2026 Ross Cunniff
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

// CSV read/write functions that conform to RFC 4180:
//      https://datatracker.ietf.org/doc/html/rfc4180
// However, a user can modify that to other related formats via flags

namespace csv {
    extern read;     // arr = csv::read(inputFile [, flags, [separator]])
    extern readRow;  // list = csv::readRow(inputFile [, flags, [separator]])
    extern write;    // csv::write(outputFile, arr [, flags, [separator]])
    extern writeRow; // csv::writeRow(outputFile, list [, flags, [separator]])

    const E_MEMORY       = -1;   // Memory allocation failure
    const E_UTF8         = -2;   // Invalid UTF-8 encoding
    const E_OADL         = -3;   // Other OADL error

    // Flags for read
    const STRIP_SPACE = 0x000001;       // Strip pre/post whitespace from fields
    const CONVERT_NUMBERS = 0x000002;   // Convert strings to numeric types
    const CONVERT_LONG = 0x000004;      // ... as long/double
    const COMBINE_CONSECUTIVE = 0x000008; // Combine consec. separators into one
    const READ_ARRAY = 0x000010;        // Read as a 2D Array

    // Flags for read and write
    const ALT_SEPARATOR = 0x000100;     // Use optional sep. instead of comma

    const READ_FLAGS_MASK = 0x00011F;   // Valid read flags
    const WRITE_FLAGS_MASK = 0x000100;  // Valid write flags

    var errNumber;      // Error number if read fails, from E_* above
    var errLine;        // Line number at which failure occurred
}

using extern "libcsv";