code: static int adjustEnd(String msg, int start, int originEnd) {
      if (originEnd == msg.length()) {
        // Already end of message.
        return originEnd;
      }
      if (msg.charAt(originEnd) == '\n') {
        // Already prior to '\n'.
        return originEnd;
      }
      // Search back for '\n'.
      int last = originEnd - 1;
      while (start < last) {
        if (msg.charAt(last) == '\n') {
          return last + 1;
        }
        last--;
      }
      return originEnd;
    }
docs: Move the end to the nearest line separator('\n') (if exist).