I need to export to a file a Prolog program expressed using an arbitrary term representation in Java. The idea is that a Prolog interpreter should be able to consult the generated file afterwards.
My question is about the correct way to write in the file Java Strings representing atom terms.

For example, if the string has a space in the middle, it should be surrounded by single quotes in the file:

 *hello world*   **becomes**   *'hello world'*

And the exporter should take into consideration characters that should be escaped:

 *'*   **becomes**  *'\''*

Could someone point me to the place were these rules are specified?, and: Can I assume that these rules are respected by major Prolog implementors? (I mean, a Prolog program generated following these rules would be correctly parsed by most Prolog interpreters?).