78 lines
2.1 KiB
Java
78 lines
2.1 KiB
Java
/*
|
|
* TASK 8
|
|
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/8
|
|
* by femsci
|
|
*/
|
|
|
|
package dev.meowmeow;
|
|
|
|
//cute atomic purely functional meows~
|
|
|
|
public class NamingUtils {
|
|
// normeow
|
|
public static String norm(String name) {
|
|
if (name.length() == 0) {
|
|
return "";
|
|
}
|
|
|
|
return String.format("%c%s", Character.toUpperCase(name.charAt(0)), name.substring(1).toLowerCase());
|
|
}
|
|
|
|
// init 6
|
|
public static String init(String name) {
|
|
String[] sgmt = name.split(" ");
|
|
|
|
if (sgmt.length == 0) {
|
|
throw new IllegalArgumentException("invalid data");
|
|
}
|
|
|
|
int len = sgmt.length;
|
|
|
|
StringBuffer buf = new StringBuffer();
|
|
|
|
// alnamic names :3
|
|
for (int c = 0; c < len - 1; ++c) {
|
|
String silliname = sgmt[c];
|
|
if (silliname.endsWith(".")) {
|
|
if (silliname.length() != 2) {
|
|
throw new IllegalArgumentException("only initials may end with a '.'");
|
|
}
|
|
|
|
buf.append(silliname.toUpperCase()).append(' ');
|
|
continue;
|
|
}
|
|
|
|
buf.append(String.format("%c.", Character.toUpperCase(silliname.charAt(0)))).append(' ');
|
|
}
|
|
|
|
// lname
|
|
buf.append(norm(sgmt[len - 1]));
|
|
|
|
return buf.toString();
|
|
}
|
|
|
|
// trills
|
|
public static String tr(String s, String assMapFrom, String assMapTo) {
|
|
// hehe >:3c
|
|
// Runtime.getRuntime().exec(new String[] {
|
|
// "/usr/bin/bash",
|
|
// String.format("-c \"echo '%s' | tr '%s' '%s'\"", s, from, to)
|
|
// });
|
|
|
|
if (assMapFrom.length() != assMapTo.length()) {
|
|
throw new IllegalArgumentException("mapping sets must have same len");
|
|
}
|
|
|
|
StringBuffer buf = new StringBuffer(s.length());
|
|
|
|
for (int rcx = 0; rcx < s.length(); ++rcx) {
|
|
char meow = s.charAt(rcx);
|
|
int assIdx = assMapFrom.indexOf(meow);
|
|
char meowie = assIdx == -1 ? meow : assMapTo.charAt(assIdx);
|
|
|
|
buf.append(meowie);
|
|
}
|
|
|
|
return buf.toString();
|
|
}
|
|
}
|