You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2022/12/30 23:26:36 UTC
[freemarker] 01/02: CFormat: Further API and javadoc cleanup
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git
commit 21022a6cffc32cc7bb2b6e8d1ccb8de657015956
Author: ddekany <dd...@apache.org>
AuthorDate: Fri Dec 30 20:05:46 2022 +0100
CFormat: Further API and javadoc cleanup
---
.../java/freemarker/core/AbstractJSONLikeFormat.java | 8 ++++----
src/main/java/freemarker/core/AbstractLegacyCFormat.java | 14 +++++---------
src/main/java/freemarker/core/CFormat.java | 13 +++++++------
src/main/java/freemarker/core/Configurable.java | 13 +++++++++----
src/main/java/freemarker/core/Default230CFormat.java | 6 +++---
src/main/java/freemarker/core/Default2321CFormat.java | 6 +++---
src/main/java/freemarker/core/Environment.java | 6 +++---
src/main/java/freemarker/core/JSONCFormat.java | 2 +-
src/main/java/freemarker/core/JavaCFormat.java | 6 +++---
src/main/java/freemarker/core/JavaScriptCFormat.java | 2 +-
.../java/freemarker/core/JavaScriptOrJSONCFormat.java | 2 +-
src/main/java/freemarker/core/XSCFormat.java | 8 ++++----
src/main/java/freemarker/template/Configuration.java | 16 +++++++++-------
src/manual/en_US/book.xml | 8 ++++----
.../java/freemarker/core/CTemplateNumberFormatTest.java | 2 +-
src/test/java/freemarker/core/CustomCFormat.java | 6 +++---
16 files changed, 61 insertions(+), 57 deletions(-)
diff --git a/src/main/java/freemarker/core/AbstractJSONLikeFormat.java b/src/main/java/freemarker/core/AbstractJSONLikeFormat.java
index 190ce697..ad6b7349 100644
--- a/src/main/java/freemarker/core/AbstractJSONLikeFormat.java
+++ b/src/main/java/freemarker/core/AbstractJSONLikeFormat.java
@@ -26,7 +26,7 @@ import java.text.NumberFormat;
/**
* Defines the methods in {@link CFormat} that are the same for all JSON-like languages.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* constructor and most methods are not exposed outside FreeMarker, and so you can't create a custom implementation.
* The class itself and some members are exposed as they are needed for configuring FreeMarker.
*
@@ -37,7 +37,7 @@ public abstract class AbstractJSONLikeFormat extends CFormat {
"Infinity", "-Infinity", "NaN",
"Infinity", "-Infinity", "NaN");
- private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.INSTANCE.getLegacyNumberFormat().clone();
+ private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
static {
DecimalFormatSymbols symbols = LEGACY_NUMBER_FORMAT_PROTOTYPE.getDecimalFormatSymbols();
symbols.setInfinity("Infinity");
@@ -65,12 +65,12 @@ public abstract class AbstractJSONLikeFormat extends CFormat {
}
@Override
- final TemplateNumberFormat getTemplateNumberFormat() {
+ final TemplateNumberFormat getTemplateNumberFormat(Environment env) {
return TEMPLATE_NUMBER_FORMAT;
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}
}
diff --git a/src/main/java/freemarker/core/AbstractLegacyCFormat.java b/src/main/java/freemarker/core/AbstractLegacyCFormat.java
index bdf7577d..c564d144 100644
--- a/src/main/java/freemarker/core/AbstractLegacyCFormat.java
+++ b/src/main/java/freemarker/core/AbstractLegacyCFormat.java
@@ -19,8 +19,6 @@
package freemarker.core;
-import java.text.NumberFormat;
-
import freemarker.template.TemplateException;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateNumberModel;
@@ -31,7 +29,7 @@ import freemarker.template.utility.StringUtil.JsStringEncQuotation;
/**
* Super class of {@link CFormat}-s that merely exist to mimic old {@code ?c} behavior for backward compatibility.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* constructor and most methods are not exposed outside FreeMarker, and so you can't create a custom implementation.
* The class itself and some members are exposed as they are needed for configuring FreeMarker.
*
@@ -50,8 +48,8 @@ public abstract class AbstractLegacyCFormat extends CFormat {
}
@Override
- final TemplateNumberFormat getTemplateNumberFormat() {
- return new LegacyCTemplateNumberFormat();
+ final TemplateNumberFormat getTemplateNumberFormat(Environment env) {
+ return new LegacyCTemplateNumberFormat(env);
}
@Override
@@ -69,12 +67,10 @@ public abstract class AbstractLegacyCFormat extends CFormat {
return "null";
}
- abstract NumberFormat getLegacyNumberFormat();
-
final class LegacyCTemplateNumberFormat extends JavaTemplateNumberFormat {
- public LegacyCTemplateNumberFormat() {
- super(getLegacyNumberFormat(), Environment.COMPUTER_FORMAT_STRING);
+ public LegacyCTemplateNumberFormat(Environment env) {
+ super(getLegacyNumberFormat(env), Environment.COMPUTER_FORMAT_STRING);
}
@Override
diff --git a/src/main/java/freemarker/core/CFormat.java b/src/main/java/freemarker/core/CFormat.java
index d9d0cca8..1b92f607 100644
--- a/src/main/java/freemarker/core/CFormat.java
+++ b/src/main/java/freemarker/core/CFormat.java
@@ -28,9 +28,9 @@ import freemarker.template.TemplateException;
* {@code "c"} and {@code "computer"} {@link Configurable#setNumberFormat(String) number_format}, and
* the {@code "c"} {@link Configurable#setBooleanFormat(String) boolean_format}.
* A {@link CFormat} currently defines how numbers, booleans, and strings are converted to text that defines a similar
- * value in some computer language (or other computer-parsed syntax) that the {@link CFormat} is made for.
+ * value in a certain computer language (or other computer-parsed syntax).
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* constructor and most methods are not exposed outside FreeMarker, and so you can't create a custom implementation.
* The class itself and some members are exposed as they are needed for configuring FreeMarker.
*
@@ -50,17 +50,18 @@ public abstract class CFormat {
* which is mutable, or not thread-safe, then it's not returned, but a clone or copy of it. The caller of this
* method is not responsible for do any such cloning or copying.
*/
- abstract TemplateNumberFormat getTemplateNumberFormat();
+ abstract TemplateNumberFormat getTemplateNumberFormat(Environment env);
/**
- * Similar to {@link #getTemplateNumberFormat()}, but only exist to serve the deprecated
+ * Similar to {@link #getTemplateNumberFormat(Environment)}, but only exist to serve the deprecated
* {@link Environment#getCNumberFormat()} method. We don't expect the result of the formatting to be the same as
* with the {@link TemplateNumberFormat}, but this method should make some effort to be similar.
*
- * @deprecated Use {@link #getTemplateNumberFormat()} instead, except in {@link Environment#getCNumberFormat()}.
+ * @deprecated Use {@link #getTemplateNumberFormat(Environment)} instead, except in
+ * {@link Environment#getCNumberFormat()}.
*/
@Deprecated
- abstract NumberFormat getLegacyNumberFormat();
+ abstract NumberFormat getLegacyNumberFormat(Environment env);
/**
* Format a {@link String} to a string literal.
diff --git a/src/main/java/freemarker/core/Configurable.java b/src/main/java/freemarker/core/Configurable.java
index 6da2b48c..bb6ef998 100644
--- a/src/main/java/freemarker/core/Configurable.java
+++ b/src/main/java/freemarker/core/Configurable.java
@@ -857,13 +857,18 @@ public class Configurable {
}
/**
- * Sets the default number format used to convert numbers to strings. Currently, this is one of these:
+ * Sets the number format used to convert numbers to strings. Currently, this is one of these:
* <ul>
- * <li>{@code "number"}: The number format returned by {@link NumberFormat#getNumberInstance(Locale)}</li>
+ * <li>{@code "number"}: The number format returned by {@link NumberFormat#getNumberInstance(Locale)}. This is the
+ * default.</li>
+ * <li>{@code "c"} (recognized since 2.3.32): The number format used by FTL's {@code c} built-in (like in
+ * {@code someNumber?c}). So with this <code>${someNumber}</code> will output the same as
+ * <code>${someNumber?c}</code>. This should only be used if the template solely generates source code,
+ * configuration file, or other content that's nor read by normal users. If the template contains parts that's
+ * read by normal users (like typical a web page), you are not supposed to use this.</li>
+ * <li>{@code "computer"}: The old (deprecated) name for {@code "c"}. Recognized by all FreeMarker versions.</li>
* <li>{@code "currency"}: The number format returned by {@link NumberFormat#getCurrencyInstance(Locale)}</li>
* <li>{@code "percent"}: The number format returned by {@link NumberFormat#getPercentInstance(Locale)}</li>
- * <li>{@code "c"} (recognized since 2.3.32), or {@code "computer"} (same as {@code "c"}, but also recognized by
- * older versions): The number format used by FTL's {@code c} built-in (like in {@code someNumber?c}).</li>
* <li>{@link java.text.DecimalFormat} pattern (like {@code "0.##"}). This syntax is extended by FreeMarker
* so that you can specify options like the rounding mode and the symbols used after a 2nd semicolon. For
* example, {@code ",000;; roundingMode=halfUp groupingSeparator=_"} will format numbers like {@code ",000"}
diff --git a/src/main/java/freemarker/core/Default230CFormat.java b/src/main/java/freemarker/core/Default230CFormat.java
index 2a247844..88749766 100644
--- a/src/main/java/freemarker/core/Default230CFormat.java
+++ b/src/main/java/freemarker/core/Default230CFormat.java
@@ -33,7 +33,7 @@ import freemarker.template.Version;
* {@linkplain Configuration#VERSION_2_3_21 2.3.21}.
* The only good reason for using this is strict backward-compatibility.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* constructor and most methods are not exposed outside FreeMarker, and so you can't create a custom implementation.
* The class itself and some members are exposed as they are needed for configuring FreeMarker.
*
@@ -49,7 +49,7 @@ public final class Default230CFormat extends AbstractLegacyCFormat {
/**
* "c" number format as it was before Incompatible Improvements 2.3.21.
*/
- private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = new DecimalFormat(
+ static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = new DecimalFormat(
"0.################",
new DecimalFormatSymbols(Locale.US));
static {
@@ -61,7 +61,7 @@ public final class Default230CFormat extends AbstractLegacyCFormat {
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
// Note: DecimalFormat-s aren't thread-safe, so you must clone the static field value.
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}
diff --git a/src/main/java/freemarker/core/Default2321CFormat.java b/src/main/java/freemarker/core/Default2321CFormat.java
index 34258892..c466769a 100644
--- a/src/main/java/freemarker/core/Default2321CFormat.java
+++ b/src/main/java/freemarker/core/Default2321CFormat.java
@@ -32,7 +32,7 @@ import freemarker.template.Version;
* {@linkplain Configuration#VERSION_2_3_21 2.3.21} and {@linkplain Configuration#VERSION_2_3_31 2.3.31}.
* The only good reason for using this is strict backward-compatibility.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* constructor and most methods are not exposed outside FreeMarker, and so you can't create a custom implementation.
* The class itself and some members are exposed as they are needed for configuring FreeMarker.
*
@@ -48,7 +48,7 @@ public final class Default2321CFormat extends AbstractLegacyCFormat {
/**
* "c" number format as it was starting from Incompatible Improvements 2.3.21.
*/
- private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.INSTANCE.getLegacyNumberFormat().clone();
+ private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
static {
DecimalFormatSymbols symbols = LEGACY_NUMBER_FORMAT_PROTOTYPE.getDecimalFormatSymbols();
symbols.setInfinity("INF");
@@ -60,7 +60,7 @@ public final class Default2321CFormat extends AbstractLegacyCFormat {
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
// Note: DecimalFormat-s aren't thread-safe, so you must clone the static field value.
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}
diff --git a/src/main/java/freemarker/core/Environment.java b/src/main/java/freemarker/core/Environment.java
index 6a00a788..c5be9e17 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -1679,7 +1679,7 @@ public final class Environment extends Configurable {
@Deprecated
public NumberFormat getCNumberFormat() {
if (cNumberFormat == null) {
- cNumberFormat = getCFormatWithPre2331IcIBug().getLegacyNumberFormat();
+ cNumberFormat = getCFormatWithPre2331IcIBug().getLegacyNumberFormat(this);
}
return cNumberFormat;
}
@@ -1694,7 +1694,7 @@ public final class Environment extends Configurable {
*/
public TemplateNumberFormat getCTemplateNumberFormat() {
if (cTemplateNumberFormat == null) {
- cTemplateNumberFormat = getCFormat().getTemplateNumberFormat();
+ cTemplateNumberFormat = getCFormat().getTemplateNumberFormat(this);
}
return cTemplateNumberFormat;
}
@@ -1705,7 +1705,7 @@ public final class Environment extends Configurable {
*/
private TemplateNumberFormat getCTemplateNumberFormatWithPre2331IcIBug() {
if (cTemplateNumberFormatWithPre2331IcIBug == null) {
- cTemplateNumberFormatWithPre2331IcIBug = getCFormatWithPre2331IcIBug().getTemplateNumberFormat();
+ cTemplateNumberFormatWithPre2331IcIBug = getCFormatWithPre2331IcIBug().getTemplateNumberFormat(this);
}
return cTemplateNumberFormatWithPre2331IcIBug;
}
diff --git a/src/main/java/freemarker/core/JSONCFormat.java b/src/main/java/freemarker/core/JSONCFormat.java
index de102676..40b0cc72 100644
--- a/src/main/java/freemarker/core/JSONCFormat.java
+++ b/src/main/java/freemarker/core/JSONCFormat.java
@@ -28,7 +28,7 @@ import freemarker.template.utility.StringUtil.JsStringEncQuotation;
* {@value #NAME} {@link CFormat}; to be used when generating JSON (and not JavaScript), except, in most cases
* {@link JavaScriptOrJSONCFormat} is recommended over this.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* most methods are not exposed outside FreeMarker. The class itself and some members are exposed as they are needed for
* configuring FreeMarker.
*
diff --git a/src/main/java/freemarker/core/JavaCFormat.java b/src/main/java/freemarker/core/JavaCFormat.java
index 023044df..020378e0 100644
--- a/src/main/java/freemarker/core/JavaCFormat.java
+++ b/src/main/java/freemarker/core/JavaCFormat.java
@@ -39,7 +39,7 @@ public final class JavaCFormat extends CFormat {
"Double.POSITIVE_INFINITY", "Double.NEGATIVE_INFINITY", "Double.NaN",
"Float.POSITIVE_INFINITY", "Float.NEGATIVE_INFINITY", "Float.NaN");
- private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.INSTANCE.getLegacyNumberFormat().clone();
+ private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
static {
DecimalFormatSymbols symbols = LEGACY_NUMBER_FORMAT_PROTOTYPE.getDecimalFormatSymbols();
symbols.setInfinity("Double.POSITIVE_INFINITY");
@@ -51,7 +51,7 @@ public final class JavaCFormat extends CFormat {
}
@Override
- TemplateNumberFormat getTemplateNumberFormat() {
+ TemplateNumberFormat getTemplateNumberFormat(Environment env) {
return TEMPLATE_NUMBER_FORMAT;
}
@@ -76,7 +76,7 @@ public final class JavaCFormat extends CFormat {
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}
diff --git a/src/main/java/freemarker/core/JavaScriptCFormat.java b/src/main/java/freemarker/core/JavaScriptCFormat.java
index ce5daab8..5dd7cbcd 100644
--- a/src/main/java/freemarker/core/JavaScriptCFormat.java
+++ b/src/main/java/freemarker/core/JavaScriptCFormat.java
@@ -28,7 +28,7 @@ import freemarker.template.utility.StringUtil.JsStringEncQuotation;
* {@value #NAME} {@link CFormat}, to be used when generating JavaScript (and not JSON), except, in most cases
* {@link JavaScriptOrJSONCFormat} is recommended over this.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* most methods are not exposed outside FreeMarker. The class itself and some members are exposed as they are needed for
* configuring FreeMarker.
*
diff --git a/src/main/java/freemarker/core/JavaScriptOrJSONCFormat.java b/src/main/java/freemarker/core/JavaScriptOrJSONCFormat.java
index 039db400..7c80c474 100644
--- a/src/main/java/freemarker/core/JavaScriptOrJSONCFormat.java
+++ b/src/main/java/freemarker/core/JavaScriptOrJSONCFormat.java
@@ -35,7 +35,7 @@ import freemarker.template.utility.StringUtil.JsStringEncQuotation;
* {@link Configuration#Configuration(Version) incompatible_improvements}
* {@linkplain Configuration#VERSION_2_3_32 2.3.32}.
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* most methods are not exposed outside FreeMarker. The class itself and some members are exposed as they are needed for
* configuring FreeMarker.
*
diff --git a/src/main/java/freemarker/core/XSCFormat.java b/src/main/java/freemarker/core/XSCFormat.java
index 9d602c09..016f8f27 100644
--- a/src/main/java/freemarker/core/XSCFormat.java
+++ b/src/main/java/freemarker/core/XSCFormat.java
@@ -33,7 +33,7 @@ import freemarker.template.TemplateException;
* XML-escaping is the duty of the auto-escaping facility of FreeMarker, and not of the {@link CFormat}, so that's not
* done here either.)
*
- * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now the
+ * <p><b>Experimental class!</b> This class is too new, and might will change over time. Therefore, for now
* most methods are not exposed outside FreeMarker. The class itself and some members are exposed as they are needed for
* configuring FreeMarker.
*
@@ -47,7 +47,7 @@ public final class XSCFormat extends CFormat {
"INF", "-INF", "NaN",
"INF", "-INF", "NaN");
- private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.INSTANCE.getLegacyNumberFormat().clone();
+ private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE = (DecimalFormat) Default230CFormat.LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
static {
DecimalFormatSymbols symbols = LEGACY_NUMBER_FORMAT_PROTOTYPE.getDecimalFormatSymbols();
symbols.setInfinity("INF");
@@ -56,7 +56,7 @@ public final class XSCFormat extends CFormat {
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}
@@ -64,7 +64,7 @@ public final class XSCFormat extends CFormat {
}
@Override
- TemplateNumberFormat getTemplateNumberFormat() {
+ TemplateNumberFormat getTemplateNumberFormat(Environment env) {
return TEMPLATE_NUMBER_FORMAT;
}
diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java
index 05385ea7..540294bd 100644
--- a/src/main/java/freemarker/template/Configuration.java
+++ b/src/main/java/freemarker/template/Configuration.java
@@ -955,12 +955,14 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
* 2.3.32 (or higher):
* <ul>
* <li><p>
- * The number formatting of {@code ?c}, {@code ?cn}, and if the {@code "c"} and {@code "computer"}
- * {@link Configurable#setNumberFormat(String) number_format} changes, if the
- * {@link #setCFormat(CFormat) c_format} was left on its default (because the default of that changes to
- * {@link JavaScriptOrJSONCFormat#INSTANCE}, from {@link Default2321CFormat#INSTANCE}):
+ * The number formatting of {@code ?c}, {@code ?cn} (and thus also of the {@code "c"}, and
+ * {@code "computer"} {@link Configurable#setNumberFormat(String) number_format}) changes, if the
+ * {@link #setCFormat(CFormat) c_format} setting was left on its default. The default of
+ * {@link #setCFormat(CFormat) c_format} changes to {@link JavaScriptOrJSONCFormat#INSTANCE}, from
+ * {@link Default2321CFormat#INSTANCE} (or from {@link Default230CFormat#INSTANCE}, depending on the
+ * previous Incompatible Improvement value), and that's what contains the changes:</p>
* <ul>
- * <li><p>Changes affecting non-whole numbers, and for whole numbers with over 100 digits:
+ * <li><p>Changes affecting non-whole numbers, and whole numbers with over 100 digits:
* Formatting is now lossless, so it potentially shows much more decimals.
* It now uses exponential format (like 1.2E-7 instead of 0.00000012) for numbers whose absolute value
* is less than 1E-6 (0.000001), and for whole numbers whose absolute value is at least 1E101 (so over
@@ -968,8 +970,8 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
* ({@code double}/{@code Double}}, or {@code float}/{@code Float}) numbers, when their absolute value
* is too big for the floating point type to store them precisely (so if the intent was to store some
* ID-s, they are likely corrupted anyway, as the type skips some whole numbers).</p></li>
- * <li><p>Changes floating point infinity format from {@code INF} to {@code Infinity}, which is the
- * JavaScript and JSON syntax. If you generate XML with XSD-style number syntax (which uses
+ * <li><p>Changes affecting floating point infinity: Output changes from {@code INF} to {@code Infinity},
+ * which is the JavaScript and JSON syntax. If you generate XML with XSD-style number syntax (which uses
* {@code INF}), but you want the other number formatting changes (recommended), then set
* {@link #setCFormat(CFormat) c_format} to {@link XSCFormat#INSTANCE}/{@code "XS"}.</p></li>
* </ul>
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 33079432..06f82070 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -30064,8 +30064,8 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
linkend="gloss.c_format"><literal>c_format</literal></link>
(also settable via the <link
linkend="ref.directive.setting"><literal>setting</literal>
- directive</link>). This specifies what format to use when
- formatting for computer consumption, like
+ directive</link>). This specifies what syntax to use when
+ formatting values for computer consumption/parser, like
<literal>"JSON"</literal>. Most prominently, this affects
the <link linkend="ref_builtin_c"><literal>c</literal>
built-in</link>, hence the name. See valid setting values,
@@ -30170,9 +30170,9 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<literal>number_format</literal> setting (also when
formatting with
<literal>?string(<replaceable>format</replaceable>)</literal>),
- now <quote>c</quote> can be used instead of
+ now <literal>"c"</literal> can be used instead of
<quote>computer</quote>. Both has the same effect on
- formatting, but <quote>c</quote> is preferred from now
+ formatting, but <literal>"c"</literal> is preferred from now
on.</para>
</listitem>
</itemizedlist>
diff --git a/src/test/java/freemarker/core/CTemplateNumberFormatTest.java b/src/test/java/freemarker/core/CTemplateNumberFormatTest.java
index d20be03b..081f21ae 100644
--- a/src/test/java/freemarker/core/CTemplateNumberFormatTest.java
+++ b/src/test/java/freemarker/core/CTemplateNumberFormatTest.java
@@ -102,7 +102,7 @@ public class CTemplateNumberFormatTest {
private void testFormat(Number n, String expectedResult) throws TemplateModelException,
TemplateValueFormatException {
- TemplateNumberFormat cTemplateNumberFormat = JSONCFormat.INSTANCE.getTemplateNumberFormat();
+ TemplateNumberFormat cTemplateNumberFormat = JSONCFormat.INSTANCE.getTemplateNumberFormat(null);
String actualResult = (String) cTemplateNumberFormat.format(new SimpleNumber(n));
assertFormatResult(n, actualResult, expectedResult);
if (!actualResult.equals("NaN") && !actualResult.equals("0") && !actualResult.startsWith("-")) {
diff --git a/src/test/java/freemarker/core/CustomCFormat.java b/src/test/java/freemarker/core/CustomCFormat.java
index 18573cb5..86658b0d 100644
--- a/src/test/java/freemarker/core/CustomCFormat.java
+++ b/src/test/java/freemarker/core/CustomCFormat.java
@@ -37,7 +37,7 @@ class CustomCFormat extends CFormat {
"M:INF", "M:NINF", "M:NaN");
private static final DecimalFormat LEGACY_NUMBER_FORMAT_PROTOTYPE =
- (DecimalFormat) Default230CFormat.INSTANCE.getLegacyNumberFormat().clone();
+ (DecimalFormat) Default230CFormat.LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
static {
DecimalFormatSymbols symbols = LEGACY_NUMBER_FORMAT_PROTOTYPE.getDecimalFormatSymbols();
@@ -47,12 +47,12 @@ class CustomCFormat extends CFormat {
}
@Override
- TemplateNumberFormat getTemplateNumberFormat() {
+ TemplateNumberFormat getTemplateNumberFormat(Environment env) {
return TEMPLATE_NUMBER_FORMAT;
}
@Override
- NumberFormat getLegacyNumberFormat() {
+ NumberFormat getLegacyNumberFormat(Environment env) {
return (NumberFormat) LEGACY_NUMBER_FORMAT_PROTOTYPE.clone();
}