Skip to content

Instantly share code, notes, and snippets.

@tomotaka
Last active December 12, 2015 07:28
Show Gist options
  • Save tomotaka/4736681 to your computer and use it in GitHub Desktop.
Save tomotaka/4736681 to your computer and use it in GitHub Desktop.
LTSV parser/dumper of dart lang
class LTSV {
static Map parse(String str) {
var pairs = str.trim().split("\t");
var ret = {};
for (var pair in pairs) {
var chunks = pair.split(":");
var name = chunks.removeAt(0);
ret[name] = chunks.join(":");
}
return ret;
}
static String dump(Map map) {
var chunks = map.keys.map((k)=>"${k}:${map[k]}");
return "${chunks.join("\t")}\n";
}
}
main() {
var str = "a:1\tb:2\n";
var parsed = LTSV.parse(str);
print("parsed[\"a\"]=${parsed["a"]}");
print("parsed[\"b\"]=${parsed["b"]}");
print("---dump---");
print(LTSV.dump(parsed));
}
@tomotaka
Copy link
Author

tomotaka commented Feb 8, 2013

http://api.dartlang.org/docs/releases/latest/dart_core/Collection.html says there is a join() method but my dart(Dart VM version: 0.2.6.0_15369_chrome-bot (Mon Nov 26 22:37:29 2012)) said there is no such method...

@tomotaka
Copy link
Author

tomotaka commented Feb 8, 2013

I updated my dart-sdk to version 0.3.4.0_r18115 (Tue Feb 5 05:52:09 2013) and join() worked.
Updated code to use join().

@tomotaka
Copy link
Author

tomotaka commented Feb 8, 2013

Revision2 supports older version(that doesn't have join()) of dart-sdk

@tomotaka
Copy link
Author

I uploaded this as a pub package!
and created a repo for this: https://github.com/tomotaka/dart-ltsv
maintenance of this code will be done on this new repository!
(I think my activities will not be so active about this repo, but any modifications are welcome.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment