net.markenwerk:utils-text-indentation

A Common indentation for pretty printing libraries for Java

License

License

Categories

Categories

Net
GroupId

GroupId

net.markenwerk
ArtifactId

ArtifactId

utils-text-indentation
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

net.markenwerk:utils-text-indentation
A Common indentation for pretty printing libraries for Java
Project URL

Project URL

https://github.com/markenwerk/java-utils-text-indentation
Project Organization

Project Organization

Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH
Source Code Management

Source Code Management

https://github.com/markenwerk/java-utils-text-indentation

Download utils-text-indentation

How to add to project

<!-- https://jarcasting.com/artifacts/net.markenwerk/utils-text-indentation/ -->
<dependency>
    <groupId>net.markenwerk</groupId>
    <artifactId>utils-text-indentation</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/net.markenwerk/utils-text-indentation/
implementation 'net.markenwerk:utils-text-indentation:1.1.2'
// https://jarcasting.com/artifacts/net.markenwerk/utils-text-indentation/
implementation ("net.markenwerk:utils-text-indentation:1.1.2")
'net.markenwerk:utils-text-indentation:jar:1.1.2'
<dependency org="net.markenwerk" name="utils-text-indentation" rev="1.1.2">
  <artifact name="utils-text-indentation" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.markenwerk', module='utils-text-indentation', version='1.1.2')
)
libraryDependencies += "net.markenwerk" % "utils-text-indentation" % "1.1.2"
[net.markenwerk/utils-text-indentation "1.1.2"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

A Common indentation for pretty printing libraries

Build Status Coverage Status Dependency Status Maven Central Issues MIT License

Overview

This library provides a Common indentation for other libraries that include a pretty printing functionality.

Consult the documentation and usage description for further information:

Maven

This library is hosted in the Maven Central Repository. You can use it with the following coordinates:

<dependency>
	<groupId>net.markenwerk</groupId>
	<artifactId>utils-text-indentation</artifactId>
	<version>1.1.2</version>
</dependency>

Motivation

The goal of this library is to avoid unnecessary and probably inconsistent repetition of a configurable indentation for formatted text output (e.g. pretty printing).

Usage

This library provides the Indentation interface.

Using an Indentation

An Indentation provides the following two methods to create a character sequence that needs to be appended at the beginning of a line, with the result that the the line is indented by the given level.

Indentation indentation = ...;

// get an indentation prefix for the given level
indentation.get(level);

// append an indentation prefix for the given level
indentation.append(appendable, level);

An Indentation provides the following two methods that optionally append a line break to create the character sequence that needs to be appended at the end of a line, with the result that the next line is indented by the given level. This includes the necessary line break characters.

Indentation indentation = ...;

// get an indentation prefix for the given level
indentation.get(level, true);

// append an indentation prefix for the given level
indentation.append(appendable, level, true);

It is also possible to check, if an Indentation will have any visible effect.

Indentation indentation = ...;

// check if the indentation will return non-empty strings 
boolean prettyPrinting = indentation.isVisible();

The result of isVisible() is useful, if a pretty printer needs to behave differently (e.g. add whitespace between separators). Even if isVisible() returns false, getPrefix(int) and getLineBreak(int) will always return a [String] that is not null. This means that it is safe to use these methods without any checks. An Indentation that has no visible effect won't include the line break characters.

Whitespace Indentation

This library provides the WhitespaceIndentation that can be safely configured to create indentation strings with the most common whitespace characters (tab and space).

// indentation with four spaces
Indentation spaceIndentation = new WhitespaceIndentation(Whitespace.SPACE, 4);

// indentation with one tab and windows style line break
Indentation tabIndentation = new WhitespaceIndentation(Whitespace.TAB, 1, LineBreak.WINDOWS);

Invisible Indentation

This library provides the InvisibleIndentation that has no visible effect.

// indentation without visible effects
Indentation spaceIndentation = new InvisibleIndentation();
net.markenwerk

Markenwerk

Versions

Version
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0