Github user wzhfy commented on a diff in the pull request: https://github.com/apache/spark/pull/12646#discussion_r118477067 --- Diff: common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java --- @@ -535,6 +577,48 @@ public UTF8String trimRight() { } } + /** + * Removes the given trim string from the ending of a string + * This method searches each character in the source string starting from the right end, removes the character if it + * is in the trim string, stops at the first character which is not in the trim string, returns the new string. + * @param trimString the trim character string + */ + public UTF8String trimRight(UTF8String trimString) { + // index trimEnd points to first no matching byte position in the input string from right side, + // it moves the number of bytes of the trimming character. + int trimEnd; + int trimIdx = 0; + int numChars = 0; // number of characters from the input string + int[] stringCharLen = new int[numBytes]; // array of character length for the input string + int[] stringCharPos = new int[numBytes]; // array of the first byte position for each character in the input string + //build the position and length array + while (trimIdx < numBytes) { + stringCharPos[numChars] = trimIdx; + stringCharLen[numChars]= numBytesForFirstByte(getByte(trimIdx)); + trimIdx += stringCharLen[numChars]; + numChars ++; + } + + trimEnd = numBytes - 1; --- End diff -- move declaration and description of `trimEnd` here.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org