You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by PascalSchumacher <gi...@git.apache.org> on 2016/11/18 17:53:19 UTC
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
GitHub user PascalSchumacher opened a pull request:
https://github.com/apache/commons-lang/pull/213
LANG-1288: Add a builder to StringEscapeUtils
patch supplied by Mark (for LANG-1066)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/PascalSchumacher/commons-lang add_EscapedStringBuilder
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/commons-lang/pull/213.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #213
----
commit 7a11c5fc982acc2223ae23a1934b19b6dd05b711
Author: pascalschumacher <pa...@gmx.net>
Date: 2016-11-18T17:36:58Z
LANG-1288: Add a builder to StringEscapeUtils
patch supplied by Mark (for LANG-1066)
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r88745033
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
+
+ private final StringBuilder sb;
--- End diff --
How about making it possible to pass in any `java.lang.Appendable` and use a `StringBuilder` as default value?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r89192411
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
+
+ private final StringBuilder sb;
+ private final CharSequenceTranslator translator;
+
+ public Builder(final CharSequenceTranslator translator) {
--- End diff --
This is true for `BasicThreadFactory.Builder` which has to be constructed using the default constructor (yiaks) but not for `TypeUtils.WildcardTypeBuilder` which has static factory methods and a private constructor. I prefer the latter approach.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r88745531
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
--- End diff --
Is `Builder` really a good name? It's more of a wrapper currently.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang issue #213: LANG-1288: Add a builder to StringEscapeUtils
Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on the issue:
https://github.com/apache/commons-lang/pull/213
As discussed on the mailing list string escaping will move to commons-text, so I'm closing this pull request.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r88803456
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
+
+ private final StringBuilder sb;
--- End diff --
The problem with `Appendable` is that its `append` method can throw an `IOException`. That would make the builder more cumbersome to use. Of course it could just rethrow the `IOException` as a `RuntimeException`, but I do not know if this is o.k. for commons-lang.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher closed the pull request at:
https://github.com/apache/commons-lang/pull/213
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang issue #213: LANG-1288: Add a builder to StringEscapeUtils
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/commons-lang/pull/213
[](https://coveralls.io/builds/8904357)
Coverage decreased (-0.003%) to 93.666% when pulling **b62c4d4a81e22b552616d346bc818cae4d73c580 on PascalSchumacher:add_EscapedStringBuilder** into **dfd69e038cc7035031d1807c4ade870d2a7e2ece on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r88745205
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
+
+ private final StringBuilder sb;
+ private final CharSequenceTranslator translator;
+
+ public Builder(final CharSequenceTranslator translator) {
--- End diff --
I'd rather have a private constructor and then put a static factory method into `StringEscapeUtils` instead of having the inner class that one needs to construct like `new StringEscapeUtils.Builder(ESCAPE)`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] commons-lang pull request #213: LANG-1288: Add a builder to StringEscapeUtil...
Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/213#discussion_r88745694
--- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
@@ -429,6 +429,65 @@ public StringEscapeUtils() {
super();
}
+ /**
+ * <p>Convenience wrapper for {@link java.lang.StringBuilder} providing escape methods.</p>
+ *
+ * <p>Example:</p>
+ * <pre>
+ * new Builder(ESCAPE_HTML4)
+ * .append("<p>")
+ * .escape("This is paragraph 1 and special chars like & get escaped.")
+ * .append("</p><p>")
+ * .escape("This is paragraph 2 & more...")
+ * .append("</p>")
+ * .toString()
+ * </pre>
+ *
+ * @since 3.6
+ */
+ public static class Builder {
+
+ private final StringBuilder sb;
--- End diff --
Actually, I'm now thinking that it may be good to have a real decorator for `Appendables` with decorates any `Appendable` by piping input to the append methods through the translator first. WDYT?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---