Adds trimLastPathSegment string method.