summaryrefslogtreecommitdiff
path: root/clformat/src/main/java/bjc/utils
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-11-13 20:20:46 -0500
committerBen Culkin <scorpress@gmail.com>2020-11-13 20:20:54 -0500
commit51507da5bf7fd5ceb39dab184020bbdb2578234c (patch)
tree9194e1dfda0736165237b186e0e4edff98c7c80d /clformat/src/main/java/bjc/utils
parent7aef85cae4d6c61ee1f34f0c25440886bafa774d (diff)
Minor tweaks
Diffstat (limited to 'clformat/src/main/java/bjc/utils')
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java4
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java34
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java37
3 files changed, 40 insertions, 35 deletions
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
index 691784a..61d88bf 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
@@ -5,6 +5,10 @@ import java.util.*;
import bjc.esodata.*;
import bjc.utils.parserutils.TokenUtils;
+// @TODO Nov 13th, 2020 Ben Culkin :ParameterDefaulting
+// Implement a method which will 'overlay' a set of parameters onto another
+// paramater set, with support for preferring one or the other.
+
/**
* Represents a set of parameters to a CL format directive.
*
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
index a2465ba..746bf31 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
@@ -2,6 +2,22 @@ package bjc.utils.ioutils.format;
import bjc.esodata.*;
+// @TODO Nov 13th, 2020 Ben Culkin :DefaultValues
+// Create some way to specify default values for the arguments to the various
+// asWhatever methods. This will cleanup use-site code for them
+
+/* @TODO Nov 13th, 2020 Ben Culkin :ParamVariables
+ * Create a new CLValue type that implements variables in a way. There are a
+ * number of different sorts of 'scopes' that could be useful, so here is the
+ * list of them:
+ * - Static variables, stored on the CLString instance
+ * - Global variables, stored on a map set on the FormatContext when formatting
+ * starts, and copied over whenever a new context is built.
+ * - Lexical variables, stored on the FormatContext, but in some sort of map which
+ * models lexical scopes (extend on FunctionalMap may do the right thing, not sure)
+ * - Local variables, stored on the FormatContext as well, but these
+ * aren't copied over when a new context is built.
+ */
/**
* Represents a parameter value to an edict that may have a dynamic value
* obtained from the format arguments.
@@ -21,15 +37,11 @@ public interface CLValue {
if (val == null) return new NullValue();
switch (val) {
- case "V":
- case "v":
- return new VValue();
- case "#":
- return new HashValue();
- case "%":
- return new PercValue();
- default:
- return new LiteralValue(val);
+ case "V": // Fall-through, V is the same as v
+ case "v": return new VValue();
+ case "#": return new HashValue();
+ case "%": return new PercValue();
+ default: return new LiteralValue(val);
}
}
@@ -55,7 +67,7 @@ public interface CLValue {
* The format parameters to use.
*
* @param paramName
- * The user-intelligble name for the value.
+ * The user-intelligible name for the value.
*
* @param directive
* The directive this value is for.
@@ -102,7 +114,7 @@ public interface CLValue {
* The format parameters to use.
*
* @param paramName
- * The user-intelligble name for the value.
+ * The user-intelligible name for the value.
*
* @param directive
* The directive the value is for.
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java
index 4fec0e0..856589c 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java
@@ -79,7 +79,7 @@ class AestheticEdict implements Edict {
// Check that we have an item
CLFormatter.checkItem(itemTape.item(), 'A');
- String tmp = itemTape.item().toString();
+ String itemString = itemTape.item().toString();
StringBuilder work = new StringBuilder();
@@ -89,34 +89,23 @@ class AestheticEdict implements Edict {
int colinc = colincPar.asInt(itemTape, "padding increment", "A", 1);
int minpad = minpadPar.asInt(itemTape, "minumum amount of padding", "A", 0);
- if (padBefore) {
- for (int i = 0; i < minpad; i++) {
- work.append(padchar);
- }
+ if (padBefore) doPadding(work, padchar, mincol, colinc, minpad);
- for (int i = work.length() + tmp.length(); i < mincol; i++) {
- for (int k = 0; k < colinc; k++) {
- work.append(padchar);
- }
- }
- }
-
- work.append(tmp);
+ work.append(itemString);
- if (!padBefore) {
- for (int i = 0; i < minpad; i++) {
- work.append(padchar);
- }
-
- for (int i = work.length(); i < mincol; i++) {
- for (int k = 0; k < colinc; k++) {
- work.append(padchar);
- }
- }
- }
+ if (!padBefore) doPadding(work, padchar, mincol, colinc, minpad);
formCTX.writer.write(work.toString());
itemTape.right();
}
+
+ private void doPadding(StringBuilder work, char padchar, int mincol, int colinc,
+ int minpad) {
+ for (int i = 0; i < minpad; i++) work.append(padchar);
+
+ for (int i = work.length(); i < mincol; i++) {
+ for (int k = 0; k < colinc; k++) work.append(padchar);
+ }
+ }
}