XenoAmess commented on a change in pull request #577:
URL: https://github.com/apache/commons-lang/pull/577#discussion_r452277354
##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -6234,8 +6239,34 @@ public static String repeat(final char ch, final int
repeat) {
return new String(buf);
}
- // Padding
- //-----------------------------------------------------------------------
+ /**
+ * <p>Returns padding using the specified delimiter repeated
+ * to a given length.</p>
+ *
+ * <pre>
+ * StringUtils.repeat('e', 0) = ""
+ * StringUtils.repeat('e', 3) = "eee"
+ * StringUtils.repeat('e', -2) = ""
+ * </pre>
+ *
+ * <p>Note: this method does not support padding with
+ * <a
href="http://www.unicode.org/glossary/#supplementary_character">Unicode
Supplementary Characters</a>
+ * as they require a pair of {@code char}s to be represented.
+ * If you are needing to support full I18N of your applications
+ * consider using {@link #repeat(String, int)} instead.
+ * </p>
+ *
+ * @param stringBuilder stringBuilder to fill
+ * @param ch character to repeat
+ * @param repeat number of times to repeat char, negative treated as zero
+ * @see #repeat(String, int)
+ */
+ public static void repeat(StringBuilder stringBuilder, final char ch,
final int repeat) {
Review comment:
@garydgregory
> Why is this API typed to a `StringBuilder` instead of a `Appendable`?
Yeah you are right. will do this change.
will aslo refine the javadoc of this function.
> Do we need an `AppendableUtils`?
Don't think so but I do think quite some of functions should be changed from
build a string, and using it to build another string, and build another string,
to build the whole string using StringBuilder, this one named `center` is a
good example I think.
I create this repeat function to reduce String creation.
And I don't actually know if people really often use functions like this in
real work.
##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -6234,8 +6239,34 @@ public static String repeat(final char ch, final int
repeat) {
return new String(buf);
}
- // Padding
- //-----------------------------------------------------------------------
+ /**
+ * <p>Returns padding using the specified delimiter repeated
+ * to a given length.</p>
+ *
+ * <pre>
+ * StringUtils.repeat('e', 0) = ""
+ * StringUtils.repeat('e', 3) = "eee"
+ * StringUtils.repeat('e', -2) = ""
+ * </pre>
+ *
+ * <p>Note: this method does not support padding with
+ * <a
href="http://www.unicode.org/glossary/#supplementary_character">Unicode
Supplementary Characters</a>
+ * as they require a pair of {@code char}s to be represented.
+ * If you are needing to support full I18N of your applications
+ * consider using {@link #repeat(String, int)} instead.
+ * </p>
+ *
+ * @param stringBuilder stringBuilder to fill
+ * @param ch character to repeat
+ * @param repeat number of times to repeat char, negative treated as zero
+ * @see #repeat(String, int)
+ */
+ public static void repeat(StringBuilder stringBuilder, final char ch,
final int repeat) {
Review comment:
@garydgregory
> Why is this API typed to a `StringBuilder` instead of a `Appendable`?
Yeah you are right. will do this change.
will aslo refine the javadoc of this function.
> Do we need an `AppendableUtils`?
Don't think so but I do think quite some of functions should be changed from
build a string, and using it to build another string, and build another string,
to build the whole string using StringBuilder, this one named `center` is a
good example I think.
I create this repeat function to reduce String creation.
And I don't actually know if people really often use functions like this in
real work.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]