justinborromeo commented on a change in pull request #7388: Support LPAD and
RPAD sql function
URL: https://github.com/apache/incubator-druid/pull/7388#discussion_r273716078
##########
File path:
core/src/main/java/org/apache/druid/java/util/common/StringUtils.java
##########
@@ -360,4 +360,93 @@ public static String encodeBase64String(byte[] input)
{
return BASE64_DECODER.decode(input);
}
+
+ /**
+ * Returns the string left-padded with the string pad to a length of len
characters.
+ * If str is longer than len, the return value is shortened to len
characters.
+ *
+ * @param base The base string to be padded
+ * @param len The length of padded string
+ * @param pad The pad string
+ * @return the string left-padded with pad to a lenght of len
+ */
+ public static String lpad(String base, Integer len, String pad)
+ {
+ if (len < 0) {
+ return null;
+ } else if (len == 0) {
+ return "";
+ }
+
+ char[] data = new char[len];
+ char[] baseChars = base.toCharArray();
Review comment:
Is there a reason you copy `base` and `pad` to their own char arrays instead
of just calling `charAt(index)` on the original strings?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]