Skip to content

Commit

Permalink
[INLONG-11190][SDK] Optimize Transform SDK Translate Function
Browse files Browse the repository at this point in the history
  • Loading branch information
vernedeng committed Sep 23, 2024
1 parent b66a57f commit 67a7db9
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: harry@inlong.com target_expression: harry.inlong.com
* case1: translate(harry@inlong.com, '@', '.') -> original_expression: harry@inlong.com 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 67a7db9

Please sign in to comment.