mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
JS: reduce the probability of colliding local variable name with a keyword
This commit is contained in:
parent
62b3c68a5b
commit
2c6068b36a
|
@ -142,14 +142,17 @@ public final class RenderingUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String indexToId(int index, String startChars) {
|
public static String indexToId(int index, String startChars) {
|
||||||
|
if (index >= startChars.length()) {
|
||||||
|
index -= startChars.length() - VARIABLE_PART_CHARS.length();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(startChars.charAt(index % startChars.length()));
|
while (index >= startChars.length()) {
|
||||||
index /= startChars.length();
|
|
||||||
while (index > 0) {
|
|
||||||
sb.append(VARIABLE_PART_CHARS.charAt(index % VARIABLE_PART_CHARS.length()));
|
sb.append(VARIABLE_PART_CHARS.charAt(index % VARIABLE_PART_CHARS.length()));
|
||||||
index /= VARIABLE_PART_CHARS.length();
|
index /= VARIABLE_PART_CHARS.length();
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.append(startChars.charAt(index % startChars.length())).reverse().toString();
|
||||||
|
} else {
|
||||||
|
return String.valueOf(startChars.charAt(index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String indexToId(int index) {
|
public static String indexToId(int index) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user