Skip to content

Commit

Permalink
Added classes for encoding/decoding data.
Browse files Browse the repository at this point in the history
  Coder: Encoder/decoder interface.
  GzipCoder: Gzip encoder/decoder.
  XzCoder: Xz encoder/decoder.
  • Loading branch information
susumu.yata committed Oct 1, 2010
1 parent 2af1f05 commit dc0ed8d
Show file tree
Hide file tree
Showing 16 changed files with 1,016 additions and 34 deletions.
257 changes: 257 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,60 @@ fi
} # ac_fn_cxx_check_header_mongrel
# ac_fn_c_find_uintX_t LINENO BITS VAR
# ------------------------------------
# Finds an unsigned integer type with width BITS, setting cache variable VAR
# accordingly.
ac_fn_c_find_uintX_t ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uint$2_t" >&5
$as_echo_n "checking for uint$2_t... " >&6; }
if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
$as_echo_n "(cached) " >&6
else
eval "$3=no"
# Order is important - never check a type that is potentially smaller
# than half of the expected target width.
for ac_type in uint$2_t 'unsigned int' 'unsigned long int' \
'unsigned long long int' 'unsigned short int' 'unsigned char'; do
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$ac_includes_default
int
main ()
{
static int test_array [1 - 2 * !((($ac_type) -1 >> ($2 / 2 - 1)) >> ($2 / 2 - 1) == 3)];
test_array [0] = 0
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
case $ac_type in #(
uint$2_t) :
eval "$3=yes" ;; #(
*) :
eval "$3=\$ac_type" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
eval as_val=\$$3
if test "x$as_val" = x""no; then :
else
break
fi
done
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
} # ac_fn_c_find_uintX_t
# ac_fn_cxx_try_link LINENO
# -------------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
Expand Down Expand Up @@ -4798,6 +4852,42 @@ fi
ac_fn_cxx_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default"
if test "x$ac_cv_header_zlib_h" = x""yes; then :
else
as_fn_error "\
The NWC Toolkit requires zlib.
Project URL: http://www.zlib.net/" "$LINENO" 5
fi
ac_fn_cxx_check_header_mongrel "$LINENO" "bzlib.h" "ac_cv_header_bzlib_h" "$ac_includes_default"
if test "x$ac_cv_header_bzlib_h" = x""yes; then :
else
as_fn_error "\
The NWC Toolkit requires zlib.
Project URL: http://www.bzip.org/" "$LINENO" 5
fi
ac_fn_cxx_check_header_mongrel "$LINENO" "lzma.h" "ac_cv_header_lzma_h" "$ac_includes_default"
if test "x$ac_cv_header_lzma_h" = x""yes; then :
else
as_fn_error "\
The NWC Toolkit requires liblzma (XZ Utils).
Project URL: http://tukaani.org/xz/" "$LINENO" 5
fi
# Checks for typedefs, structures, and compiler characteristics.
ac_fn_cxx_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
if test "x$ac_cv_type_size_t" = x""yes; then :
Expand All @@ -4810,6 +4900,20 @@ _ACEOF
fi
ac_fn_c_find_uintX_t "$LINENO" "8" "ac_cv_c_uint8_t"
case $ac_cv_c_uint8_t in #(
no|yes) ;; #(
*)
$as_echo "#define _UINT8_T 1" >>confdefs.h
cat >>confdefs.h <<_ACEOF
#define uint8_t $ac_cv_c_uint8_t
_ACEOF
;;
esac
# Checks for library functions.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv in -liconv" >&5
Expand Down Expand Up @@ -4863,6 +4967,159 @@ Project URL: http://www.gnu.org/software/libiconv/" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzopen in -lz" >&5
$as_echo_n "checking for gzopen in -lz... " >&6; }
if test "${ac_cv_lib_z_gzopen+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lz $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char gzopen ();
int
main ()
{
return gzopen ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_lib_z_gzopen=yes
else
ac_cv_lib_z_gzopen=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzopen" >&5
$as_echo "$ac_cv_lib_z_gzopen" >&6; }
if test "x$ac_cv_lib_z_gzopen" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBZ 1
_ACEOF
LIBS="-lz $LIBS"
else
as_fn_error "\
The NWC Toolkit requires zlib.
Project URL: http://www.zlib.net/" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzopen in -lbz2" >&5
$as_echo_n "checking for BZ2_bzopen in -lbz2... " >&6; }
if test "${ac_cv_lib_bz2_BZ2_bzopen+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lbz2 $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char BZ2_bzopen ();
int
main ()
{
return BZ2_bzopen ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_lib_bz2_BZ2_bzopen=yes
else
ac_cv_lib_bz2_BZ2_bzopen=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzopen" >&5
$as_echo "$ac_cv_lib_bz2_BZ2_bzopen" >&6; }
if test "x$ac_cv_lib_bz2_BZ2_bzopen" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBBZ2 1
_ACEOF
LIBS="-lbz2 $LIBS"
else
as_fn_error "\
The NWC Toolkit requires zlib.
Project URL: http://www.bzip.org/" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lzma_code in -llzma" >&5
$as_echo_n "checking for lzma_code in -llzma... " >&6; }
if test "${ac_cv_lib_lzma_lzma_code+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-llzma $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lzma_code ();
int
main ()
{
return lzma_code ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_lib_lzma_lzma_code=yes
else
ac_cv_lib_lzma_lzma_code=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lzma_lzma_code" >&5
$as_echo "$ac_cv_lib_lzma_lzma_code" >&6; }
if test "x$ac_cv_lib_lzma_lzma_code" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBLZMA 1
_ACEOF
LIBS="-llzma $LIBS"
else
as_fn_error "\
The NWC Toolkit requires liblzma (XZ Utils).
Project URL: http://tukaani.org/xz/" "$LINENO" 5
fi
ac_config_files="$ac_config_files Makefile lib/Makefile tools/Makefile tests/Makefile"
cat >confcache <<\_ACEOF
Expand Down
31 changes: 31 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,45 @@ The NWC Toolkit requires libiconv.
Project URL: http://www.gnu.org/software/libiconv/])])

