LTSV implemetation for D
D
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
LICENSE_1_0.txt
README.md

README.md

LTSV for D

ltsv-d is a LTSV implementation for D

Usage

Parse LTSV format

  • fromLTSV

Returns an associative array by default:

import ltsv;

immutable apacheLog = "host:127.0.0.1\tident:-\tuser:foo\ttime:[10/Oct/2000:13:55:36 -0700]\treq:GET /apache.gif HTTP/1.0\tstatus:200\tsize:777\treferer:http://www.example.com/start.html\tua:Mozilla/4.08 [en] (Win98; I ;Nav)";

auto record = fromLTSV(apacheLog);
assert(record["host"] == "127.0.0.1");
assert(record["size"] == "700");

Can returns a struct or class:

struct ApacheLog
{
    string host, ident, user, time, req, referer, ua;
    size_t size, status;
}

/// convert into struct or class directly
auto record = fromLTSV!ApacheLog(apacheLog);
assert(record.host == "127.0.0.1");
assert(record.size == 777);

Dump D object into LTSV format

/// foo:bar\thoge:fuga\tpiyo:puyo
auto line = ["foo":"bar", "hoge":"fuga", "piyo":"puyo"].toLTSV();

struct or class:

struct Test
{
    string a = "D";
    size_t b = 1999;
    double c = 10.0;
}

/// a:D b:1999 c:10.0
auto line = Test().toLTSV();

Test

% rdmd -unittest --main src/ltsv.d

Link

Copyright

AuthorMasahiro Nakagawa
CopyrightCopyright (c) 2013- Masahiro Nakagawa
LicenseBoost Software License, Version 1.0