![JAR search and dependency download from the Maven repository](/logo.png)
org.cthul.strings.format.AbstractArgs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cthul-strings Show documentation
Show all versions of cthul-strings Show documentation
Functions for converting strings from and to various formats,
such as roman numbers, alpha indices, Java identifiers,
and format strings.
The newest version!
package org.cthul.strings.format;
/**
* Utility methods for implementing {@link FormatArgs} or {@link MatchResults}.
* @author Arian Treffer
*/
public abstract class AbstractArgs {
protected static int cToI(char c) {
if (c < 'A') throw invalidCIndex(c);
if (c > 'Z') {
if (c < 'a' || c > 'z') throw invalidCIndex(c);
return c - 'a' + 26;
} else {
return c - 'A';
}
}
protected static IllegalArgumentException invalidCIndex(char c) {
return new IllegalArgumentException("Expected [A-Za-z], got " + c);
}
protected static char iToC(int i) {
if (i < 0 || i > 51) {
throw new IllegalArgumentException("Expected 0-51, got" + i);
}
if (i < 26) {
return (char)('A' + i);
} else {
return (char)('a' + i - 26);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy