+ bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
+ num = ((*size_ret <= 1 /* Check the possibility of short cut. */
+ || NILP (buffer_defaults.enable_multibyte_characters))
+ ? 0
+ : find_charset_in_str (*data_ret, *size_ret, charsets, Qnil));
+
+ if (!num || (num == 1 && charsets[CHARSET_ASCII]))
+ {
+ /* No multibyte character in OBJ. We need not encode it. */
+ *nofree_ret = 1;
+ if (NILP (type)) type = QSTRING;
+ }
+ else
+ {
+ /* We must encode contents of OBJ to compound text format.
+ The format is compatible with what the target `STRING'
+ expects if OBJ contains only ASCII and Latin-1
+ characters. */
+ int bufsize;
+ unsigned char *buf;
+ struct coding_system coding;
+
+ setup_coding_system
+ (Fcheck_coding_system (Vclipboard_coding_system), &coding);
+ coding.mode |= CODING_MODE_LAST_BLOCK;
+ bufsize = encoding_buffer_size (&coding, *size_ret);
+ buf = (unsigned char *) xmalloc (bufsize);
+ encode_coding (&coding, *data_ret, buf, *size_ret, bufsize);
+ *size_ret = coding.produced;
+ *data_ret = buf;
+ if (charsets[charset_latin_iso8859_1]
+ && (num == 1 || (num == 2 && charsets[CHARSET_ASCII])))
+ {
+ /* Ok, we can return it as `STRING'. */
+ if (NILP (type)) type = QSTRING;
+ }
+ else
+ {
+ /* We must return it as `COMPOUND_TEXT'. */
+ if (NILP (type)) type = QCOMPOUND_TEXT;
+ }
+ }