Start adding UTF-8 support: first step Add an internal function that guesses the encoding of a string: ASCII, UTF-8, or CP437. Add a test program and 3 test cases, one for each encoding. --HG-- branch : HEAD
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt index c93a0e5..82bc870 100644 --- a/regress/CMakeLists.txt +++ b/regress/CMakeLists.txt
@@ -5,6 +5,7 @@ add_from_file add_from_filep add_from_zip + encoding encrypt fread get_comment
diff --git a/regress/Makefile.am b/regress/Makefile.am index 9cf0cd6..6912213 100644 --- a/regress/Makefile.am +++ b/regress/Makefile.am
@@ -4,6 +4,7 @@ add_from_file \ add_from_filep \ add_from_zip \ + encoding \ encrypt \ fread \ get_comment \ @@ -45,6 +46,9 @@ add_from_file.test \ add_from_filep.test \ add_from_zip.test \ + encoding-ascii.test \ + encoding-cp437.test \ + encoding-utf-8.test \ encrypt.test \ fread.test \ get_comment.test \
diff --git a/regress/encoding-ascii.test b/regress/encoding-ascii.test new file mode 100644 index 0000000..5d086f8 --- /dev/null +++ b/regress/encoding-ascii.test
@@ -0,0 +1,5 @@ +# recognize ASCII +program encoding +return 0 +args ABC%^&&*!@#_.as./- +stdout guessing ABC%^&&*!@#_.as./-: ASCII
diff --git a/regress/encoding-cp437.test b/regress/encoding-cp437.test new file mode 100644 index 0000000..fca9109 --- /dev/null +++ b/regress/encoding-cp437.test
@@ -0,0 +1,5 @@ +# recognize CP437 +program encoding +return 0 +args TestAá^$ +stdout guessing TestAá^$: CP437
diff --git a/regress/encoding-utf-8.test b/regress/encoding-utf-8.test new file mode 100644 index 0000000..74e431b --- /dev/null +++ b/regress/encoding-utf-8.test
@@ -0,0 +1,5 @@ +# recognize UTF-8 +program encoding +return 0 +args TestÄÖAÜß^$ +stdout guessing TestÄÖAÜß^$: UTF-8
diff --git a/regress/encoding.c b/regress/encoding.c new file mode 100644 index 0000000..2bf6d65 --- /dev/null +++ b/regress/encoding.c
@@ -0,0 +1,56 @@ +/* + encoding.c -- tool for encoding tests + Copyright (C) 2011 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at <libzip@nih.at> + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "zip.h" +#include "zipint.h" + +const char *result[] = { + "ASCII", + "UTF-8", + "CP437" +}; + +int +main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "usage: %s string_to_guess\n", argv[0]); + exit(1); + } + printf("guessing %s: %s\n", argv[1], result[_zip_guess_encoding(argv[1], strlen(argv[1]))]); + exit(0); +}