Aggiunti alcuni esercizi di java.
This commit is contained in:
21
squeaky-clean/src/main/java/SqueakyClean.java
Normal file
21
squeaky-clean/src/main/java/SqueakyClean.java
Normal file
@@ -0,0 +1,21 @@
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class SqueakyClean {
|
||||
static String clean(String identifier) {
|
||||
|
||||
var result = identifier.replace(' ', '_')
|
||||
.replaceAll("[α-ω]", "")
|
||||
.replaceAll("\\p{C}", "CTRL")
|
||||
.replaceAll("[^\\p{L}\\p{P}]", "");
|
||||
var matcher = Pattern.compile("(.*)(-\\p{L})(.*)").matcher(result);
|
||||
if (matcher.matches()) {
|
||||
result = matcher.replaceAll(
|
||||
matcher.group(1)
|
||||
+ matcher.group(2).toUpperCase(Locale.ROOT).substring(1)
|
||||
+ matcher.group(3)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user