Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
com.github.lonely-lockley:ltsv-parser
Advanced tools
"A new implementation of ltsv parser. Does not use regular expressions, respects quote and escape characters, can parse data in strict and lenient modes"
A new implementation of a small and fast LTSV parser. Compared to making/ltsv4j it:
Be careful - this parser instances are stateful and not synchronized!
Parser defaults allow to parse LTSV formatted data in strict mode:
LtsvParser parser = LtsvParser.builder().build();
Iterator<Map<String, String>> entries = parser.parse("city:Moscow\tlat:55.7522\tlon:37.6155",
StandardCharsets.UTF_8);
if (entries.hasNext()) {
Map<String, String> result = entries.next();
System.out.println(result.toString());
}
If a data is not fully compatible with LTSV it is still possible to parse that line:
LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse("city=`New York`\tlat=40.6943\tlon=-73.9249",
StandardCharsets.UTF_8);
By default parser works in strict mode. It will throw a ParseLtsvException if meets a problem in input data. For example a value without a key like this:
LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse("city=`New York`\t=40.6943\tlon=-73.9249",
StandardCharsets.UTF_8);
You can enable lenient parse mode when building a parser to make it ignore some recoverable errors in input data. In the case above lenient parser returns null
key for value 40.6943
. Lenient mode tries to do it's best to parse your data, but it is not guaranteed to be parsed correctly. You should test such cases thoroughly.
Parse a FileInputStream:
test.ltsv
city=Moscow lat=55.7522 lon=37.6155
city=`New York` lat=40.6943 lon=-73.9249
city=Berlin lat=52.5218 lon=13.4015
city=London lat=51.5000 lon=-0.1167
Parser.java
InputStream in = new FileInputStream(new File("test.ltsv"));
LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse(in);
while (entries.hasNext()) {
Map<String, String> result = entries.next();
System.out.println(result.toString());
}
implementation 'com.github.lonely-lockley:ltsv-parser:1.0.0'
<dependency>
<groupId>com.github.lonely-lockley</groupId>
<artifactId>ltsv-parser</artifactId>
<version>1.0.0</version>
</dependency>
Licensed under the Apache License, Version 2.0.
FAQs
Unknown package
We found that com.github.lonely-lockley:ltsv-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.