|
19 | 19 | package org.apache.pinot.common.function.scalar.string; |
20 | 20 |
|
21 | 21 | import org.apache.commons.lang3.StringUtils; |
| 22 | +import org.apache.commons.lang3.Strings; |
22 | 23 | import org.apache.pinot.spi.annotations.ScalarFunction; |
23 | 24 |
|
24 | 25 |
|
@@ -54,35 +55,28 @@ public String concatWS(String separator, String input1, String input2) { |
54 | 55 | } |
55 | 56 |
|
56 | 57 | /** |
57 | | - * @param input |
58 | | - * @param searchString target substring to replace |
59 | | - * @param substitute new substring to be replaced with target |
60 | | - * @see String#replaceAll(String, String) |
| 58 | + * @see Strings#replace(String, String, String) |
61 | 59 | */ |
62 | 60 | @ScalarFunction |
63 | | - public String replace(String input, String searchString, String substitute) { |
64 | | - if (StringUtils.isEmpty(input) || StringUtils.isEmpty(searchString) || substitute == null) { |
65 | | - return input; |
| 61 | + public String replace(String text, String searchString, String replacement) { |
| 62 | + if (text.isEmpty() || searchString.isEmpty()) { |
| 63 | + return text; |
66 | 64 | } |
67 | 65 | int start = 0; |
68 | | - int end = StringUtils.indexOf(input, searchString, start); |
| 66 | + int end = Strings.CS.indexOf(text, searchString, start); |
69 | 67 | if (end == StringUtils.INDEX_NOT_FOUND) { |
70 | | - return input; |
| 68 | + return text; |
71 | 69 | } |
72 | 70 | final int replLength = searchString.length(); |
73 | | - int increase = Math.max(substitute.length() - replLength, 0) * 16; |
| 71 | + int increase = Math.max(replacement.length() - replLength, 0) * 16; |
74 | 72 | _buffer.setLength(0); |
75 | | - _buffer.ensureCapacity(input.length() + increase); |
76 | | - int max = -1; |
| 73 | + _buffer.ensureCapacity(text.length() + increase); |
77 | 74 | while (end != StringUtils.INDEX_NOT_FOUND) { |
78 | | - _buffer.append(input, start, end).append(substitute); |
| 75 | + _buffer.append(text, start, end).append(replacement); |
79 | 76 | start = end + replLength; |
80 | | - if (--max == 0) { |
81 | | - break; |
82 | | - } |
83 | | - end = StringUtils.indexOf(input, searchString, start); |
| 77 | + end = Strings.CS.indexOf(text, searchString, start); |
84 | 78 | } |
85 | | - _buffer.append(input, start, input.length()); |
| 79 | + _buffer.append(text, start, text.length()); |
86 | 80 | return _buffer.toString(); |
87 | 81 | } |
88 | 82 | } |
0 commit comments