Unexpected behavior of term_string

I’m using: SWI-Prolog version 9.0.0

can someone help me understand this behavior from term_string/2

?- term_string(" -- abc \a \b \f \n \r \t \v \u1234 \' - \\ \" - \` -- ",A).
A = "\" -- abc \a \b \f \n \r \t \v ሴ ' - \\\\ \"\" - ` -- \"".

?- term_string(" \\ \"  \\\\ \"\" -- ",A).
A = "\" \\\\ \"\"  \\\\\\\\ \"\"\"\" -- \"".

?- term_string(' -- abc \a \b \f \n \r \t \v \u1234 \' -  \\ \" -  \` -- ',A).
A = "' -- abc \a \b \f \n \r \t \v ሴ '' -  \\\\ \" -  ` -- '".

why the escape sequences \\ , \" and \’ get “duplicated” while the other ones don’t?

shouldn’t also \" become \\\" instead of \“\” ?

Try each of your queries, adding this to each one: ,string_codes(A,Codes),string_chars(A,Chars).
And you probably want this flag setting:

set_prolog_flag(answer_write_options, [quoted(true),portray(true),max_depth(100),spacing(next_argument)]).
?- String = " -- abc \a \b \f \n \r \t \v \u1234 \' - \\ \" - \` -- ", term_string(String, A), string_codes(String,StringCodes), string_chars(String,StringChars), string_codes(A,Codes), string_chars(A,Chars).
String = " -- abc \a \b \f \n \r \t \v ሴ ' - \\ \" - ` -- ",
A = "\" -- abc \a \b \f \n \r \t \v ሴ ' - \\\\ \"\" - ` -- \"",
StringCodes = [32, 45, 45, 32, 97, 98, 99, 32, 7, 32, 8, 32, 12, 32, 10, 32, 13, 32, 9, 32, 11, 32, 4660, 32, 39, 32, 45, 32, 92, 32, 34, 32, 45, 32, 96, 32, 45, 45, 32],
StringChars = [' ', -, -, ' ', a, b, c, ' ', '\a', ' ', '\b', ' ', '\f', ' ', '\n', ' ', '\r', ' ', '\t', ' ', '\v', ' ', ሴ, ' ', '\'', ' ', -, ' ', \, ' ', '"', ' ', -, ' ', '`', ' ', -, -, ' '],
Codes = [34, 32, 45, 45, 32, 97, 98, 99, 32, 7, 32, 8, 32, 12, 32, 10, 32, 13, 32, 9, 32, 11, 32, 4660, 32, 39, 32, 45, 32, 92, 92, 32, 34, 34, 32, 45, 32, 96, 32, 45, 45, 32, 34],
Chars = ['"', ' ', -, -, ' ', a, b, c, ' ', '\a', ' ', '\b', ' ', '\f', ' ', '\n', ' ', '\r', ' ', '\t', ' ', '\v', ' ', ሴ, ' ', '\'', ' ', -, ' ', \, \, ' ', '"', '"', ' ', -, ' ', '`', ' ', -, -, ' ', '"'].

?- String = " \\ \"  \\\\ \"\" -- ", term_string(String, A), string_codes(String,StringCodes), string_chars(String,StringChars), string_codes(A,Codes), string_chars(A,Chars).
String = " \\ \"  \\\\ \"\" -- ",
A = "\" \\\\ \"\"  \\\\\\\\ \"\"\"\" -- \"",
StringCodes = [32, 92, 32, 34, 32, 32, 92, 92, 32, 34, 34, 32, 45, 45, 32],
StringChars = [' ', \, ' ', '"', ' ', ' ', \, \, ' ', '"', '"', ' ', -, -, ' '],
Codes = [34, 32, 92, 92, 32, 34, 34, 32, 32, 92, 92, 92, 92, 32, 34, 34, 34, 34, 32, 45, 45, 32, 34],
Chars = ['"', ' ', \, \, ' ', '"', '"', ' ', ' ', \, \, \, \, ' ', '"', '"', '"', '"', ' ', -, -, ' ', '"'].

?- Atom = ' -- abc \a \b \f \n \r \t \v \u1234 \' -  \\ \" -  \` -- ', term_string(Atom, A), string_codes(Atom,AtomCodes), string_chars(Atom,AtomChars), string_codes(A,Codes), string_chars(A,Chars).
Atom = ' -- abc \a \b \f \n \r \t \v ሴ \' -  \\ " -  ` -- ',
A = "' -- abc \a \b \f \n \r \t \v ሴ '' -  \\\\ \" -  ` -- '",
AtomCodes = [32, 45, 45, 32, 97, 98, 99, 32, 7, 32, 8, 32, 12, 32, 10, 32, 13, 32, 9, 32, 11, 32, 4660, 32, 39, 32, 45, 32, 32, 92, 32, 34, 32, 45, 32, 32, 96, 32, 45, 45, 32],
AtomChars = [' ', -, -, ' ', a, b, c, ' ', '\a', ' ', '\b', ' ', '\f', ' ', '\n', ' ', '\r', ' ', '\t', ' ', '\v', ' ', ሴ, ' ', '\'', ' ', -, ' ', ' ', \, ' ', '"', ' ', -, ' ', ' ', '`', ' ', -, -, ' '],
Codes = [39, 32, 45, 45, 32, 97, 98, 99, 32, 7, 32, 8, 32, 12, 32, 10, 32, 13, 32, 9, 32, 11, 32, 4660, 32, 39, 39, 32, 45, 32, 32, 92, 92, 32, 34, 32, 45, 32, 32, 96, 32, 45, 45, 32, 39],
Chars = ['\'', ' ', -, -, ' ', a, b, c, ' ', '\a', ' ', '\b', ' ', '\f', ' ', '\n', ' ', '\r', ' ', '\t', ' ', '\v', ' ', ሴ, ' ', '\'', '\'', ' ', -, ' ', ' ', \, \, ' ', '"', ' ', -, ' ', ' ', '`', ' ', -, -, ' ', '\''].

as you can see the escape sequences \ , " and \’ get duplicated while the other ones don’t