diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/ioutils/format/ConditionalDirective.java | 117 |
1 files changed, 0 insertions, 117 deletions
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<Object> formatParams, Matcher dirMatcher, CLFormatter fmt) { - StringBuffer condBody = new StringBuffer(); - - List<String> 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; - } - -} |
