public BinaryString trimLeft ( BinaryString trimStr ) { ensureMaterialized ( ) ; if ( trimStr == null ) { return null ; } trimStr . ensureMaterialized ( ) ; if ( trimStr . isSpaceString ( ) ) { return trimLeft ( ) ; } if ( inFirstSegment ( ) ) { int searchIdx = 0 ; while ( searchIdx < this . sizeInBytes ) { int charBytes = numBytesForFirstByte ( getByteOneSegment ( searchIdx ) ) ; BinaryString currentChar = copyBinaryStringInOneSeg ( searchIdx , searchIdx + charBytes - 1 ) ; // try to find the matching for the character in the trimString characters. if ( trimStr . contains ( currentChar ) ) { searchIdx += charBytes ; } else { break ; } } // empty string if ( searchIdx >= sizeInBytes ) { return EMPTY_UTF8 ; } else { return copyBinaryStringInOneSeg ( searchIdx , sizeInBytes - 1 ) ; } } else { return trimLeftSlow ( trimStr ) ; } }
Walk each character of current string from left end remove the character if it is in trim string . Stops at the first character which is not in trim string . Return the new substring .