/* xls2xml: Converts from Microsoft Excel files to XML. Copyright 1999 Roberto Arturo Tena Sanchez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Roberto Arturo Tena Sanchez */ #include int fil_ucs2ToUTF8 (U8 * out, int outlen, U8 * in, int inlen) { U16 c; U8 * inend = in + inlen; U8 * outend = out + outlen; U8 * outstart = out; test (!(inlen % 2), -3); while (in < inend) { c = _xls2xml_sreadU16 (in); in += 2; if (c < 0x0080) { test (out < outend, -1); *out = (U8)c; out++; } else if (c < 0x0800) { test (out < outend, -1); *out = 0xc0 | (c >> 6); out++; test (out < outend, -1); *out = 0x80 | (0x3f & c); out++; } else /* c < 0xffff */ { test (out < outend, -1); *out = 0xe0 | (c >> 12); out++; test (out < outend, -1); *out = 0x80 | (0x3f & (c >> 6)); out++; test (out < outend, -1); *out = 0x80 | (0x3f & c); out++; } } return out - outstart; }