com.vladsch.flexmark.util.format.CharWidthProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flexmark-util-format Show documentation
Show all versions of flexmark-util-format Show documentation
flexmark-java format utility classes
The newest version!
package com.vladsch.flexmark.util.format;
import com.vladsch.flexmark.util.misc.CharPredicate;
import org.jetbrains.annotations.NotNull;
public interface CharWidthProvider {
int getSpaceWidth();
int getCharWidth(char c);
default int getStringWidth(@NotNull CharSequence chars) {
return getStringWidth(chars, CharPredicate.NONE);
}
default int getStringWidth(@NotNull CharSequence chars, @NotNull CharPredicate zeroWidthChars) {
int iMax = chars.length();
int width = 0;
for (int i = 0; i < iMax; i++) {
char c = chars.charAt(i);
if (!zeroWidthChars.test(c)) {
width += getCharWidth(c);
}
}
return width;
}
CharWidthProvider NULL =
new CharWidthProvider() {
@Override
public int getSpaceWidth() {
return 1;
}
@Override
public int getCharWidth(char c) {
return 1;
}
};
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy