utf8.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:3k
源码类别:
midi
开发平台:
Unix_Linux
- /*****************************************************************************
- * utf8.c: Test for UTF-8 encoding/decoding stuff
- *****************************************************************************
- * Copyright (C) 2006 Rémi Denis-Courmont
- * $Id: f34a953c9ce95d2e95a38f1871b1d8ccfb111aff $
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include <vlc_common.h>
- #include "vlc_charset.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- static void test (const char *in, const char *out)
- {
- bool isutf8 = !strcmp (in, out);
- char *str = strdup (in);
- if (str == NULL)
- abort ();
- if (isutf8)
- printf (""%s" should be accepted...n", in);
- else
- printf (""%s" should be rewritten as "%s"...n", in, out);
- if ((IsUTF8 (in) != NULL) != isutf8)
- {
- printf (" ERROR: IsUTF8 (%s) failedn", in);
- exit (1);
- }
- if ((EnsureUTF8 (str) != NULL) != isutf8)
- {
- printf (" ERROR: EnsureUTF8 (%s) failedn", in);
- exit (2);
- }
- if (strcmp (str, out))
- {
- printf (" ERROR: got "%s"n", str);
- exit (3);
- }
- if ((EnsureUTF8 (str) == NULL) || IsUTF8 (str) == NULL)
- {
- printf (" ERROR: EnsureUTF8 (%s) is not UTF-8n", in);
- exit (4);
- }
- free (str);
- }
- int main (void)
- {
- (void)setvbuf (stdout, NULL, _IONBF, 0);
- test ("", "");
- test ("this_should_not_be_modified_1234",
- "this_should_not_be_modified_1234");
- test ("xFF", "?"); // invalid byte
- test ("xEFxBBxBFHello", "xEFxBBxBFHello"); // BOM
- test ("x00xE9", ""); // no conversion past end of string
- test ("TxC3xA9lxC3xA9vision xE2x82xAC", "Télévision €");
- test ("TxE9lxE9vision", "T?l?vision");
- test ("xC1x94xC3xa9lxC3xA9vision", "??élévision"); /* overlong */
- test ("HelxF0x83x85x87lo", "Hel????lo"); /* more overlong */
- return 0;
- }