Skip to content

repeatedly/ltsv-d

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 

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

About

LTSV implemetation for D

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages