Skip to content

Commit

Permalink
[INLONG-11190][SDK] Optimize Transform SDK Translate Function (#11191)
Browse files Browse the repository at this point in the history
  • Loading branch information
vernedeng authored Sep 24, 2024
1 parent c2e599a commit 175763e
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* find_chars: A string containing the characters to be replaced.
* replace_chars: A string containing the characters to substitute.
* examples:
* case1: translate(email, '@', '.') -> original_expression: [email protected] target_expression: harry.inlong.com
* case1: translate([email protected], '@', '.') -> original_expression: [email protected] target_expression: harry.inlong.com
* case2: translate(hello WorD, 'WD', 'wd') -> original_expression: hello WorD target_expression: hello word
*/
@TransformFunction(names = {"translate"})
Expand Down Expand Up @@ -108,9 +108,7 @@ private Map<Character, Character> parseReplacementMap(String findChars, String r
return ImmutableMap.of();
}

final int findSize = findChars == null ? 0 : findChars.length();
final int replaceSize = replaceChars == null ? 0 : replaceChars.length();
final int commonSize = Math.min(findSize, replaceSize);
final int commonSize = Math.min(findChars.length(), replaceChars.length());
// Create a map to store character replacements
Map<Character, Character> replacementMap = new HashMap<>();
for (int i = 0; i < commonSize; i++) {
Expand Down

0 comments on commit 175763e

Please sign in to comment.