AC_CHECK_HEADER([zlib.h], , [AC_MSG_ERROR([\
The NWC Toolkit requires zlib.
Project URL: http://www.zlib.net/])])

AC_CHECK_HEADER([bzlib.h], , [AC_MSG_ERROR([\
The NWC Toolkit requires zlib.
Project URL: http://www.bzip.org/])])

AC_CHECK_HEADER([lzma.h], , [AC_MSG_ERROR([\
The NWC Toolkit requires liblzma (XZ Utils).
Project URL: http://tukaani.org/xz/])])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_CHECK_LIB([iconv], [iconv], , [AC_MSG_ERROR([\
The NWC Toolkit requires libiconv.
Project URL: http://www.gnu.org/software/libiconv/])])

AC_CHECK_LIB([z], [gzopen], , [AC_MSG_ERROR([\
The NWC Toolkit requires zlib.
Project URL: http://www.zlib.net/])])

AC_CHECK_LIB([bz2], [BZ2_bzopen], , [AC_MSG_ERROR([\
The NWC Toolkit requires zlib.
Project URL: http://www.bzip.org/])])

AC_CHECK_LIB([lzma], [lzma_code], , [AC_MSG_ERROR([\
The NWC Toolkit requires liblzma (XZ Utils).
Project URL: http://tukaani.org/xz/])])

AC_CONFIG_FILES([Makefile lib/Makefile tools/Makefile tests/Makefile])
AC_OUTPUT
13 changes: 8 additions & 5 deletions include/nwc-toolkit/character-encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class CharacterEncoding {
static bool Convert(const String &src_code, const String &src,
const String &dest_code, StringBuilder *dest);

static bool DetectFromBOM(const String &str, StringBuilder *encoding);
static bool DetectFromResponseHead(const String &str,
StringBuilder *encoding);
static bool DetectFromHtml(const String &str, StringBuilder *encoding);
static bool DetectFromXml(const String &str, StringBuilder *encoding);
static bool DetectFromBOM(
const String &str, StringBuilder *encoding);
static bool DetectFromResponseHeader(
const String &str, StringBuilder *encoding);
static bool DetectFromHtmlHeader(
const String &str, StringBuilder *encoding);
static bool DetectFromXmlHeader(
const String &str, StringBuilder *encoding);

private:
// Disallows copies.
Expand Down
Loading

0 comments on commit dc0ed8d

Please sign in to comment.