Skip to content

Commit

Permalink
CoreUtilities.toUpperCase
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 6, 2022
1 parent f4f0829 commit a79f8f4
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ else if (CoreUtilities.toLowerCase(object.element).contains(contLow)) {
// Returns the value of an element in all uppercase letters.
// -->
tagProcessor.registerStaticTag(ElementTag.class, "to_uppercase", (attribute, object) -> {
// Intentionally do not use CoreUtilities here as users may expect multi-language compat.
return new ElementTag(object.element.toUpperCase());
}, "upper");

Expand Down Expand Up @@ -1436,8 +1437,8 @@ else if (CoreUtilities.toLowerCase(object.element).contains(contLow)) {
return new ElementTag("");
}
StringBuilder TitleCase = new StringBuilder(object.element.length());
String Upper = object.element.toUpperCase();
// Intentionally do not use CoreUtilities here as users may expect multi-language compat.
String Upper = object.element.toUpperCase();
String Lower = object.element.toLowerCase();
TitleCase.append(Upper.charAt(0));
for (int i = 1; i < object.element.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public static void registerTags() {
if (section == null) {
return null;
}
Object obj = section.get(attribute.getParam().toUpperCase());
Object obj = section.get(attribute.getParam());
if (obj == null) {
return null;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ public static void registerTags() {
Debug.echoError("Script '" + container.getName() + "' missing root section?!");
return null;
}
Object obj = section.get(key.asString().toUpperCase());
Object obj = section.get(key.asString());
if (obj == null) {
return null;
}
Expand All @@ -356,7 +356,7 @@ public static void registerTags() {
Debug.echoError("Script '" + container.getName() + "' missing root section?!");
return null;
}
Object obj = section.get(key.asString().toUpperCase());
Object obj = section.get(key.asString());
if (obj == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public static void registerTags() {
tagProcessor.registerStaticTag(TimeTag.class, ElementTag.class, "last_day_of_week", (attribute, object, dayText) -> {
DayOfWeek day;
try {
day = DayOfWeek.valueOf(dayText.asString().toUpperCase());
day = DayOfWeek.valueOf(CoreUtilities.toUpperCase(dayText.asString()));
}
catch (IllegalArgumentException ex) {
attribute.echoError("'" + dayText + "' is not a valid day-of-week.");
Expand Down Expand Up @@ -523,7 +523,7 @@ public static void registerTags() {
tagProcessor.registerStaticTag(TimeTag.class, ElementTag.class, "next_day_of_week", (attribute, object, dayText) -> {
DayOfWeek day;
try {
day = DayOfWeek.valueOf(dayText.asString().toUpperCase());
day = DayOfWeek.valueOf(CoreUtilities.toUpperCase(dayText.asString()));
}
catch (IllegalArgumentException ex) {
attribute.echoError("'" + dayText + "' is not a valid day-of-week.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public ScriptEntry(String command, String[] arguments, ScriptContainer script, O
internal = new ScriptEntryInternal();
internal.lineNumber = lineNum;
entryData = DenizenCore.implementation.getEmptyScriptEntryData();
internal.command = command.toUpperCase();
internal.command = CoreUtilities.toUpperCase(command);
internal.yamlSubcontent = insides;
internal.argPrefixMap = new HashMap<>();
if (script != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public static void setHadError() {
private static HashMap<String, String> scriptOriginalNames = new HashMap<>();

public static String getSource(String script) {
return scriptSources.get(script.toUpperCase());
return scriptSources.get(CoreUtilities.toLowerCase(script));
}

public static String getOriginalName(String script) {
return scriptOriginalNames.get(script.toUpperCase());
return scriptOriginalNames.get(CoreUtilities.toLowerCase(script));
}

public static String clearComments(String filename, String input, boolean trackSources) {
Expand All @@ -71,9 +71,9 @@ public static String clearComments(String filename, String input, boolean trackS
String trimStart = lines[lineNum].replaceAll("^[\\s]+", "");
if (trackSources && !trimmedLine.startsWith("#") && trimStart.length() == lines[lineNum].length() && trimmedLine.endsWith(":") && trimmedLine.length() > 1) {
String name = trimmedLine.substring(0, trimmedLine.length() - 1).replace('\"', '\'').replace("'", "");
scriptSources.put(name.toUpperCase(), filename);
scriptOriginalNames.put(name.toUpperCase(), name);
result.append(name.toUpperCase()).append(":\n");
scriptSources.put(CoreUtilities.toLowerCase(name), filename);
scriptOriginalNames.put(CoreUtilities.toLowerCase(name), name);
result.append(CoreUtilities.toUpperCase(name)).append(":\n");
hasAnyScript = true;
}
else if (!trimmedLine.startsWith("#")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public boolean shouldPreParse() {
}

public void setName(String commandName) {
name = commandName.toUpperCase();
name = CoreUtilities.toUpperCase(commandName);
}

protected String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void execute(final ScriptEntry scriptEntry) {
Debug.report(scriptEntry, getName(), idElement, actionElement, filename, key, value, split, rawText, toId, dataType, rawFormat, (yaml_action != null ? db("yaml_action", yaml_action.name()) : null), dataAction);
}
// Do action
Action action = Action.valueOf(actionElement.asString().toUpperCase());
Action action = actionElement.asEnum(Action.class);
final String id = idElement.asLowerString();
if (action != Action.LOAD && action != Action.SAVE && scriptEntry.shouldWaitFor()) {
scriptEntry.setFinished(true);
Expand Down Expand Up @@ -652,7 +652,7 @@ public void Set(YamlConfiguration yaml, int index, String key, Object value, Ele
value = autoConvertObject(value);
if (dataType != null && value instanceof String) {
String rawValue = value.toString();
switch (DataType.valueOf(dataType.asString().toUpperCase())) {
switch (dataType.asEnum(DataType.class)) {
case DOUBLE:
value = Double.parseDouble(rawValue);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
in_elsecommand = true;
in_subcommand = false;
}
else if (!has_brace && !in_elsecommand && DenizenCore.commandRegistry.get(arg.toUpperCase()) != null) {
else if (!has_brace && !in_elsecommand && DenizenCore.commandRegistry.get(CoreUtilities.toUpperCase(arg)) != null) {
Deprecations.ifCommandSingleLine.warn(scriptEntry);
in_subcommand = true;
subcommand.add(arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("action")
&& arg.matchesEnum(Action.class)) {
scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
scriptEntry.addObject("action", arg.asElement().asEnum(Action.class));
if (scriptEntry.getObject("action") == Action.DELAY
&& arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("delay", arg.asType(DurationTag.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ScriptContainer(YamlConfiguration configurationSection, String scriptCont
configurationSection.forceLoweredRootKey("debug");
configurationSection.forceLoweredRootKey("script");
configurationSection.forceLoweredRootKey("speed");
this.name = scriptContainerName.toUpperCase();
this.name = CoreUtilities.toUpperCase(scriptContainerName);
}

public void postCheck() {
Expand Down Expand Up @@ -182,9 +182,8 @@ public ScriptTag getAsScriptArg() {
* @return the type of container
*/
public String getContainerType() {
return contents.contains("type")
? contents.getString("type").toUpperCase()
: null;
String type = contents.getString("type");
return type == null ? null : CoreUtilities.toUpperCase(type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,29 @@ public static boolean equalsIgnoreCase(String input, String compared) {
return true;
}

public static String toUpperCase(String input) {
int len = input.length();
boolean any = false;
char c;
for (int i = 0; i < len; i++) {
c = input.charAt(i);
if (c >= 'a' && c <= 'z') {
any = true;
break;
}
}
if (!any) {
return input;
}
char[] data = input.toCharArray();
for (int i = 0; i < data.length; i++) {
if (data[i] >= 'a' && data[i] <= 'z') {
data[i] -= 'a' - 'A';
}
}
return new String(data);
}

public static String toLowerCase(String input) {
int len = input.length();
boolean any = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int getValue() {
}

public static int romanToArabic(String input) {
String romanNumeral = input.toUpperCase();
String romanNumeral = CoreUtilities.toUpperCase(input);
int result = 0;
int i = 0;
List<RomanNumeral> romanNumerals = RomanNumeral.reverseSortedValues;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.denizenscript.denizencore.utilities.debugging;

import com.denizenscript.denizencore.utilities.CoreUtilities;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
Expand All @@ -11,7 +13,6 @@ public class DebugLog extends Logger {

public DebugLog(String l, String f) {
super(l, null);

try {
handler = new FileHandler(f, true);
addHandler(handler);
Expand All @@ -36,19 +37,14 @@ private static class DebugFormatter extends Formatter {
@Override
public String format(LogRecord rec) {
Throwable exception = rec.getThrown();

String out = this.date.format(rec.getMillis());

out += "[" + rec.getLevel().getName().toUpperCase() + "] ";
out += "[" + CoreUtilities.toUpperCase(rec.getLevel().getName()) + "] ";
out += rec.getMessage() + '\n';

if (exception != null) {
StringWriter writer = new StringWriter();
exception.printStackTrace(new PrintWriter(writer));

return out + writer;
}

return out;
}
}
Expand Down

0 comments on commit a79f8f4

Please sign in to comment.