private static void appendNewlineIfNoTrailingNewline(Editable text) {
      int len = text.length();
      if (len == 0) {
        text.append('\n');
        return;
      }

      if (text.charAt(len - 1) != '\n') {
        text.append('\n');
      }
    }
Appends a newline to the provided text if the text does not already end with a newline.
java/com/google/android/apps/authenticator/util/Utilities.java