Remove "Smart" Quotes per default

This commit is contained in:
Olof Larsson 2013-12-17 12:53:30 +01:00
parent 8d1ec9f51d
commit 59ad607b14
3 changed files with 53 additions and 0 deletions

View File

@ -73,6 +73,12 @@ public class MCommand
public boolean isUsingTokenizer() { return this.usingTokenizer; }
public void setUsingTokenizer(boolean usingTokenizer) { this.usingTokenizer = usingTokenizer; }
// FIELD: usingSmartQuotesRemoval
// Are "smart" quotes replaced with normal characters?
protected boolean usingSmartQuotesRemoval;
public boolean isUsingSmartQuotesRemoval() { return this.usingSmartQuotesRemoval; }
public void setUsingSmartQuotesRemoval(boolean usingSmartQuotesRemoval) { this.usingSmartQuotesRemoval = usingSmartQuotesRemoval; }
// FIELD: requirements
// All these requirements must be met for the command to be executable;
protected List<Req> requirements;
@ -184,6 +190,7 @@ public class MCommand
this.errorOnToManyArgs = true;
this.usingTokenizer = true;
this.usingSmartQuotesRemoval = true;
this.desc = null;
this.descPermission = null;

View File

@ -82,6 +82,16 @@ public class MCoreBukkitCommand extends Command
argList = new ArrayList<String>(Arrays.asList(args));
}
if (this.mcommand.isUsingSmartQuotesRemoval())
{
List<String> oldArgList = argList;
argList = new ArrayList<String>();
for (String arg : oldArgList)
{
argList.add(Txt.removeSmartQuotes(arg));
}
}
this.mcommand.execute(sender, argList);
return true;

View File

@ -489,6 +489,42 @@ public class Txt
return ret;
}
// -------------------------------------------- //
// "SMART" QUOTES
// -------------------------------------------- //
// The quite stupid "Smart quotes" design idea means replacing normal characters with mutated UTF-8 alternatives.
// The normal characters look good in Minecraft.
// The UFT-8 "smart" alternatives look quite bad.
// http://www.fileformat.info/info/unicode/block/general_punctuation/list.htm
public static String removeSmartQuotes(String string)
{
if (string == null) return null;
// LEFT SINGLE QUOTATION MARK
string = string.replace("\u2018", "'");
// RIGHT SINGLE QUOTATION MARK
string = string.replace("\u2019", "'");
// LEFT DOUBLE QUOTATION MARK
string = string.replace("\u201C", "\"");
// RIGHT DOUBLE QUOTATION MARK
string = string.replace("\u201D", "\"");
// ONE DOT LEADER
string = string.replace("\u2024", ".");
// TWO DOT LEADER
string = string.replace("\u2025", "..");
// HORIZONTAL ELLIPSIS
string = string.replace("\u2026", "...");
return string;
}
// -------------------------------------------- //
// String comparison
// -------------------------------------------- //