From 0b373102f64fd7bfd25837a24ffb4ccb44b9d7e9 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Thu, 1 Mar 2018 14:16:15 -0500 Subject: Finish most of CL formatting. There are a couple of unimplemented directives, but the only ones I'd consider anywhere near crucial would be the floating-point ones, which I'm not sure what I should do with them. --- .../utils/ioutils/format/ConditionalDirective.java | 117 --------------------- 1 file changed, 117 deletions(-) delete mode 100644 base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java (limited to 'base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java') diff --git a/base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java b/base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java deleted file mode 100644 index 5ae842c..0000000 --- a/base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java +++ /dev/null @@ -1,117 +0,0 @@ -package bjc.utils.ioutils.format; - -import bjc.utils.esodata.Tape; - -import java.util.ArrayList; -import java.util.IllegalFormatConversionException; -import java.util.List; -import java.util.regex.Matcher; - -class ConditionalDirective implements Directive { - - @Override - public void format(StringBuffer sb, Object item, CLModifiers mods, CLParameters arrParams, - Tape formatParams, Matcher dirMatcher, CLFormatter fmt) { - StringBuffer condBody = new StringBuffer(); - - List clauses = new ArrayList<>(); - String defClause = null; - boolean isDefault = false; - - while(dirMatcher.find()) { - /* Process a list of clauses. */ - String dirName = dirMatcher.group("name"); - String dirMods = dirMatcher.group("modifiers"); - - if(dirName != null) { - /* Append everything up to this directive. */ - dirMatcher.appendReplacement(condBody, ""); - - if(dirName.equals("]")) { - /* End the conditional. */ - String clause = condBody.toString(); - if(isDefault) { - defClause = clause; - } else { - clauses.add(clause); - } - - break; - } else if(dirName.equals(";")) { - /* End the clause. */ - String clause = condBody.toString(); - if(isDefault) { - defClause = clause; - } else { - clauses.add(clause); - } - - /* - * Mark the next clause as the default. - */ - if(dirMods.contains(":")) { - isDefault = true; - } - } else { - /* Not a special directive. */ - condBody.append(dirMatcher.group()); - } - } - } - - Object par = formatParams.item(); - if(mods.colonMod) { - formatParams.right(); - - if(par == null) { - throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if(!(par instanceof Boolean)) { - throw new IllegalFormatConversionException('[', par.getClass()); - } - boolean res = (Boolean) par; - - String frmt; - if(res) - frmt = clauses.get(1); - else - frmt = clauses.get(0); - - fmt.doFormatString(frmt, sb, formatParams); - } else if(mods.atMod) { - if(par == null) { - throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if(!(par instanceof Boolean)) { - throw new IllegalFormatConversionException('[', par.getClass()); - } - boolean res = (Boolean) par; - - if(res) { - fmt.doFormatString(clauses.get(0), sb, formatParams); - } else { - formatParams.right(); - } - } else { - int res; - if(arrParams.length() > 1) { - res = arrParams.getInt(0, "conditional choice", '['); - } else { - if(par == null) { - throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if(!(par instanceof Number)) { - throw new IllegalFormatConversionException('[', par.getClass()); - } - res = ((Number) par).intValue(); - - formatParams.right(); - } - - if(res < 0 || res > clauses.size()) { - if(defClause != null) fmt.doFormatString(defClause, sb, formatParams); - } else { - fmt.doFormatString(clauses.get(res), sb, formatParams); - } - } - return; - } - -} -- cgit v1.2.3