summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java
diff options
context:
space:
mode:
authorstudent <student@69.161.224.52>2018-02-09 11:52:03 -0500
committerstudent <student@69.161.224.52>2018-02-09 11:52:03 -0500
commit92ec9adfcb115fe86d5ba27fcc089db027374d6a (patch)
tree3ebbce2d97c9fd9fd1ce29959210a6bf2fc8f5dd /base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java
parent46c1a3e1e7cf21f3c63dcb028fd1807e870dfbef (diff)
Work on CL format strings
Diffstat (limited to 'base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java')
-rw-r--r--base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java b/base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java
new file mode 100644
index 0000000..d5d4b29
--- /dev/null
+++ b/base/src/main/java/bjc/utils/ioutils/format/NumberDirective.java
@@ -0,0 +1,46 @@
+package bjc.utils.ioutils.format;
+
+import java.util.regex.Matcher;
+
+import bjc.utils.esodata.Tape;
+import bjc.utils.ioutils.NumberUtils;
+
+public class NumberDirective implements Directive {
+
+ @Override
+ public void format(StringBuffer sb, Object item, CLModifiers mods, CLParameters params, Tape<Object> tParams,
+ Matcher dirMatcher) {
+ /*
+ * Initialize the two padding related parameters, and then fill them in from the
+ * directive parameters if they are present.
+ */
+ int mincol = 0;
+ char padchar = ' ';
+ if (params.length() > (argidx + 2)) {
+ mincol = params.getIntDefault(argidx + 1, "minimum column count", 'R', 0);
+ }
+ if (params.length() > (argidx + 3)) {
+ padchar = params.getCharDefault(argidx + 2, "padding character", 'R', ' ');
+ }
+
+ if (mods.colonMod) {
+ /*
+ * We're doing commas, so check if the two comma-related parameters were
+ * supplied.
+ */
+ int commaInterval = 0;
+ char commaChar = ',';
+ if (params.length() > (argidx + 3)) {
+ commaChar = params.getCharDefault((argidx + 3), "comma character", 'R', ' ');
+ }
+ if (params.length() > (argidx + 4)) {
+ commaInterval = params.getIntDefault((argidx + 4), "comma interval", 'R', 0);
+ }
+
+ NumberUtils.toCommaString(val, mincol, padchar, commaInterval, commaChar, mods.atMod, radix);
+ } else {
+ NumberUtils.toNormalString(val, mincol, padchar, mods.atMod, radix);
+ }
+ }
+
+}