[liblas] 01/06: Imported Upstream version 1.8.1

Bas Couwenberg sebastic at debian.org
Tue Aug 23 20:25:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository liblas.

commit 77369fed3cac44f502906084cae1508c2cc9c925
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Tue Aug 23 21:15:51 2016 +0200

    Imported Upstream version 1.8.1
---
 apps/CMakeLists.txt                                |  453 +-
 apps/las2col.c                                     |   16 +-
 apps/las2las.cpp                                   |    2 +-
 apps/las2pg.c                                      |  248 +-
 apps/laskernel.cpp                                 |  492 +-
 bin/ci/before_install.sh                           |    2 +-
 cmake/modules/FindPROJ4.cmake                      |   88 +-
 doc/conf.py                                        |   18 +-
 doc/development/annual_report_2010.txt             |  247 -
 doc/download.txt                                   |    9 +-
 doc/python.txt                                     |   49 +-
 doc/utilities/index.txt                            |    2 +-
 doc/utilities/las2tindex.txt                       |    7 +-
 doc/utilities/lasblock.txt                         |   84 -
 doc/utilities/lasdiff.txt                          |   28 -
 doc/utilities/lasmerge.txt                         |   76 -
 .../external/property_tree/detail/rapidxml.hpp     | 5142 ++++++++++----------
 .../liblas/external/property_tree/xml_parser.hpp   |  306 +-
 python/liblas/header.py                            |   11 +-
 python/tests/Header.txt                            |    2 +-
 src/CMakeLists.txt                                 |  534 +-
 src/detail/reader/header.cpp                       |  172 +-
 22 files changed, 3779 insertions(+), 4209 deletions(-)

diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index d22b4ea..beb83e2 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -1,225 +1,228 @@
-###############################################################################
-#
-# apps/CMakeLists.txt controls building of libLAS utilities
-#
-# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
-#
-###############################################################################
-
-include_directories(
-    .
-    ../include
-    ../include/liblas/capi)
-
-###############################################################################
-# Collect programs to build
-
-set(LASINFO lasinfo)
-set(LAS2LAS las2las)
-set(LAS2TXT las2txt)
-set(TXT2LAS txt2las)
-set(TS2LAS ts2las)
-set(LASBLOCK lasblock )
-set(LAS2COL las2col )
-set(LAS2PG las2pg )
-
-set(BIGFILE_TEST bigfile_test)
-set(LASINDEX_TEST lasindex_test)
-
-if(Boost_IOSTREAMS_FOUND)
-  set(BIGFILE_BIO_TEST bigfile_boost_iostreams_test)
-endif()
-
-# Set the build type to release if it is not explicitly set by the user and
-# isn't in the cache yet
-if (NOT CMAKE_BUILD_TYPE )
-  set(CMAKE_BUILD_TYPE "Release")
-endif()
-
-# Utilities depending on 3rd-pary libraries
-if(GDAL_FOUND)
-    set(LAS2OGR las2ogr)
-endif()
-
-
-set(LIBLAS_UTILITIES
-    ${LASINFO} ${LAS2LAS} ${TXT2LAS}  ${LAS2COL}  ${LAS2PG}
-    ${LAS2OGR} ${LAS2LAS} ${LASBLOCK} ${TS2LAS}  ${LAS2TXT})
-
-# TODO: Experimental and requires testing --mloskot
-# Generate user-specific settings for Visual Studio project
-set(VCPROJ_USER_REMOTE_MACHINE_DEBUG ${MACHINE_NAME})
-set(VCPROJ_USER_ENVIRONMENT_DEBUG "${ENVIRONMENT_PATH}")
-
-if(MSVC)
-    foreach(utility ${LIBLAS_UTILITIES})
-        set(USER_FILE ${utility}.vcproj.$ENV{USERDOMAIN}.$ENV{USERNAME}.user)
-        set(OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${USER_FILE})
-        message(STATUS "Generating ${CMAKE_GENERATOR} user-specific settings in ${USER_FILE}")
-        configure_file(${CMAKE_SOURCE_DIR}/cmake/libLAS.vcproj.user.template ${OUTPUT_PATH} @ONLY)
-    endforeach()
-endif()
-
-###############################################################################
-# Configure build targets
-
-if(WIN32)
-    add_definitions("-DLAS_DLL_EXPORT=1")
-endif()
-
-
-set(APPS_CPP_DEPENDENCIES
-    ${LIBLAS_LIB_NAME}
-)
-
-# link_directories(${Boost_LIBRARY_DIRS})
-
-#    add_executable(lasschematest lasschematest.cpp laskernel.cpp)
-#    target_link_libraries(lasschematest ${APPS_CPP_DEPENDENCIES} ${LIBXML2_LIBRARIES})
-
-
-if(LAS2LAS)
-    add_executable(${LAS2LAS} las2las.cpp laskernel.cpp)
-    target_link_libraries(${LAS2LAS} ${APPS_CPP_DEPENDENCIES} )
-endif()
-
-if(LASINFO)
-    add_executable(${LASINFO} lasinfo.cpp laskernel.cpp )
-    target_link_libraries(${LASINFO} ${APPS_CPP_DEPENDENCIES}  )
-endif()
-
-if(LAS2TXT)
-    add_executable( ${LAS2TXT}  las2txt.cpp laskernel.cpp )
-    target_link_libraries(${LAS2TXT} ${APPS_CPP_DEPENDENCIES}  )
-endif()
-
-# Build txt2las
-if(TXT2LAS)
-    set(TXT2LAS_SRC lascommon.c ${TXT2LAS}.c)
-    add_executable(${TXT2LAS} ${TXT2LAS_SRC})
-    target_link_libraries(${TXT2LAS} ${LIBLAS_C_LIB_NAME})
-endif()
-
-# Build las2col
-if(LAS2COL)
-    set(LAS2COL_SRC lascommon.c ${LAS2COL}.c)
-    add_executable(${LAS2COL} ${LAS2COL_SRC})
-    target_link_libraries(${LAS2COL} ${LIBLAS_C_LIB_NAME})
-endif()
-
-# Build las2pg
-if(LAS2PG)
-    set(LAS2PG_SRC lascommon.c ${LAS2PG}.c)
-    add_executable(${LAS2PG} ${LAS2PG_SRC})
-    target_link_libraries(${LAS2PG} ${LIBLAS_C_LIB_NAME})
-endif()
-
-if(TS2LAS)
-    add_executable(${TS2LAS} ts2las.cpp laskernel.cpp)
-    target_link_libraries(${TS2LAS} ${APPS_CPP_DEPENDENCIES} )
-endif()
-
-# Build lasblock
-if(LASBLOCK)
-    set(LASBLOCK_SRC lasblock.cpp laskernel.cpp)
-    add_executable(${LASBLOCK} ${LASBLOCK_SRC})
-    target_link_libraries(${LASBLOCK} ${APPS_CPP_DEPENDENCIES} )
-endif()
-
-# Build las2ogr
-if(LAS2OGR)
-    add_executable(${LAS2OGR} las2ogr.cpp)
-    target_link_libraries(${LAS2OGR} ${APPS_CPP_DEPENDENCIES})
-endif()
-
-
-if(BIGFILE_TEST)
-    add_executable(${BIGFILE_TEST} bigtest.c)
-    target_link_libraries(${BIGFILE_TEST} ${LIBLAS_C_LIB_NAME})
-endif()
-
-if (LASINDEX_TEST)
-    add_executable(${LASINDEX_TEST} lasindex_test.cpp)
-    target_link_libraries(${LASINDEX_TEST} ${APPS_CPP_DEPENDENCIES})
-endif()
-
-if(BIGFILE_BIO_TEST)
-    add_executable(${BIGFILE_BIO_TEST} bigfile_boost_iostreams_test.cpp)
-    target_link_libraries(${BIGFILE_BIO_TEST} ${APPS_CPP_DEPENDENCIES} )
-endif()
-
-###############################################################################
-# Targets installation
-
-install(TARGETS ${LIBLAS_UTILITIES}
-    RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
-    LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
-    ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
-
-
-if(UNIX)
-
-  set(LIBLAS_UTILS_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${Boost_LIBRARY_DIRS})
-  if(LASZIP_FOUND)
-    get_filename_component(LASZIP_LIBRARY_DIRS ${LASZIP_LIBRARY} PATH)
-    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${LASZIP_LIBRARY_DIRS})
-  endif()
-  if(GEOTIFF_FOUND)
-    get_filename_component(GEOTIFF_LIBRARY_DIRS ${GEOTIFF_LIBRARY} PATH)
-    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GEOTIFF_LIBRARY_DIRS})
-  endif()
-  if(GDAL_FOUND)
-    get_filename_component(GDAL_LIBRARY_DIRS ${GDAL_LIBRARY} PATH)
-    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GDAL_LIBRARY_DIRS})
-  endif()
-  set_target_properties(${LIBLAS_UTILITIES} PROPERTIES
-    INSTALL_RPATH "${LIBLAS_UTILS_RPATH}")
-
-  if(WITH_PKGCONFIG)
-
-    set(PKGCFG_PREFIX "${CMAKE_INSTALL_PREFIX}")
-    set(PKGCFG_INC_DIR "${LIBLAS_INCLUDE_SUBDIR}")
-    set(PKGCFG_LIB_DIR "${LIBLAS_LIB_SUBDIR}")
-    set(PKGCFG_REQUIRES  "")
-    set(PKGCFG_VERSION ${VERSION})
-    set(PKGCFG_LINK_FLAGS "-llas -llas_c")
-    set(PKGCFG_COMPILE_FLAGS "")
-    if(LIBXML2_FOUND)
-      set(PKGCFG_REQUIRES "${PKGCFG_REQUIRES} libxml-2.0")
-    endif()
-    if(GEOTIFF_FOUND)
-      set(PKGCFG_REQUIRES "${PKGCFG_REQUIRES} geotiff")
-    endif()
-    #  if(WITH_GDAL)
-    #    set(PKGCFG_INC_DIR "${PKGCFG_INC_DIR} ${GDAL_INCLUDE_DIR}")
-    #  endif()
-    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/liblas.pc.in
-      ${CMAKE_CURRENT_BINARY_DIR}/liblas.pc @ONLY)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblas.pc
-      DESTINATION ${LIBLAS_LIB_DIR}/pkgconfig
-      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
-
-  else()
-
-    # Autoconf compatibility variables to use the same script source.
-    set(prefix ${CMAKE_INSTALL_PREFIX})
-    set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
-    set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
-
-    GET_DIRECTORY_PROPERTY(LIBLAS_DEFINITIONS DIRECTORY ${libLAS_SOURCE_DIR}/ COMPILE_DEFINITIONS)
-
-    set(LIBLAS_CONFIG_DEFINITIONS "")
-    foreach(definition ${LIBLAS_DEFINITIONS})
-        set(LIBLAS_CONFIG_DEFINITIONS "${LIBLAS_CONFIG_DEFINITIONS} -D${definition}")
-    endforeach()
-
-
-    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/liblas-config.in
-      ${CMAKE_CURRENT_BINARY_DIR}/liblas-config @ONLY)
-
-    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/liblas-config
-      DESTINATION bin)
-
-  endif()
-
-endif()
+###############################################################################
+#
+# apps/CMakeLists.txt controls building of libLAS utilities
+#
+# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
+#
+###############################################################################
+
+include_directories(
+    .
+    ../include
+    ../include/liblas/capi)
+
+###############################################################################
+# Collect programs to build
+
+set(LASINFO lasinfo)
+set(LAS2LAS las2las)
+set(LAS2TXT las2txt)
+set(TXT2LAS txt2las)
+set(TS2LAS ts2las)
+set(LASBLOCK lasblock )
+
+if (NOT WIN32)
+    set(LAS2COL las2col )
+    set(LAS2PG las2pg )
+endif()
+
+set(BIGFILE_TEST bigfile_test)
+set(LASINDEX_TEST lasindex_test)
+
+if(Boost_IOSTREAMS_FOUND)
+  set(BIGFILE_BIO_TEST bigfile_boost_iostreams_test)
+endif()
+
+# Set the build type to release if it is not explicitly set by the user and
+# isn't in the cache yet
+if (NOT CMAKE_BUILD_TYPE )
+  set(CMAKE_BUILD_TYPE "Release")
+endif()
+
+# Utilities depending on 3rd-pary libraries
+if(GDAL_FOUND)
+    set(LAS2OGR las2ogr)
+endif()
+
+
+set(LIBLAS_UTILITIES
+    ${LASINFO} ${LAS2LAS} ${TXT2LAS}  ${LAS2COL}  ${LAS2PG}
+    ${LAS2OGR} ${LAS2LAS} ${LASBLOCK} ${TS2LAS}  ${LAS2TXT})
+
+# TODO: Experimental and requires testing --mloskot
+# Generate user-specific settings for Visual Studio project
+set(VCPROJ_USER_REMOTE_MACHINE_DEBUG ${MACHINE_NAME})
+set(VCPROJ_USER_ENVIRONMENT_DEBUG "${ENVIRONMENT_PATH}")
+
+if(MSVC)
+    foreach(utility ${LIBLAS_UTILITIES})
+        set(USER_FILE ${utility}.vcproj.$ENV{USERDOMAIN}.$ENV{USERNAME}.user)
+        set(OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${USER_FILE})
+        message(STATUS "Generating ${CMAKE_GENERATOR} user-specific settings in ${USER_FILE}")
+        configure_file(${CMAKE_SOURCE_DIR}/cmake/libLAS.vcproj.user.template ${OUTPUT_PATH} @ONLY)
+    endforeach()
+endif()
+
+###############################################################################
+# Configure build targets
+
+if(WIN32)
+    add_definitions("-DLAS_DLL_EXPORT=1")
+endif()
+
+
+set(APPS_CPP_DEPENDENCIES
+    ${LIBLAS_LIB_NAME}
+)
+
+# link_directories(${Boost_LIBRARY_DIRS})
+
+#    add_executable(lasschematest lasschematest.cpp laskernel.cpp)
+#    target_link_libraries(lasschematest ${APPS_CPP_DEPENDENCIES} ${LIBXML2_LIBRARIES})
+
+
+if(LAS2LAS)
+    add_executable(${LAS2LAS} las2las.cpp laskernel.cpp)
+    target_link_libraries(${LAS2LAS} ${APPS_CPP_DEPENDENCIES} )
+endif()
+
+if(LASINFO)
+    add_executable(${LASINFO} lasinfo.cpp laskernel.cpp )
+    target_link_libraries(${LASINFO} ${APPS_CPP_DEPENDENCIES}  )
+endif()
+
+if(LAS2TXT)
+    add_executable( ${LAS2TXT}  las2txt.cpp laskernel.cpp )
+    target_link_libraries(${LAS2TXT} ${APPS_CPP_DEPENDENCIES}  )
+endif()
+
+# Build txt2las
+if(TXT2LAS)
+    set(TXT2LAS_SRC lascommon.c ${TXT2LAS}.c)
+    add_executable(${TXT2LAS} ${TXT2LAS_SRC})
+    target_link_libraries(${TXT2LAS} ${LIBLAS_C_LIB_NAME})
+endif()
+
+# Build las2col
+if(LAS2COL)
+    set(LAS2COL_SRC lascommon.c ${LAS2COL}.c)
+    add_executable(${LAS2COL} ${LAS2COL_SRC})
+    target_link_libraries(${LAS2COL} ${LIBLAS_C_LIB_NAME})
+endif()
+
+# Build las2pg
+if(LAS2PG)
+    set(LAS2PG_SRC lascommon.c ${LAS2PG}.c)
+    add_executable(${LAS2PG} ${LAS2PG_SRC})
+    target_link_libraries(${LAS2PG} ${LIBLAS_C_LIB_NAME})
+endif()
+
+if(TS2LAS)
+    add_executable(${TS2LAS} ts2las.cpp laskernel.cpp)
+    target_link_libraries(${TS2LAS} ${APPS_CPP_DEPENDENCIES} )
+endif()
+
+# Build lasblock
+if(LASBLOCK)
+    set(LASBLOCK_SRC lasblock.cpp laskernel.cpp)
+    add_executable(${LASBLOCK} ${LASBLOCK_SRC})
+    target_link_libraries(${LASBLOCK} ${APPS_CPP_DEPENDENCIES} )
+endif()
+
+# Build las2ogr
+if(LAS2OGR)
+    add_executable(${LAS2OGR} las2ogr.cpp)
+    target_link_libraries(${LAS2OGR} ${APPS_CPP_DEPENDENCIES})
+endif()
+
+
+if(BIGFILE_TEST)
+    add_executable(${BIGFILE_TEST} bigtest.c)
+    target_link_libraries(${BIGFILE_TEST} ${LIBLAS_C_LIB_NAME})
+endif()
+
+if (LASINDEX_TEST)
+    add_executable(${LASINDEX_TEST} lasindex_test.cpp)
+    target_link_libraries(${LASINDEX_TEST} ${APPS_CPP_DEPENDENCIES})
+endif()
+
+if(BIGFILE_BIO_TEST)
+    add_executable(${BIGFILE_BIO_TEST} bigfile_boost_iostreams_test.cpp)
+    target_link_libraries(${BIGFILE_BIO_TEST} ${APPS_CPP_DEPENDENCIES} )
+endif()
+
+###############################################################################
+# Targets installation
+
+install(TARGETS ${LIBLAS_UTILITIES}
+    RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
+    LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
+    ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
+
+
+if(UNIX)
+
+  set(LIBLAS_UTILS_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${Boost_LIBRARY_DIRS})
+  if(LASZIP_FOUND)
+    get_filename_component(LASZIP_LIBRARY_DIRS ${LASZIP_LIBRARY} PATH)
+    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${LASZIP_LIBRARY_DIRS})
+  endif()
+  if(GEOTIFF_FOUND)
+    get_filename_component(GEOTIFF_LIBRARY_DIRS ${GEOTIFF_LIBRARY} PATH)
+    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GEOTIFF_LIBRARY_DIRS})
+  endif()
+  if(GDAL_FOUND)
+    get_filename_component(GDAL_LIBRARY_DIRS ${GDAL_LIBRARY} PATH)
+    set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GDAL_LIBRARY_DIRS})
+  endif()
+  set_target_properties(${LIBLAS_UTILITIES} PROPERTIES
+    INSTALL_RPATH "${LIBLAS_UTILS_RPATH}")
+
+  if(WITH_PKGCONFIG)
+
+    set(PKGCFG_PREFIX "${CMAKE_INSTALL_PREFIX}")
+    set(PKGCFG_INC_DIR "${LIBLAS_INCLUDE_SUBDIR}")
+    set(PKGCFG_LIB_DIR "${LIBLAS_LIB_SUBDIR}")
+    set(PKGCFG_REQUIRES  "")
+    set(PKGCFG_VERSION ${VERSION})
+    set(PKGCFG_LINK_FLAGS "-llas -llas_c")
+    set(PKGCFG_COMPILE_FLAGS "")
+    if(LIBXML2_FOUND)
+      set(PKGCFG_REQUIRES "${PKGCFG_REQUIRES} libxml-2.0")
+    endif()
+    if(GEOTIFF_FOUND)
+      set(PKGCFG_REQUIRES "${PKGCFG_REQUIRES} geotiff")
+    endif()
+    #  if(WITH_GDAL)
+    #    set(PKGCFG_INC_DIR "${PKGCFG_INC_DIR} ${GDAL_INCLUDE_DIR}")
+    #  endif()
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/liblas.pc.in
+      ${CMAKE_CURRENT_BINARY_DIR}/liblas.pc @ONLY)
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblas.pc
+      DESTINATION ${LIBLAS_LIB_DIR}/pkgconfig
+      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+
+  else()
+
+    # Autoconf compatibility variables to use the same script source.
+    set(prefix ${CMAKE_INSTALL_PREFIX})
+    set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
+    set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
+
+    GET_DIRECTORY_PROPERTY(LIBLAS_DEFINITIONS DIRECTORY ${libLAS_SOURCE_DIR}/ COMPILE_DEFINITIONS)
+
+    set(LIBLAS_CONFIG_DEFINITIONS "")
+    foreach(definition ${LIBLAS_DEFINITIONS})
+        set(LIBLAS_CONFIG_DEFINITIONS "${LIBLAS_CONFIG_DEFINITIONS} -D${definition}")
+    endforeach()
+
+
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/liblas-config.in
+      ${CMAKE_CURRENT_BINARY_DIR}/liblas-config @ONLY)
+
+    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/liblas-config
+      DESTINATION bin)
+
+  endif()
+
+endif()
diff --git a/apps/las2col.c b/apps/las2col.c
index 4579f25..ff4c99f 100644
--- a/apps/las2col.c
+++ b/apps/las2col.c
@@ -24,7 +24,7 @@
 
 #include <limits.h>
 #include <inttypes.h>
-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
 
 #include <endian.h>
 #include <unistd.h>
@@ -160,18 +160,18 @@ void usage()
     fprintf(stderr,"----------------------------------------------------------\n");
     fprintf(stderr,"\n");
 
-    fprintf(stderr,"Convert a las/laz file into columnar format (binary) of MonetDB, outputs for each entry a file <ouput_prefix>_col_<entry_name>.dat:\n");
-    fprintf(stderr,"  las2col -i <input_file> -o <ouput_prefix>\n");
+    fprintf(stderr,"Convert a las/laz file into columnar format (binary) of MonetDB, outputs for each entry a file <output_prefix>_col_<entry_name>.dat:\n");
+    fprintf(stderr,"  las2col -i <input_file> -o <output_prefix>\n");
     fprintf(stderr,"\n");
 
-    fprintf(stderr,"Convert a list of las/laz files (still outputs for each entry a file <ouput_prefix>_col_<entry_name>.dat):\n");
-    fprintf(stderr,"  las2col -i <las_file_1> -i <las_file_2> -o <ouput_prefix>\n");
+    fprintf(stderr,"Convert a list of las/laz files (still outputs for each entry a file <output_prefix>_col_<entry_name>.dat):\n");
+    fprintf(stderr,"  las2col -i <las_file_1> -i <las_file_2> -o <output_prefix>\n");
     fprintf(stderr,"Alternatively:\n");
-    fprintf(stderr,"  las2col -f <file_with_the_list_las/laz_files> -o <ouput_prefix>\n");
+    fprintf(stderr,"  las2col -f <file_with_the_list_las/laz_files> -o <output_prefix>\n");
     fprintf(stderr,"\n");
 
     fprintf(stderr,"Convert a list of las/laz files using <num_read_threads> threads (default is 1):\n");
-    fprintf(stderr,"  las2col -f <file_with_the_list_las/laz_files> -o <ouput_prefix> --num_read_threads <number_of_threads>\n");
+    fprintf(stderr,"  las2col -f <file_with_the_list_las/laz_files> -o <output_prefix> --num_read_threads <number_of_threads>\n");
     fprintf(stderr,"\n\n");
 
     fprintf(stderr,"----------------------------------------------------------\n");
@@ -218,7 +218,7 @@ void usage()
     fprintf(stderr," After generating the columnar files, import them in MonetDB. Example: \n");
     fprintf(stderr,"   mclient <db_name> -s \"COPY BINARY INTO flat FROM ('<full_parent_path>/out_col_x.dat','<full_parent_path>/out_col_y.dat','<full_parent_path>/out_col_z.dat')\"\n");
     fprintf(stderr," Note that full paths of the columnar files MUST be used. Also note that a table called flat has to be created in a MonetDB DB beforehand. The table must have \n");
-    fprintf(stderr," the columns in the same order as specified by the --parse option, and the column types must be the ones speficied above. Example: \n");
+    fprintf(stderr," the columns in the same order as specified by the --parse option, and the column types must be the ones specified above. Example: \n");
     fprintf(stderr,"   mclient <db_name> -s \"create table flat (x double, y double, z double)\"\n");
     fprintf(stderr," Note that for decimal entries (XYZ) the column definition at table-creation time must be decimal(<num_digits_unscaled_max>,<num_digits_scale>)\n");
     fprintf(stderr," For example, if the maximum X value of a file (or a list of files) is 638982.55, then the X definition when creating the table is decimal(8,2). Example:\n");
diff --git a/apps/las2las.cpp b/apps/las2las.cpp
index 4b4f2e6..7bb2d1f 100644
--- a/apps/las2las.cpp
+++ b/apps/las2las.cpp
@@ -342,7 +342,7 @@ int main(int argc, char* argv[])
         if (vm.count("min-offset")) 
         {
             if (vm.count("offset")) {
-                throw std::runtime_error("min-offset cannot be used with offets.  Use one or the other");
+                throw std::runtime_error("min-offset cannot be used with offset.  Use one or the other");
             }
             
             bMinOffset = true;
diff --git a/apps/las2pg.c b/apps/las2pg.c
index 05bbd20..a6142bd 100644
--- a/apps/las2pg.c
+++ b/apps/las2pg.c
@@ -20,105 +20,105 @@
 #include <stdint.h>
 #include <limits.h>
 #include <inttypes.h>
-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
 
-#	include <endian.h>
+#   include <endian.h>
 
 #elif defined(__APPLE__)
 
-#	include <libkern/OSByteOrder.h>
+#   include <libkern/OSByteOrder.h>
 
-#	define htobe16(x) OSSwapHostToBigInt16(x)
-#	define htole16(x) OSSwapHostToLittleInt16(x)
-#	define be16toh(x) OSSwapBigToHostInt16(x)
-#	define le16toh(x) OSSwapLittleToHostInt16(x)
+#   define htobe16(x) OSSwapHostToBigInt16(x)
+#   define htole16(x) OSSwapHostToLittleInt16(x)
+#   define be16toh(x) OSSwapBigToHostInt16(x)
+#   define le16toh(x) OSSwapLittleToHostInt16(x)
 
-#	define htobe32(x) OSSwapHostToBigInt32(x)
-#	define htole32(x) OSSwapHostToLittleInt32(x)
-#	define be32toh(x) OSSwapBigToHostInt32(x)
-#	define le32toh(x) OSSwapLittleToHostInt32(x)
+#   define htobe32(x) OSSwapHostToBigInt32(x)
+#   define htole32(x) OSSwapHostToLittleInt32(x)
+#   define be32toh(x) OSSwapBigToHostInt32(x)
+#   define le32toh(x) OSSwapLittleToHostInt32(x)
 
-#	define htobe64(x) OSSwapHostToBigInt64(x)
-#	define htole64(x) OSSwapHostToLittleInt64(x)
-#	define be64toh(x) OSSwapBigToHostInt64(x)
-#	define le64toh(x) OSSwapLittleToHostInt64(x)
+#   define htobe64(x) OSSwapHostToBigInt64(x)
+#   define htole64(x) OSSwapHostToLittleInt64(x)
+#   define be64toh(x) OSSwapBigToHostInt64(x)
+#   define le64toh(x) OSSwapLittleToHostInt64(x)
 
-#	define __BYTE_ORDER    BYTE_ORDER
-#	define __BIG_ENDIAN    BIG_ENDIAN
-#	define __LITTLE_ENDIAN LITTLE_ENDIAN
-#	define __PDP_ENDIAN    PDP_ENDIAN
+#   define __BYTE_ORDER    BYTE_ORDER
+#   define __BIG_ENDIAN    BIG_ENDIAN
+#   define __LITTLE_ENDIAN LITTLE_ENDIAN
+#   define __PDP_ENDIAN    PDP_ENDIAN
 
 #elif defined(__OpenBSD__)
 
-#	include <sys/endian.h>
+#   include <sys/endian.h>
 
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
 
-#	include <sys/endian.h>
+#   include <sys/endian.h>
 
-#	define be16toh(x) betoh16(x)
-#	define le16toh(x) letoh16(x)
+#   define be16toh(x) betoh16(x)
+#   define le16toh(x) letoh16(x)
 
-#	define be32toh(x) betoh32(x)
-#	define le32toh(x) letoh32(x)
+#   define be32toh(x) betoh32(x)
+#   define le32toh(x) letoh32(x)
 
-#	define be64toh(x) betoh64(x)
-#	define le64toh(x) letoh64(x)
+#   define be64toh(x) betoh64(x)
+#   define le64toh(x) letoh64(x)
 
 #elif defined(__WINDOWS__)
 
-#	include <winsock2.h>
-#	include <sys/param.h>
+#   include <winsock2.h>
+#   include <sys/param.h>
 
-#	if BYTE_ORDER == LITTLE_ENDIAN
+#   if BYTE_ORDER == LITTLE_ENDIAN
 
-#		define htobe16(x) htons(x)
-#		define htole16(x) (x)
-#		define be16toh(x) ntohs(x)
-#		define le16toh(x) (x)
+#       define htobe16(x) htons(x)
+#       define htole16(x) (x)
+#       define be16toh(x) ntohs(x)
+#       define le16toh(x) (x)
 
-#		define htobe32(x) htonl(x)
-#		define htole32(x) (x)
-#		define be32toh(x) ntohl(x)
-#		define le32toh(x) (x)
+#       define htobe32(x) htonl(x)
+#       define htole32(x) (x)
+#       define be32toh(x) ntohl(x)
+#       define le32toh(x) (x)
 
-#		define htobe64(x) htonll(x)
-#		define htole64(x) (x)
-#		define be64toh(x) ntohll(x)
-#		define le64toh(x) (x)
+#       define htobe64(x) htonll(x)
+#       define htole64(x) (x)
+#       define be64toh(x) ntohll(x)
+#       define le64toh(x) (x)
 
-#	elif BYTE_ORDER == BIG_ENDIAN
+#   elif BYTE_ORDER == BIG_ENDIAN
 
-		/* that would be xbox 360 */
-#		define htobe16(x) (x)
-#		define htole16(x) __builtin_bswap16(x)
-#		define be16toh(x) (x)
-#		define le16toh(x) __builtin_bswap16(x)
+        /* that would be xbox 360 */
+#       define htobe16(x) (x)
+#       define htole16(x) __builtin_bswap16(x)
+#       define be16toh(x) (x)
+#       define le16toh(x) __builtin_bswap16(x)
 
-#		define htobe32(x) (x)
-#		define htole32(x) __builtin_bswap32(x)
-#		define be32toh(x) (x)
-#		define le32toh(x) __builtin_bswap32(x)
+#       define htobe32(x) (x)
+#       define htole32(x) __builtin_bswap32(x)
+#       define be32toh(x) (x)
+#       define le32toh(x) __builtin_bswap32(x)
 
-#		define htobe64(x) (x)
-#		define htole64(x) __builtin_bswap64(x)
-#		define be64toh(x) (x)
-#		define le64toh(x) __builtin_bswap64(x)
+#       define htobe64(x) (x)
+#       define htole64(x) __builtin_bswap64(x)
+#       define be64toh(x) (x)
+#       define le64toh(x) __builtin_bswap64(x)
 
-#	else
+#   else
 
-#		error byte order not supported
+#       error byte order not supported
 
-#	endif
+#   endif
 
-#	define __BYTE_ORDER    BYTE_ORDER
-#	define __BIG_ENDIAN    BIG_ENDIAN
-#	define __LITTLE_ENDIAN LITTLE_ENDIAN
-#	define __PDP_ENDIAN    PDP_ENDIAN
+#   define __BYTE_ORDER    BYTE_ORDER
+#   define __BIG_ENDIAN    BIG_ENDIAN
+#   define __LITTLE_ENDIAN LITTLE_ENDIAN
+#   define __PDP_ENDIAN    PDP_ENDIAN
 
 #else
 
-#	error platform not supported
+#   error platform not supported
 
 #endif
 
@@ -166,7 +166,7 @@ void usage()
     fprintf(stderr,"  las2pg -i <input_file>.las\n");
     fprintf(stderr,"\n");
 
-    fprintf(stderr,"Convert a las/laz file into PostgreSQL binary dump format, outputs <ouput_name>:\n");
+    fprintf(stderr,"Convert a las/laz file into PostgreSQL binary dump format, outputs <output_name>:\n");
     fprintf(stderr,"  las2pg -i <input_file>.las -o <output_name>\n");
     fprintf(stderr,"Use flag --stdout to write to standard output (recommended use together with a pipe, see below).\n");
     fprintf(stderr,"\n\n");
@@ -198,7 +198,7 @@ void usage()
     fprintf(stderr,"   M - vertex index number as integer\n");
     fprintf(stderr,"   k - Morton 2D code using X and Y (unscaled and no offset) as bigint\n\n");
 
-    fprintf(stderr," The moffset flag (for example '--moffset 8600000,40000000') specifies a global offset to substract to X and Y \n");
+    fprintf(stderr," The moffset flag (for example '--moffset 8600000,40000000') specifies a global offset to subtract to X and Y \n");
     fprintf(stderr," to be used when computing the Morton 2D code. Values must be unscaled \n\n");
 
     fprintf(stderr," The check flag (for example '--check 0.01,0.01') checks suitability to compute Morton 2D codes \n");
@@ -211,7 +211,7 @@ void usage()
     fprintf(stderr," The intended use of this tool is by using the --stdout flag and a pipe to avoid storing intermediate files. Example: \n");
     fprintf(stderr,"    las2pg 1.2-with-color.laz --parse xyzRGBi --stdout | psql -c \"copy flat from stdin with binary\" \n");
     fprintf(stderr," This obviously require a table called flat to be created in a PostgreSQL DB beforehand. The table must have \n");
-    fprintf(stderr," the columns in the same order as specified by the --parse option, and the column types must be the ones speficied above. Example: \n");
+    fprintf(stderr," the columns in the same order as specified by the --parse option, and the column types must be the ones specified above. Example: \n");
     fprintf(stderr,"    psql -c \"create table flat (x double precision, y double precision, z double precision, r integer, g integer, b integer, i integer)\" \n\n");
 }
 
@@ -331,24 +331,24 @@ int main(int argc, char *argv[])
                 )
         {
             i++;
-		    buffer = strtok (argv[i], ",");
-		    j = 0;
-		    while (buffer) {
-		        if (j == 0) {
-		            global_offset_x = S64(buffer);
-		        }
-		        else if (j == 1) {
-		            global_offset_y = S64(buffer);
-		        }
-		        j++;
-		        buffer = strtok (NULL, ",");
-		        while (buffer && *buffer == '\040')
-		            buffer++;
-		    }
-		    if (j != 2){
-		    	fprintf(stderr, "Only two int64_t are required in moffset option!\n");
-		        exit(1);
-		    }
+            buffer = strtok (argv[i], ",");
+            j = 0;
+            while (buffer) {
+                if (j == 0) {
+                    global_offset_x = S64(buffer);
+                }
+                else if (j == 1) {
+                    global_offset_y = S64(buffer);
+                }
+                j++;
+                buffer = strtok (NULL, ",");
+                while (buffer && *buffer == '\040')
+                    buffer++;
+            }
+            if (j != 2){
+                fprintf(stderr, "Only two int64_t are required in moffset option!\n");
+                exit(1);
+            }
 
         }
         else if (   strcmp(argv[i], "--check") == 0 ||
@@ -357,24 +357,24 @@ int main(int argc, char *argv[])
         {
             i++;
             check = TRUE;
-		    buffer = strtok (argv[i], ",");
-		    j = 0;
-		    while (buffer) {
-		        if (j == 0) {
-		            sscanf(buffer, "%lf", &scale_x);
-		        }
-		        else if (j == 1) {
-		            sscanf(buffer, "%lf", &scale_y);
-		        }
-		        j++;
-		        buffer = strtok (NULL, ",");
-		        while (buffer && *buffer == '\040')
-		            buffer++;
-		    }
-		    if (j != 2){
-		    	fprintf(stderr, "Only two doubles are required in moffset option!\n");
-		        exit(1);
-		    }
+            buffer = strtok (argv[i], ",");
+            j = 0;
+            while (buffer) {
+                if (j == 0) {
+                    sscanf(buffer, "%lf", &scale_x);
+                }
+                else if (j == 1) {
+                    sscanf(buffer, "%lf", &scale_y);
+                }
+                j++;
+                buffer = strtok (NULL, ",");
+                while (buffer && *buffer == '\040')
+                    buffer++;
+            }
+            if (j != 2){
+                fprintf(stderr, "Only two doubles are required in moffset option!\n");
+                exit(1);
+            }
         }
         else if (   strcmp(argv[i], "--stdout") == 0
                 )
@@ -417,7 +417,7 @@ int main(int argc, char *argv[])
     num_entries = strlen(parse_string);
 
     if (use_stdout == TRUE && file_name_out){
-      LASError_Print("If an ouput file is specified, --stdout must not be used!");
+      LASError_Print("If an output file is specified, --stdout must not be used!");
       exit(1);
     }
 
@@ -481,37 +481,37 @@ int main(int argc, char *argv[])
 
     if (check)
     {
-    	// Check specified scales are like in the LAS file
-    	if (fabs(scale_x - file_scale_x) > TOLERANCE){
-	    fprintf(stderr, "ERROR: x scale in input file (%lf) does not match specified x scale (%lf)\n",file_scale_x, scale_x);
+        // Check specified scales are like in the LAS file
+        if (fabs(scale_x - file_scale_x) > TOLERANCE){
+        fprintf(stderr, "ERROR: x scale in input file (%lf) does not match specified x scale (%lf)\n",file_scale_x, scale_x);
             exit(1);
-    	}
-    	if (fabs(scale_y - file_scale_y) > TOLERANCE){
-    	    fprintf(stderr, "ERROR: y scale in input file (%lf) does not match specified y scale (%lf)\n",file_scale_y, scale_y);
+        }
+        if (fabs(scale_y - file_scale_y) > TOLERANCE){
+            fprintf(stderr, "ERROR: y scale in input file (%lf) does not match specified y scale (%lf)\n",file_scale_y, scale_y);
             exit(1);
-    	}
-    	/* Check that the extent of the file (taking into account the global offset)
-    	 * is within 0,2^31 */
+        }
+        /* Check that the extent of the file (taking into account the global offset)
+         * is within 0,2^31 */
         double check_min_x = 1.0 + LASHeader_GetMinX(header) - (((double) global_offset_x) * scale_x);
-    	if (check_min_x < TOLERANCE) {
-    	    fprintf(stderr, "ERROR: Specied X global offset is too large. (MinX - (GlobalX*ScaleX)) < 0\n");
+        if (check_min_x < TOLERANCE) {
+            fprintf(stderr, "ERROR: Specied X global offset is too large. (MinX - (GlobalX*ScaleX)) < 0\n");
             exit(1);
-    	}
+        }
         double check_min_y = 1.0 + LASHeader_GetMinY(header) - (((double) global_offset_y) * scale_y);
-    	if (check_min_y < TOLERANCE) {
+        if (check_min_y < TOLERANCE) {
             fprintf(stderr, "ERROR: Specied Y global offset is too large. (MinY - (GlobalY*ScaleY)) < 0\n");
             exit(1);
-    	}
+        }
         double check_max_x = LASHeader_GetMaxX(header) - (((double) global_offset_x) * scale_x);
-    	if (check_max_x > (MAX_INT_31 * scale_x)) {
-    		fprintf(stderr, "ERROR: Specied X global offset is too small. (MaxX - (GlobalX*ScaleX)) > (2^31)*ScaleX\n");
+        if (check_max_x > (MAX_INT_31 * scale_x)) {
+            fprintf(stderr, "ERROR: Specied X global offset is too small. (MaxX - (GlobalX*ScaleX)) > (2^31)*ScaleX\n");
             exit(1);
-    	}
+        }
         double check_max_y = LASHeader_GetMaxY(header) - (((double) global_offset_y) * scale_y);
-    	if (check_max_y > (MAX_INT_31 * scale_y)) {
-    		fprintf(stderr, "ERROR: Specied Y global offset is too small. (MaxY - (GlobalY*ScaleY)) > (2^31)*ScaleY\n");
+        if (check_max_y > (MAX_INT_31 * scale_y)) {
+            fprintf(stderr, "ERROR: Specied Y global offset is too small. (MaxY - (GlobalY*ScaleY)) > (2^31)*ScaleY\n");
             exit(1);
-    	}
+        }
     }
 
 
diff --git a/apps/laskernel.cpp b/apps/laskernel.cpp
index f6c655f..d45d868 100644
--- a/apps/laskernel.cpp
+++ b/apps/laskernel.cpp
@@ -4,13 +4,13 @@ bool OptechScanAngleFixer::transform(liblas::Point& p)
 {
     boost::int8_t angle = p.GetScanAngleRank();
     double a = static_cast<double>(angle);
-    
+
     double da = 1.944445 * a;
-    
+
     double rda = liblas::detail::sround(da);
-    
+
     boost::int32_t new_a = static_cast<boost::int32_t>(rda);
-    
+
     boost::int8_t output = 0;
     if (new_a > (std::numeric_limits<boost::int8_t>::max)())
     {
@@ -24,13 +24,13 @@ bool OptechScanAngleFixer::transform(liblas::Point& p)
     {
         output = static_cast<boost::int8_t>(new_a);
     }
-    
+
     p.SetScanAngleRank(output);
     return true;
-    
+
 }
 
-std::istream* OpenInput(std::string const& filename, bool bEnd) 
+std::istream* OpenInput(std::string const& filename, bool bEnd)
 {
     std::ios::openmode mode = std::ios::in | std::ios::binary;
     if (bEnd == true) {
@@ -41,11 +41,11 @@ std::istream* OpenInput(std::string const& filename, bool bEnd)
     {
         istrm = &std::cin;
     }
-    else 
+    else
     {
         istrm = new std::ifstream(filename.c_str(), mode);
     }
-    
+
     if (!istrm->good())
     {
         delete istrm;
@@ -79,9 +79,9 @@ std::vector<char> TryReadRawFileData(std::string const& filename)
         // delete[] data;
         delete infile;
         return data;
-    } 
-    else 
-    {   
+    }
+    else
+    {
         delete infile;
         return data;
     }
@@ -94,7 +94,7 @@ bool term_progress(std::ostream& os, double complete)
 
     tick = (std::min)(40, (std::max)(0, tick));
 
-    // Have we started a new progress run?  
+    // Have we started a new progress run?
     if (tick < lastTick && lastTick >= 39)
         lastTick = -1;
 
@@ -127,12 +127,12 @@ void SetStreamPrecision(std::ostream& os, double scale)
     frac = std::modf(scale, &integer);
 
     boost::uint32_t prec = static_cast<boost::uint32_t>(std::fabs(std::floor(std::log10(frac))));
-    os.precision(prec);    
+    os.precision(prec);
 }
 
 void SetHeaderCompression(liblas::Header& header, std::string const& filename)
 {
-    
+
        // our policy for determining the output format is this:
         //   if -compressed given, use LAZ
         //   else if we see .las or .laz, use LAS or LAZ (resp.)
@@ -167,12 +167,12 @@ void SetHeaderCompression(liblas::Header& header, std::string const& filename)
             throw liblas::liblas_error("Unknown output file type");
             break;
         }
-        
+
 }
 
 liblas::Header FetchHeader(std::string const& filename)
 {
-    
+
     std::ifstream ifs;
     if (!liblas::Open(ifs, filename.c_str()))
     {
@@ -198,8 +198,8 @@ void RewriteHeader(liblas::Header const& header, std::string const& filename)
     }
     ofs.close();
 
-}  
-  
+}
+
 void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& header)
 {
 
@@ -209,18 +209,18 @@ void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& head
     }
 
     liblas::property_tree::ptree tree = summary.GetPTree();
-    
+
     try
     {
         header.SetMin(tree.get<double>("summary.points.minimum.x"),
                       tree.get<double>("summary.points.minimum.y"),
                       tree.get<double>("summary.points.minimum.z"));
-    
+
         header.SetMax(tree.get<double>("summary.points.maximum.x"),
                       tree.get<double>("summary.points.maximum.y"),
                       tree.get<double>("summary.points.maximum.z"));
-        
-    }     catch (liblas::property_tree::ptree_bad_path const& ) 
+
+    }     catch (liblas::property_tree::ptree_bad_path const& )
     {
         std::cerr << "Unable to write header bounds info.  Does the outputted file have any points?";
         return;
@@ -233,25 +233,25 @@ void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& head
         {
             header.SetPointRecordsByReturnCount(i, 0);
         }
-    
+
         BOOST_FOREACH(ptree::value_type &v,
                 tree.get_child("summary.points.points_by_return"))
         {
             boost::uint32_t i = v.second.get<boost::uint32_t>("id");
             boost::uint32_t count = v.second.get<boost::uint32_t>("count");
-            header.SetPointRecordsByReturnCount(i-1, count);        
-        } 
-        
-    }     catch (liblas::property_tree::ptree_bad_path const& ) 
+            header.SetPointRecordsByReturnCount(i-1, count);
+        }
+
+    }     catch (liblas::property_tree::ptree_bad_path const& )
     {
         std::cerr << "Unable to write header point return count info.  "
                      "Does the outputted file have any points?";
         return;
     }
-    
+
 }
 
-bool IsDualRangeFilter(std::string parse_string) 
+bool IsDualRangeFilter(std::string parse_string)
 {
 
 string::size_type dash = parse_string.find_first_of("-");
@@ -262,8 +262,8 @@ if (dash != std::string::npos) {
 return false;
 }
 
-liblas::FilterPtr MakeReturnFilter( std::vector<boost::uint16_t> const& returns, 
-                                    liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeReturnFilter( std::vector<boost::uint16_t> const& returns,
+                                    liblas::FilterI::FilterType ftype)
 {
     typedef liblas::ReturnFilter filter;
     filter* return_filter = new filter(returns, false);
@@ -271,17 +271,17 @@ liblas::FilterPtr MakeReturnFilter( std::vector<boost::uint16_t> const& returns,
     return liblas::FilterPtr(return_filter);
 }
 
-liblas::FilterPtr MakeClassFilter(std::vector<liblas::Classification> const& classes, 
-                                  liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeClassFilter(std::vector<liblas::Classification> const& classes,
+                                  liblas::FilterI::FilterType ftype)
 {
     typedef liblas::ClassificationFilter filter;
-    filter* class_filter = new filter(classes); 
+    filter* class_filter = new filter(classes);
     class_filter->SetType(ftype);
     return liblas::FilterPtr(class_filter);
 }
 
-liblas::FilterPtr MakeBoundsFilter(liblas::Bounds<double> const& bounds, 
-                                   liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeBoundsFilter(liblas::Bounds<double> const& bounds,
+                                   liblas::FilterI::FilterType ftype)
 {
     typedef liblas::BoundsFilter filter;
     filter* bounds_filter = new filter(bounds);
@@ -289,8 +289,8 @@ liblas::FilterPtr MakeBoundsFilter(liblas::Bounds<double> const& bounds,
     return liblas::FilterPtr(bounds_filter);
 }
 
-liblas::FilterPtr MakeIntensityFilter(std::string intensities, 
-                                      liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeIntensityFilter(std::string intensities,
+                                      liblas::FilterI::FilterType ftype)
 {
     typedef liblas::ContinuousValueFilter<boost::uint16_t> filter;
     filter::filter_func f = &liblas::Point::GetIntensity;
@@ -299,8 +299,8 @@ liblas::FilterPtr MakeIntensityFilter(std::string intensities,
     return liblas::FilterPtr(intensity_filter);
 }
 
-liblas::FilterPtr MakeTimeFilter(std::string times, 
-                                 liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeTimeFilter(std::string times,
+                                 liblas::FilterI::FilterType ftype)
 {
     typedef liblas::ContinuousValueFilter<double> filter;
     filter::filter_func f = &liblas::Point::GetTime;
@@ -309,8 +309,8 @@ liblas::FilterPtr MakeTimeFilter(std::string times,
     return liblas::FilterPtr(time_filter);
 }
 
-liblas::FilterPtr MakeScanAngleFilter(std::string intensities, 
-                                      liblas::FilterI::FilterType ftype) 
+liblas::FilterPtr MakeScanAngleFilter(std::string intensities,
+                                      liblas::FilterI::FilterType ftype)
 {
     typedef liblas::ContinuousValueFilter<boost::int32_t> filter;
     filter::filter_func f = &liblas::Point::GetScanAngleRank;
@@ -319,8 +319,8 @@ liblas::FilterPtr MakeScanAngleFilter(std::string intensities,
     return liblas::FilterPtr(intensity_filter);
 }
 
-liblas::FilterPtr MakeColorFilter(liblas::Color const& low, 
-                                  liblas::Color const& high, 
+liblas::FilterPtr MakeColorFilter(liblas::Color const& low,
+                                  liblas::Color const& high,
                                   liblas::FilterI::FilterType ftype)
 {
     liblas::ColorFilter* filter = new liblas::ColorFilter(low, high);
@@ -328,13 +328,13 @@ liblas::FilterPtr MakeColorFilter(liblas::Color const& low,
     return liblas::FilterPtr(filter);
 }
 
-po::options_description GetFilteringOptions() 
+po::options_description GetFilteringOptions()
 {
 
 po::options_description filtering_options("Filtering options");
 
 filtering_options.add_options()
-    ("extent,e", po::value< string >(), "Extent window that points must fall within to keep.\nUse a comma-separated or quoted, space-separated list, for example, \n -e minx, miny, maxx, maxy\n or \n -e minx, miny, minz, maxx, maxy, maxz\n -e \"minx miny minz maxx maxy maxz\"")     
+    ("extent,e", po::value< string >(), "Extent window that points must fall within to keep.\nUse a comma-separated or quoted, space-separated list, for example, \n -e minx, miny, maxx, maxy\n or \n -e minx, miny, minz, maxx, maxy, maxz\n -e \"minx miny minz maxx maxy maxz\"")
     ("minx", po::value< double >(), "Extent must be greater than or equal to minx to be kept. \n --minx 1234.0")
     ("miny", po::value< double >(), "Extent must be greater than or equal to miny to be kept. \n --miny 5678.0")
     ("minz", po::value< double >(), "Extent must be greater than or equal to minz to be kept. If maxx and maxy are set but not minz *and maxz, all z values are kept. \n --minz 0.0")
@@ -358,10 +358,10 @@ filtering_options.add_options()
     ("keep-color", po::value< string >(), "Range in which to keep colors.\nDefine colors as two 3-tuples (R,G,B-R,G,B):  \n--keep-color '0,0,0-125,125,125'")
     ("drop-color", po::value< string >(), "Range in which to drop colors.\nDefine colors as two 3-tuples (R,G,B-R,G,B):  \n--drop-color '255,255,255-65536,65536,65536'")
 ;
-return filtering_options;    
+return filtering_options;
 }
 
-po::options_description GetTransformationOptions() 
+po::options_description GetTransformationOptions()
 {
     po::options_description transform_options("Transformation options");
 
@@ -374,17 +374,17 @@ po::options_description GetTransformationOptions()
         ("color-source-scale", po::value< boost::uint32_t >(), "A number used by --color-source to scale the input R, G, B  values for the point.  For example, to scale the 8 bit color data from an input raster to 16 bit, the 8 bit data should be multiplied by 256. \n--color-source-scale 256")
 
     ;
-    
+
     return transform_options;
 }
 
-po::options_description GetHeaderOptions() 
+po::options_description GetHeaderOptions()
 {
     po::options_description transform_options("Header modification options");
 
     transform_options.add_options()
         ("a_srs", po::value< string >(), "Coordinate system to assign to input LAS file")
-        ("a_vertcs", po::value< std::vector<string> >()->multitoken(), "Override vertical coordinate system information.  Use --a_vertcs \"verticalCSType [citation [verticalDatum [verticalUnits]]]\"\nFor example: --a_vertcs 5703 \"North American Vertical Datum of 1988 (NAVD88)\" 5103 9001")   
+        ("a_vertcs", po::value< std::vector<string> >()->multitoken(), "Override vertical coordinate system information.  Use --a_vertcs \"verticalCSType [citation [verticalDatum [verticalUnits]]]\"\nFor example: --a_vertcs 5703 \"North American Vertical Datum of 1988 (NAVD88)\" 5103 9001")
         ("offset", po::value< string >(), "A comma-separated or quoted, space-separated list of offsets to set on the output file: \n--offset 0,0,0\n--offset \"1234 5678 91011\"")
         ("scale", po::value< std::vector<double> >()->multitoken(), "A list of scales to set on the output file. Scales *cannot* be negative, and should always be a negative power of 10 \n--scale 0.1 0.1 0.00001")
         ("file-format,f", po::value< string >(), "Set the LAS format of the new file (only 1.0-1.2 supported at this time): \n--file-format 1.2\n-f 1.1")
@@ -399,7 +399,7 @@ po::options_description GetHeaderOptions()
         ("generating-software", po::value<std::string>(), "Set the SoftwareID for the file. --generating-software \"liblas.org\"")
         ("fix-optech-scan-angle", po::value<bool>()->zero_tokens(), "Multiply the scan angle by 1.944445 to fix up scan angle generation output by some Optech scanners")
     ;
-    
+
     return transform_options;
 }
 std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
@@ -407,18 +407,18 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
     std::vector<liblas::FilterPtr> filters;
     liblas::Bounds<double> extent;
     bool bSetExtent = false;
-    
-    if (vm.count("keep-classes")) 
+
+    if (vm.count("keep-classes"))
     {
         std::vector<boost::uint32_t> classes = vm["keep-classes"].as< std::vector<boost::uint32_t> >();
-        
+
         std::vector<liblas::Classification> klasses;
 
         ostringstream oss;
-        
+
         for (std::vector<boost::uint32_t>::const_iterator i = classes.begin();
              i != classes.end();
-             i++) 
+             i++)
             {
                 oss << *i << " ";
                 klasses.push_back(liblas::Classification(*i, false, false, false));
@@ -428,24 +428,24 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
 
                 std::cout << "Keeping classes with the values: " << oss.str() << std::endl;
         }
-        
-            
-        liblas::FilterPtr class_filter = MakeClassFilter(  klasses, 
+
+
+        liblas::FilterPtr class_filter = MakeClassFilter(  klasses,
                                                           liblas::FilterI::eInclusion);
-        filters.push_back(class_filter); 
+        filters.push_back(class_filter);
     }
 
-    if (vm.count("drop-classes")) 
+    if (vm.count("drop-classes"))
     {
         std::vector<boost::uint32_t> classes = vm["drop-classes"].as< std::vector<boost::uint32_t> >();
 
         std::vector<liblas::Classification> klasses;
 
         ostringstream oss;
-        
+
         for (std::vector<boost::uint32_t>::const_iterator i = classes.begin();
              i != classes.end();
-             i++) 
+             i++)
             {
                 oss << *i << " ";
                 klasses.push_back(liblas::Classification(*i,false, false, false));
@@ -455,12 +455,12 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
 
                 std::cout << "Dropping classes with the values: " << oss.str() << std::endl;
         }
-        liblas::FilterPtr class_filter = MakeClassFilter(  klasses, 
+        liblas::FilterPtr class_filter = MakeClassFilter(  klasses,
                                                             liblas::FilterI::eExclusion);
         filters.push_back(class_filter);
     }
 
-    if (vm.count("keep-returns")) 
+    if (vm.count("keep-returns"))
     {
         std::vector<boost::uint16_t> returns = vm["keep-returns"].as< std::vector<boost::uint16_t> >();
 
@@ -470,19 +470,19 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             ostringstream oss;
             for (std::vector<boost::uint16_t>::const_iterator i = returns.begin();
                  i != returns.end();
-                 i++) 
+                 i++)
                 {
                     oss << *i << " ";
                 }
                 std::cout << "Keeping returns with the values: " << oss.str() << std::endl;
         }
 
-        liblas::FilterPtr return_filter = MakeReturnFilter(  returns, 
+        liblas::FilterPtr return_filter = MakeReturnFilter(  returns,
                                                             liblas::FilterI::eInclusion);
-        filters.push_back(return_filter); 
+        filters.push_back(return_filter);
     }
 
-    if (vm.count("drop-returns")) 
+    if (vm.count("drop-returns"))
     {
         std::vector<boost::uint16_t> returns = vm["keep-returns"].as< std::vector<boost::uint16_t> >();
 
@@ -491,19 +491,19 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             ostringstream oss;
             for (std::vector<boost::uint16_t>::const_iterator i = returns.begin();
                  i != returns.end();
-                 i++) 
+                 i++)
                 {
                     oss << *i << " ";
                 }
                 std::cout << "Dropping returns with the values: " << oss.str() << std::endl;
         }
 
-        liblas::FilterPtr return_filter = MakeReturnFilter(  returns, 
+        liblas::FilterPtr return_filter = MakeReturnFilter(  returns,
                                                             liblas::FilterI::eExclusion);
-        filters.push_back(return_filter); 
+        filters.push_back(return_filter);
     }
 
-    if (vm.count("minx")) 
+    if (vm.count("minx"))
     {
         double minx = vm["minx"].as< double >();
         (extent.min)(0, minx);
@@ -512,7 +512,7 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             std::cout << "Setting minx to: " << minx << std::endl;
     }
 
-    if (vm.count("maxx")) 
+    if (vm.count("maxx"))
     {
         double maxx = vm["maxx"].as< double >();
         (extent.max)(0, maxx);
@@ -521,7 +521,7 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             std::cout << "Setting maxx to: " << maxx << std::endl;
     }
 
-    if (vm.count("miny")) 
+    if (vm.count("miny"))
     {
         double miny = vm["miny"].as< double >();
         (extent.min)(1, miny);
@@ -530,7 +530,7 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             std::cout << "Setting miny to: " << miny << std::endl;
     }
 
-    if (vm.count("maxy")) 
+    if (vm.count("maxy"))
     {
         double maxy = vm["maxy"].as< double >();
         (extent.max)(1, maxy);
@@ -539,7 +539,7 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             std::cout << "Setting maxy to: " << maxy << std::endl;
     }
 
-    if (vm.count("minz")) 
+    if (vm.count("minz"))
     {
         double minz = vm["minz"].as< double >();
         (extent.min)(2, minz);
@@ -548,7 +548,7 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             std::cout << "Setting minz to: " << minz << std::endl;
     }
 
-    if (vm.count("maxz")) 
+    if (vm.count("maxz"))
     {
         double maxz = vm["maxz"].as< double >();
         (extent.max)(2, maxz);
@@ -556,8 +556,8 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
         if (verbose)
             std::cout << "Setting maxz to: " << maxz << std::endl;
     }
-    
-    if (vm.count("extent")) 
+
+    if (vm.count("extent"))
     {
         std::string bounds_string = vm["extent"].as< string >();
 
@@ -569,19 +569,19 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
         for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) {
             vbounds.push_back(atof((*t).c_str()));
         }
-        if (vbounds.size() == 4) 
+        if (vbounds.size() == 4)
         {
-            bounds = liblas::Bounds<double>(vbounds[0], 
-                                    vbounds[1], 
-                                    vbounds[2], 
+            bounds = liblas::Bounds<double>(vbounds[0],
+                                    vbounds[1],
+                                    vbounds[2],
                                     vbounds[3]);
         } else if (vbounds.size() == 6)
         {
-            bounds = liblas::Bounds<double>(vbounds[0], 
-                                    vbounds[1], 
-                                    vbounds[2], 
-                                    vbounds[3], 
-                                    vbounds[4], 
+            bounds = liblas::Bounds<double>(vbounds[0],
+                                    vbounds[1],
+                                    vbounds[2],
+                                    vbounds[3],
+                                    vbounds[4],
                                     vbounds[5]);
         } else {
             ostringstream oss;
@@ -589,16 +589,16 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
                    "6-tuple, not a "<< vbounds.size()<<"-tuple" << "\n";
             throw std::runtime_error(oss.str());
         }
-        
-        if ( bSetExtent ) 
+
+        if ( bSetExtent )
         {
-            if (verbose) 
+            if (verbose)
             {
                 std::cout << " Growing --extent bounds with those that were set via --[x|y|z][min|max]" << std::endl;
             }
             bounds.grow(extent);
         }
-    
+
         if (verbose)
         {
             std::cout << "---------------------------------------------------------" << std::endl;
@@ -607,35 +607,35 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
 
             std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
             std::cout.precision(6);
-    
-            std::cout << " minx: " << bounds.minx() 
-                      << " miny: " << bounds.miny() 
-                      << " minz: " << bounds.minz() 
+
+            std::cout << " minx: " << bounds.minx()
+                      << " miny: " << bounds.miny()
+                      << " minz: " << bounds.minz()
                       << std::endl;
-            std::cout << " maxx: " << bounds.maxx() 
-                      << " maxy: " << bounds.maxy() 
-                      << " maxz: " << bounds.maxz() 
+            std::cout << " maxx: " << bounds.maxx()
+                      << " maxy: " << bounds.maxy()
+                      << " maxz: " << bounds.maxz()
                       << std::endl;
             std::cout << "---------------------------------------------------------" << std::endl;
         }
 
         liblas::FilterPtr bounds_filter = MakeBoundsFilter(bounds, liblas::FilterI::eInclusion);
         // Set to false because we are using this opportunity to set the filter
-        // If it were still true after this point, *another* BoundsFilter would be 
+        // If it were still true after this point, *another* BoundsFilter would be
         // added to the filters list at the end of this function
         if (bSetExtent)
-            bSetExtent = false; 
+            bSetExtent = false;
         filters.push_back(bounds_filter);
-        
+
     }
-    if (vm.count("keep-intensity")) 
+    if (vm.count("keep-intensity"))
     {
         std::string intensities = vm["keep-intensity"].as< string >();
         if (verbose)
             std::cout << "Keeping intensities with values: " << intensities << std::endl;
         if (IsDualRangeFilter(intensities)) {
             // We need to make two filters
-            // Given a range 0-200, split the expression into two filters 
+            // Given a range 0-200, split the expression into two filters
             string::size_type dash = intensities.find_first_of("-");
             std::string low = intensities.substr(0,dash);
             std::string high = intensities.substr(dash+1, intensities.size());
@@ -643,14 +643,14 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             liblas::FilterPtr lt_filter = MakeIntensityFilter(">="+low, liblas::FilterI::eInclusion);
             filters.push_back(lt_filter);
             liblas::FilterPtr gt_filter = MakeIntensityFilter("<="+high, liblas::FilterI::eInclusion);
-            filters.push_back(gt_filter);                
+            filters.push_back(gt_filter);
         } else {
             liblas::FilterPtr intensity_filter = MakeIntensityFilter(intensities, liblas::FilterI::eInclusion);
             filters.push_back(intensity_filter);
-            
+
         }
     }
-    if (vm.count("drop-intensity")) 
+    if (vm.count("drop-intensity"))
     {
         std::string intensities = vm["drop-intensity"].as< string >();
         if (verbose)
@@ -660,17 +660,17 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             throw std::runtime_error("Range filters are not supported for drop-intensity");
         } else {
             liblas::FilterPtr intensity_filter = MakeIntensityFilter(intensities, liblas::FilterI::eExclusion);
-            filters.push_back(intensity_filter);   
+            filters.push_back(intensity_filter);
         }
     }
-    if (vm.count("keep-scan-angle")) 
+    if (vm.count("keep-scan-angle"))
     {
         std::string angles = vm["keep-scan-angle"].as< string >();
         if (verbose)
             std::cout << "Keeping scan angles with values: " << angles << std::endl;
         if (IsDualRangeFilter(angles)) {
             // We need to make two filters
-            // Given a range 0-200, split the expression into two filters 
+            // Given a range 0-200, split the expression into two filters
             string::size_type dash = angles.find_first_of("-");
             std::string low = angles.substr(0,dash);
             std::string high = angles.substr(dash+1, angles.size());
@@ -678,14 +678,14 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             liblas::FilterPtr lt_filter = MakeScanAngleFilter(">="+low, liblas::FilterI::eInclusion);
             filters.push_back(lt_filter);
             liblas::FilterPtr gt_filter = MakeScanAngleFilter("<="+high, liblas::FilterI::eInclusion);
-            filters.push_back(gt_filter);                
+            filters.push_back(gt_filter);
         } else {
             liblas::FilterPtr angle_filter = MakeScanAngleFilter(angles, liblas::FilterI::eInclusion);
             filters.push_back(angle_filter);
-            
+
         }
     }
-    if (vm.count("drop-scan-angle")) 
+    if (vm.count("drop-scan-angle"))
     {
         std::string angles = vm["drop-scan-angle"].as< string >();
         if (verbose)
@@ -695,18 +695,18 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             throw std::runtime_error("Range filters are not supported for drop-scan-angle");
         } else {
             liblas::FilterPtr angle_filter = MakeScanAngleFilter(angles, liblas::FilterI::eExclusion);
-            filters.push_back(angle_filter);   
+            filters.push_back(angle_filter);
         }
     }
-    
-    if (vm.count("keep-time")) 
+
+    if (vm.count("keep-time"))
     {
         std::string times = vm["keep-time"].as< string >();
         if (verbose)
             std::cout << "Keeping times with values: " << times << std::endl;
         if (IsDualRangeFilter(times)) {
             // We need to make two filters
-            // Given a range 0-200, split the expression into two filters 
+            // Given a range 0-200, split the expression into two filters
             string::size_type dash = times.find_first_of("-");
             std::string low = times.substr(0,dash);
             std::string high = times.substr(dash+1, times.size());
@@ -714,107 +714,107 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
             liblas::FilterPtr lt_filter = MakeTimeFilter(">="+low, liblas::FilterI::eInclusion);
             filters.push_back(lt_filter);
             liblas::FilterPtr gt_filter = MakeTimeFilter("<="+high, liblas::FilterI::eInclusion);
-            filters.push_back(gt_filter);                
+            filters.push_back(gt_filter);
         } else {
             liblas::FilterPtr time_filter = MakeTimeFilter(times, liblas::FilterI::eInclusion);
             filters.push_back(time_filter);
-            
+
         }
     }
-    if (vm.count("drop-time")) 
+    if (vm.count("drop-time"))
     {
         std::string times = vm["drop-time"].as< string >();
         if (verbose)
             std::cout << "Dropping times with values: " << times << std::endl;
-            
+
         if (IsDualRangeFilter(times)) {
             throw std::runtime_error("Range filters are not supported for drop-time");
         } else {
             liblas::FilterPtr time_filter = MakeTimeFilter(times, liblas::FilterI::eExclusion);
-            filters.push_back(time_filter);   
+            filters.push_back(time_filter);
         }
     }
 
-    if (vm.count("keep-color")) 
+    if (vm.count("keep-color"))
     {
         std::string keepers = vm["keep-color"].as< string >();
         if (verbose)
             std::cout << "Keeping colors in range:: " << keepers << std::endl;
-            
+
         // Pull apart color ranges in the form: R,G,B-R,G,B
         boost::char_separator<char> sep_dash("-");
         boost::char_separator<char> sep_comma(",");
         std::vector<liblas::Color> colors;
         tokenizer low_high(keepers, sep_dash);
         for (tokenizer::iterator t = low_high.begin(); t != low_high.end(); ++t) {
-            
+
             tokenizer rgbs((*t), sep_comma);
             std::vector<liblas::Color::value_type> rgb;
             for(tokenizer::iterator c = rgbs.begin(); c != rgbs.end(); ++c)
             {
                 int color_val = atoi((*c).c_str());
-                if (color_val < ((std::numeric_limits<boost::uint16_t>::min)()) || 
-                    color_val > ((std::numeric_limits<boost::uint16_t>::max)())) 
+                if (color_val < ((std::numeric_limits<boost::uint16_t>::min)()) ||
+                    color_val > ((std::numeric_limits<boost::uint16_t>::max)()))
                 {
                     ostringstream oss;
                     oss << "Color value must be between 0-65536, not " << color_val;
                     throw std::runtime_error( oss.str() );
-                    
+
                 }
                 rgb.push_back(static_cast<boost::uint16_t>(color_val));
             }
             liblas::Color color(rgb[0], rgb[1], rgb[2]);
             colors.push_back(color);
         }
-        
+
         liblas::FilterPtr color_filter = MakeColorFilter(colors[0], colors[1], liblas::FilterI::eInclusion);
         filters.push_back(color_filter);
     }
-    if (vm.count("drop-color")) 
+    if (vm.count("drop-color"))
     {
         std::string dropers = vm["drop-color"].as< string >();
         if (verbose)
             std::cout << "Dropping colors in range:: " << dropers << std::endl;
-            
+
         // Pull apart color ranges in the form: R,G,B-R,G,B
         boost::char_separator<char> sep_dash("-");
         boost::char_separator<char> sep_comma(",");
         std::vector<liblas::Color> colors;
         tokenizer low_high(dropers, sep_dash);
         for (tokenizer::iterator t = low_high.begin(); t != low_high.end(); ++t) {
-            
+
             tokenizer rgbs((*t), sep_comma);
             std::vector<liblas::Color::value_type> rgb;
             for(tokenizer::iterator c = rgbs.begin(); c != rgbs.end(); ++c)
             {
                 int color_val = atoi((*c).c_str());
-                if (color_val < (std::numeric_limits<boost::uint16_t>::min)() || 
-                    color_val > (std::numeric_limits<boost::uint16_t>::max)()) 
+                if (color_val < (std::numeric_limits<boost::uint16_t>::min)() ||
+                    color_val > (std::numeric_limits<boost::uint16_t>::max)())
                 {
                     ostringstream oss;
                     oss << "Color value must be between 0-65536, not " << color_val;
                     throw std::runtime_error( oss.str() );
-                    
+
                 }
                 rgb.push_back(static_cast<boost::uint16_t>(color_val));
             }
             liblas::Color color(rgb[0], rgb[1], rgb[2]);
             colors.push_back(color);
         }
-        
+
         liblas::FilterPtr color_filter = MakeColorFilter(colors[0], colors[1], liblas::FilterI::eExclusion);
         filters.push_back(color_filter);
     }
 
-    if (vm.count("thin")) 
+    if (vm.count("thin"))
     {
         boost::uint32_t thin = vm["thin"].as< boost::uint32_t >();
         if (thin != 0) {
             if (verbose)
                 std::cout << "Thining file by keeping every "<<thin<<"'th point "  << std::endl;
-            
+
             liblas::FilterPtr thin_filter = liblas::FilterPtr(new liblas::ThinFilter(thin));
-            filters.push_back(thin_filter);    
+            filters.push_back(thin_filter);
         }
     }
 
@@ -841,23 +841,23 @@ std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
         liblas::FilterPtr return_filter = liblas::FilterPtr(new liblas::ReturnFilter(returns, false));
         filters.push_back(return_filter);
     }
-    
+
     if (vm.count("valid_only")){
         if (verbose)
             std::cout << "Keeping valid points only."  << std::endl;
         liblas::FilterPtr valid_filter = liblas::FilterPtr(new liblas::ValidationFilter());
-        filters.push_back(valid_filter);            
+        filters.push_back(valid_filter);
     }
 
 
-    // If we have bSetExtent and we haven't turned it off by merging with a --extent 
+    // If we have bSetExtent and we haven't turned it off by merging with a --extent
     // BoundsFilter, make a filter
     if (bSetExtent)
     {
         liblas::FilterPtr bounds_filter = MakeBoundsFilter(extent, liblas::FilterI::eInclusion);
         filters.push_back(bounds_filter);
     }
-    
+
     return filters;
 }
 
@@ -865,7 +865,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
 {
     std::vector<liblas::TransformPtr> transforms;
 
-    if (vm.count("offset")) 
+    if (vm.count("offset"))
     {
         std::string offset_string = vm["offset"].as< string >();
         if (verbose)
@@ -879,7 +879,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             // Check if the user set --offset min,min,min
             // FIXME: make this so the user could do --offset min,min,20.00
             if (!(*t).compare(m))
-            {   
+            {
                 mins = true;
                 continue;
             }
@@ -889,7 +889,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
                 offsets.push_back(atof((*t).c_str()));
             }
         }
-        if (offsets.size() != 3) 
+        if (offsets.size() != 3)
         {
             throw std::runtime_error("All three values for setting the offset must be floats, and there must be three values");
 
@@ -898,7 +898,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
     }
 
 
-    if (vm.count("scale")) 
+    if (vm.count("scale"))
     {
         std::vector<double> scales = vm["scale"].as< std::vector<double> >();
 
@@ -910,13 +910,13 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             throw std::runtime_error(oss.str());
         }
 
-        
+
         if (verbose)
         {
             ostringstream oss;
             for (std::vector<double>::const_iterator i = scales.begin();
                  i != scales.end();
-                 i++) 
+                 i++)
                 {
                     oss << *i << " ";
                 }
@@ -926,13 +926,13 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
 
         header.SetScale(scales[0], scales[1], scales[2]);
     }
-    
-    if (vm.count("file-format")) 
+
+    if (vm.count("file-format"))
     {
         std::string format_string = vm["file-format"].as< string >();
         if (verbose)
             std::cout << "Setting format to: " << format_string << std::endl;
-            
+
         boost::char_separator<char> sep(".");
         std::vector<int> versions;
         tokenizer tokens(format_string, sep);
@@ -947,30 +947,30 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             oss << "Format version must dotted -- ie, '1.0' or '1.2', not " << format_string;
             throw std::runtime_error(oss.str());
         }
-        
+
         int minor = versions[1];
         if (minor > 2){
             ostringstream oss;
             oss << "Format version must dotted -- ie, '1.0' or '1.2', not " << format_string;
             throw std::runtime_error(oss.str());
         }
-        header.SetVersionMinor(static_cast<boost::uint8_t>(minor)); 
+        header.SetVersionMinor(static_cast<boost::uint8_t>(minor));
     }
 
-    if (vm.count("point-format")) 
+    if (vm.count("point-format"))
     {
         boost::uint32_t format = vm["point-format"].as< boost::uint32_t >();
         if (verbose)
             std::cout << "Setting point format to: " << format << std::endl;
-            
+
         if (format > 3){
             ostringstream oss;
             oss << "Point format valid range is 0-3, not " << format;
             throw std::runtime_error(oss.str());
         }
-        header.SetDataFormatId(static_cast<liblas::PointFormatName>(format)); 
+        header.SetDataFormatId(static_cast<liblas::PointFormatName>(format));
     }
-    if (vm.count("pad-header")) 
+    if (vm.count("pad-header"))
     {
         std::string header_pad = vm["pad-header"].as< string >();
         if (verbose)
@@ -981,7 +981,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             ostringstream oss;
             oss << "Header pad was 0.  It must be greater than "<<offset<< " bytes";
             throw std::runtime_error(oss.str());
-            
+
         }
         header.SetDataOffset(atoi(header_pad.c_str()));
     }
@@ -995,32 +995,32 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             ostringstream oss;
             for (std::vector<std::string>::const_iterator i = creation.begin();
                  i != creation.end();
-                 i++) 
+                 i++)
                 {
                     oss << *i << " ";
                 }
                 std::cout << "Setting file creation to " << oss.str() << std::endl;
         }
-            
+
         std::string m("now");
         bool now = false;
-        if (creation.size() == 1 ) 
+        if (creation.size() == 1 )
         {
-            if (!(creation[0].compare(m))) 
+            if (!(creation[0].compare(m)))
             {
                 now = true;
-            }            
+            }
         }
-        
+
         boost::int32_t day = 0;
         boost::int32_t year = 0;
-        
-        
-        if (creation.size() == 2) 
+
+
+        if (creation.size() == 2)
         {
             day = atoi(creation[0].c_str());
             year = atoi(creation[1].c_str());
-            
+
             if (day < 0 || day > 366) {
                 ostringstream oss;
                 oss << "Day must be between 1-366, not " << day;
@@ -1032,10 +1032,10 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
                 oss << "Year must be greater than 0, not " << year;
                 throw std::runtime_error(oss.str());
             }
-            
+
         }
-        
-        if (now == true) 
+
+        if (now == true)
         {
             liblas::Header h;
             header.SetCreationDOY(h.GetCreationDOY());
@@ -1043,31 +1043,31 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         } else {
             header.SetCreationDOY(static_cast<boost::uint16_t>(day));
             header.SetCreationYear(static_cast<boost::uint16_t>(year));
-            
+
         }
     }
 
-    if (vm.count("add-schema")) 
+    if (vm.count("add-schema"))
     {
         liblas::VariableRecord vlr = header.GetSchema().GetVLR();
         header.AddVLR(vlr);
     }
 
-    if (vm.count("delete-vlr")) 
+    if (vm.count("delete-vlr"))
     {
         std::vector<std::string> vlrs = vm["delete-vlr"].as< std::vector<std::string> >();
-        
-        
+
+
         if (vlrs.size() % 2 != 0) {
             ostringstream err;
             err << "VLR descriptions must be in pairs of 2 -- A name and an ID";
             throw std::runtime_error(err.str());
         }
         ostringstream oss;
-        
+
         for (std::vector<std::string>::const_iterator i = vlrs.begin();
              i != vlrs.end();
-             i++) 
+             i++)
             {
                 oss << *i << " ";
             }
@@ -1076,7 +1076,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
 
                 std::cout << "Deleting VLRs with the values: " << oss.str() << std::endl;
         }
-        
+
         for (std::vector<std::string>::size_type i = 0; i < vlrs.size(); i=i+2)
         {
             boost::int32_t id = atoi(vlrs[i+1].c_str());
@@ -1093,11 +1093,11 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         }
     }
 
-    if (vm.count("add-vlr")) 
+    if (vm.count("add-vlr"))
     {
         std::vector<std::string> vlrs = vm["add-vlr"].as< std::vector<std::string> >();
-        
-        
+
+
         if (vlrs.size() < 3) {
             ostringstream err;
             err << "VLR additions must be at least 3 arguments -- --add-vlr NAME 42 \"filename.ext\"";
@@ -1107,15 +1107,15 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             throw std::runtime_error("Only one VLR may be added at a time");
 
         ostringstream oss;
-        
+
         for (std::vector<std::string>::const_iterator i = vlrs.begin();
              i != vlrs.end();
-             i++) 
+             i++)
             {
                 oss << *i << " ";
             }
 
-        
+
         liblas::VariableRecord v;
         v.SetUserId(vlrs[0]);
 
@@ -1131,9 +1131,9 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         }
 
         v.SetRecordId(static_cast<boost::uint16_t>(id));
-        
+
         std::vector<boost::uint8_t> data;
-        
+
         std::string data_or_filename;
         if (vlrs.size() == 4){
 
@@ -1141,28 +1141,28 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             data_or_filename = vlrs[3];
         } else {
             data_or_filename = vlrs[2];
-        } 
+        }
 
         try {
             std::vector<char> d;
             d = TryReadRawFileData(data_or_filename);
-            for (std::vector<char>::const_iterator i = d.begin(); i != d.end(); ++i) 
+            for (std::vector<char>::const_iterator i = d.begin(); i != d.end(); ++i)
             {
                 data.push_back(*i);
             }
-            
+
         } catch (std::runtime_error const& ) {
             std::string::const_iterator i;
             for (i = data_or_filename.begin(); i != data_or_filename.end(); ++i)
             {
                 data.push_back(*i);
             }
-        }    
+        }
 
         if (data.size() > (std::numeric_limits<boost::uint16_t>::max)()) {
             std::ostringstream oss;
-            oss << "This VLR with length " << data.size() << " does" 
-                << " not fit within the maximum VLR size of " 
+            oss << "This VLR with length " << data.size() << " does"
+                << " not fit within the maximum VLR size of "
                 << (std::numeric_limits<boost::uint16_t>::max)();
             throw std::runtime_error(oss.str());
         }
@@ -1179,7 +1179,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         header.AddVLR(v);
     }
 
-    if (vm.count("generating-software")) 
+    if (vm.count("generating-software"))
     {
         std::string software = vm["generating-software"].as< std::string >();
         if (verbose)
@@ -1190,32 +1190,32 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         header.SetSoftwareId(software);
     }
 
-    if (vm.count("system-identifier")) 
+    if (vm.count("system-identifier"))
     {
         std::string id = vm["system-identifier"].as< std::string >();
-        
+
 
         if (verbose)
         {
 
                 std::cout << "Setting System ID to: " << id<< std::endl;
         }
-        
+
         header.SetSystemId(id);
     }
-    
 
-    if (vm.count("a_srs")) 
+
+    if (vm.count("a_srs"))
     {
         liblas::SpatialReference in_ref;
-        
+
         std::string input_srs = vm["a_srs"].as< string >();
-        
+
         if (!input_srs.empty())
         {
             in_ref.SetFromUserInput(input_srs);
         }
-        
+
         if (verbose)
             std::cout << "Setting input SRS to '" << input_srs << "'"<< std::endl;
         header.SetSRS(in_ref);
@@ -1246,29 +1246,29 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
 
             throw std::runtime_error(oss.str());
         }
-        
+
         if (verbose)
         {
             ostringstream oss;
             for (std::vector<std::string>::const_iterator i = vertical_vec.begin();
                  i != vertical_vec.end();
-                 i++) 
+                 i++)
                 {
                     oss << *i << " ";
                 }
                 std::cout << "Setting vertical info to: " << oss.str() << std::endl;
         }
-            
+
         boost::int32_t verticalCSType = boost::lexical_cast<boost::int32_t>(vertical_vec[0]);
-        
+
         std::string citation;
         int verticalDatum = -1;
         int verticalUnits = 9001;
-        
+
         if (vertical_vec.size() > 1) {
             citation = boost::lexical_cast<std::string>(vertical_vec[1]);
         }
-        
+
         if (vertical_vec.size() > 2) {
             verticalDatum = boost::lexical_cast<boost::int32_t>(vertical_vec[2]);
         }
@@ -1276,13 +1276,13 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         if (vertical_vec.size() > 3) {
             verticalUnits = boost::lexical_cast<boost::int32_t>(vertical_vec[3]);
         }
-        
+
         vert_ref.SetVerticalCS(verticalCSType, citation, verticalDatum, verticalUnits);
-        header.SetSRS(vert_ref);      
+        header.SetSRS(vert_ref);
     }
-    if (vm.count("add-wkt-srs")) 
+    if (vm.count("add-wkt-srs"))
     {
-        // Reset the SRS using WKT, which will cause both GeoTIFF keys and OGC WKT 
+        // Reset the SRS using WKT, which will cause both GeoTIFF keys and OGC WKT
         // VLRs to be written to the file.
         liblas::SpatialReference ref = header.GetSRS();
         std::string wkt = ref.GetWKT();
@@ -1290,11 +1290,11 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         header.SetSRS(ref);
     }
 
-    if (vm.count("t_srs")) 
+    if (vm.count("t_srs"))
     {
         liblas::SpatialReference in_ref;
         liblas::SpatialReference out_ref;
-        
+
         std::string output_srs = vm["t_srs"].as< string >();
         if (verbose)
             std::cout << "Setting output SRS to " << output_srs << std::endl;
@@ -1304,30 +1304,30 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
             std::string input_srs = vm["a_srs"].as< string >();
             in_ref.SetFromUserInput(input_srs);
         } else {
-            // If the user didn't assign an input SRS, we'll try to take 
+            // If the user didn't assign an input SRS, we'll try to take
             // it from our existing header.
             in_ref = header.GetSRS();
             if (in_ref.GetVLRs().size() == 0)
             {
                 throw std::runtime_error("No input SRS is available on the file you have specified.  Please use --a_srs to assign one");
             }
-            
+
         }
-        // Set the header's SRS to the output SRS now.  We've already 
-        // made the transformation, and this SRS will be used to 
+        // Set the header's SRS to the output SRS now.  We've already
+        // made the transformation, and this SRS will be used to
         // write the new file(s)
         header.SetSRS(out_ref);
-        
+
         liblas::Bounds<double> b = header.GetExtent();
-    
+
         liblas::ReprojectionTransform trans(in_ref, out_ref);
-    
+
         liblas::Point minimum(&header);
         minimum.SetCoordinates(b.minx(), b.miny(), b.minz());
 
         liblas::Point maximum(&header);
         maximum.SetCoordinates(b.maxx(), b.maxy(), b.maxz());
-        
+
         trans.transform(minimum);
         trans.transform(maximum);
         b = liblas::Bounds<double>(minimum, maximum);
@@ -1336,7 +1336,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         transforms.push_back(srs_transform);
     }
 
-    if (vm.count("color-source")) 
+    if (vm.count("color-source"))
     {
         std::string datasource = vm["color-source"].as< string >();
         std::vector<boost::uint32_t> bands;
@@ -1345,14 +1345,14 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         if (vm.count("color-source-bands"))
         {
             bands = vm["color-source-bands"].as< std::vector<boost::uint32_t> >();
-            if (bands.size() != 3) 
+            if (bands.size() != 3)
             {
                 std::ostringstream oss;
                 oss << "The bands list must have three elements, not " << bands.size();
                 throw std::runtime_error(oss.str());
             }
-        } 
-        else 
+        }
+        else
         {
             bands.resize(3);
             bands[0] = 1;
@@ -1364,9 +1364,9 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         {
             bSetScale = true;
             scale = vm["color-source-scale"].as< boost::uint32_t >();
-        }          
-        
-        
+        }
+
+
         if (verbose)
         {
             // make a displayable string for the bands list
@@ -1380,19 +1380,19 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
                 if (i2 != bands.end())
                     bnds << ", ";
             }
-            std::cout << "Fetching color from ' " << datasource 
-                      << "' using bands '" << bnds.str() 
+            std::cout << "Fetching color from ' " << datasource
+                      << "' using bands '" << bnds.str()
                       << "' for R, G, B";
             if (bSetScale)
                 std::cout << " with a scale factor of " << scale;
             std::cout<< std::endl;
-                
+
         }
 
-        
+
         // Check the schema to see if we have color
         liblas::Schema const& schema = header.GetSchema();
-        
+
         try
         {
             schema.GetDimension("Red");
@@ -1408,15 +1408,15 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         {
             throw std::runtime_error("The header for this file does not allow storing blue color information.  Alter the header's data format using the --point-format switch");
         }
-        
+
         try
         {
             schema.GetDimension("Green");
         } catch (std::runtime_error const&)
         {
             throw std::runtime_error("The header for this file does not allow storing green color information.  Alter the header's data format using the --point-format switch");
-        }        
-        
+        }
+
         liblas::TransformPtr color_fetch = liblas::TransformPtr(new liblas::ColorFetchingTransform(datasource, bands, &header));
         if (bSetScale) {
             liblas::ColorFetchingTransform* c = dynamic_cast<liblas::ColorFetchingTransform*>(color_fetch.get());
@@ -1424,7 +1424,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         }
         transforms.push_back(color_fetch);
     }
-    if (vm.count("point-translate")) 
+    if (vm.count("point-translate"))
     {
         std::string translate = vm["point-translate"].as< std::string >();
         if (verbose)
@@ -1436,7 +1436,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
         transforms.push_back(trans_trans);
     }
 
-    if (vm.count("fix-optech-scan-angle")) 
+    if (vm.count("fix-optech-scan-angle"))
     {
         if (verbose)
             std::cout << "Fixing Scan Angles by multiplying by 1.944445" << std::endl;
@@ -1448,7 +1448,7 @@ std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbo
     return transforms;
 }
 
-liblas::property_tree::ptree SummarizeReader(liblas::Reader& reader) 
+liblas::property_tree::ptree SummarizeReader(liblas::Reader& reader)
 {
     liblas::Summary s;
 
@@ -1458,8 +1458,8 @@ liblas::property_tree::ptree SummarizeReader(liblas::Reader& reader)
     {
         throw std::runtime_error("Unable to read any points from file.");
     }
-        
-    while (read) 
+
+    while (read)
     {
         liblas::Point const& p = reader.GetPoint();
         s.AddPoint(p);
diff --git a/bin/ci/before_install.sh b/bin/ci/before_install.sh
index 54f5525..35a650e 100755
--- a/bin/ci/before_install.sh
+++ b/bin/ci/before_install.sh
@@ -14,7 +14,7 @@ sudo apt-get install \
     libproj-dev \
     libxml2-dev \
     libtiff4-dev \
-    libgeotiff-dev 
+    libgeotiff-dev
 # install libgeotiff from sources
 #wget http://download.osgeo.org/geotiff/libgeotiff/libgeotiff-1.4.0.tar.gz
 #tar -xzf libgeotiff-1.4.0.tar.gz
diff --git a/cmake/modules/FindPROJ4.cmake b/cmake/modules/FindPROJ4.cmake
index 2a819ce..b65f7d2 100644
--- a/cmake/modules/FindPROJ4.cmake
+++ b/cmake/modules/FindPROJ4.cmake
@@ -1,44 +1,44 @@
-###############################################################################
-# CMake module to search for PROJ.4 library
-#
-# On success, the macro sets the following variables:
-# PROJ4_FOUND       = if the library found
-# PROJ4_LIBRARY     = full path to the library
-# PROJ4_INCLUDE_DIR = where to find the library headers 
-# also defined, but not for general use are
-# PROJ4_LIBRARY, where to find the PROJ.4 library.
-#
-# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-#
-###############################################################################
-
-# Try to use OSGeo4W installation
-IF(WIN32)
-    SET(PROJ4_OSGEO4W_HOME "C:/OSGeo4W") 
-
-    IF($ENV{OSGEO4W_HOME})
-        SET(PROJ4_OSGEO4W_HOME "$ENV{OSGEO4W_HOME}") 
-    ENDIF()
-ENDIF(WIN32)
-
-FIND_PATH(PROJ4_INCLUDE_DIR proj_api.h
-    PATHS ${PROJ4_OSGEO4W_HOME}/include
-    DOC "Path to PROJ.4 library include directory")
-
-SET(PROJ4_NAMES ${PROJ4_NAMES} proj proj_i)
-FIND_LIBRARY(PROJ4_LIBRARY
-    NAMES ${PROJ4_NAMES}
-    PATHS ${PROJ4_OSGEO4W_HOME}/lib
-    DOC "Path to PROJ.4 library file")
-
-# Handle the QUIETLY and REQUIRED arguments and set SPATIALINDEX_FOUND to TRUE
-# if all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ4 DEFAULT_MSG PROJ4_LIBRARY PROJ4_INCLUDE_DIR)
-
-IF(PROJ4_FOUND)
-  SET(PROJ4_LIBRARIES ${PROJ4_LIBRARY})
-ENDIF()
+###############################################################################
+# CMake module to search for PROJ.4 library
+#
+# On success, the macro sets the following variables:
+# PROJ4_FOUND       = if the library found
+# PROJ4_LIBRARY     = full path to the library
+# PROJ4_INCLUDE_DIR = where to find the library headers 
+# also defined, but not for general use are
+# PROJ4_LIBRARY, where to find the PROJ.4 library.
+#
+# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+###############################################################################
+
+# Try to use OSGeo4W installation
+IF(WIN32)
+    SET(PROJ4_OSGEO4W_HOME "C:/OSGeo4W") 
+
+    IF($ENV{OSGEO4W_HOME})
+        SET(PROJ4_OSGEO4W_HOME "$ENV{OSGEO4W_HOME}") 
+    ENDIF()
+ENDIF(WIN32)
+
+FIND_PATH(PROJ4_INCLUDE_DIR proj_api.h
+    PATHS ${PROJ4_OSGEO4W_HOME}/include
+    DOC "Path to PROJ.4 library include directory")
+
+SET(PROJ4_NAMES ${PROJ4_NAMES} proj proj_i)
+FIND_LIBRARY(PROJ4_LIBRARY
+    NAMES ${PROJ4_NAMES}
+    PATHS ${PROJ4_OSGEO4W_HOME}/lib
+    DOC "Path to PROJ.4 library file")
+
+# Handle the QUIETLY and REQUIRED arguments and set SPATIALINDEX_FOUND to TRUE
+# if all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ4 DEFAULT_MSG PROJ4_LIBRARY PROJ4_INCLUDE_DIR)
+
+IF(PROJ4_FOUND)
+  SET(PROJ4_LIBRARIES ${PROJ4_LIBRARY})
+ENDIF()
diff --git a/doc/conf.py b/doc/conf.py
index 211d888..d39b9d0 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -22,12 +22,12 @@ sys.path.append(os.path.abspath('../python'))
 
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = [  'sphinx.ext.autodoc', 
-                'sphinx.ext.doctest', 
-                'sphinx.ext.intersphinx', 
-                'sphinx.ext.todo', 
-                'sphinx.ext.ifconfig', 
-                'rst2pdf.pdfbuilder', 
+extensions = [  'sphinx.ext.autodoc',
+                'sphinx.ext.doctest',
+                'sphinx.ext.intersphinx',
+                'sphinx.ext.todo',
+                'sphinx.ext.ifconfig',
+                'rst2pdf.pdfbuilder',
                 ]
 
 # Add any paths that contain templates here, relative to this directory.
@@ -44,7 +44,7 @@ master_doc = 'docs'
 
 # General information about the project.
 project = u'libLAS'
-copyright = u'2014, Howard Butler, Mateusz Loskot and others'
+copyright = u'2016, Howard Butler, Mateusz Loskot and others'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
@@ -58,7 +58,7 @@ def read_version(filename):
     major = 'LIBLAS_VERSION_MAJOR'
     minor = 'LIBLAS_VERSION_MINOR'
     patch = 'LIBLAS_VERSION_PATCH'
-    
+
     for line in data:
         if str(major) in line:
             line = line.replace('SET('+major+' ', '')
@@ -76,7 +76,7 @@ def read_version(filename):
             line = line.replace('"','')
             pat = line.strip()
     return '%s.%s.%s'%(maj, min, pat)
-    
+
 version = read_version('../CMakeLists.txt')
 
 # The full version, including alpha/beta/rc tags.
diff --git a/doc/development/annual_report_2010.txt b/doc/development/annual_report_2010.txt
deleted file mode 100644
index d1ee5a8..0000000
--- a/doc/development/annual_report_2010.txt
+++ /dev/null
@@ -1,247 +0,0 @@
-.. _annual_report_2010:
-
-******************************************************************************
-2010 Annual Report
-******************************************************************************
-
-:Author: Howard Butler
-:Contact: hobu.inc at gmail.com
-:Date: 12/21/2010
-
-The following document is a synopsis of major development activities that have 
-taken place in the libLAS project (or related projects) in the 2010 calendar 
-year.  
-
-Vertical Datum Reprojection and Transformation
-..............................................................................
-
-Frank Warmerdam implemented vertical datum reprojection and transformation in the 
-entire open source GIS stack in the past year (`proj.4`_, `GDAL`_ and `libgeotiff`_).  This work 
-makes it possible to make vertical datum transformations via command-line utilities 
-like :ref:`las2las <las2las>` in addition to providing the tools for software 
-developers to implement the features in their own software.
-
-.. _`libgeotiff`: http://www.remotesensing.org/geotiff/geotiff.html
-.. _`proj.4`: http://proj.maptools.org/
-.. _`GDAL`: http://www.gdal.org
-
-libLAS Processing Kernel
-..............................................................................
-
-libLAS gained something I call the "libLAS Processing Kernel" in the past year. 
-It's really just a set of common functions that all application-level software 
-can reuse to implement filtering and transformation on LAS data.  The collation 
-of all of this functionality in a common place has meant the reuse of the 
-same operations in many of the libLAS utilities include :ref:`las2las <las2las>`, 
-:ref:`lasinfo <lasinfo>`, and :ref:`las2txt <las2txt>`.  New features implemented 
-in the kernel include:
-
-* Color fetching from GDAL raster data sources
-* Data reprojection and vertical datum transformation
-* Numerous filtering operations
-* Header modification
-
-These utilities are available to all software developers who wish to reuse them 
-in their own tools.
-
-
-Re-engineering of :ref:`las2las <las2las>` :ref:`las2txt <las2txt>` and :ref:`lasinfo <lasinfo>`
-...................................................................................................
-
-:ref:`las2las <las2las>` :ref:`las2txt <las2txt>` and :ref:`lasinfo <lasinfo>`
-were re-imagined in light of development of the `libLAS Processing Kernel`_ to
-take advantage of new functionality and regularize command-line argument
-handling and parsing. The previous versions of the utilities have been
-preserved under the :ref:`las2las-old <las2las_old>` :ref:`las2txt-old
-<las2txt_old>` and :ref:`lasinfo-old <lasinfo_old>` monikers in case people
-have significant processing workflows developed with them. It would be
-advantageous to upgrade to the new versions in many cases -- both for
-significantly improved functionality and for a speed improvement that is
-sometimes double that of the -old versions.
-
-Some new features the utilities gained as part of this effort include:
-
-* Setting color information from GDAL rasters
-* Splitting files based on a point count or a file size in mb
-* Chaining many filter operations together into a single call
-* Modifying header information, including setting coordinate system info
-* Summarizing data more fully and more flexibly (XML, per-point)
-
-Chipper
-..............................................................................
-
-Andrew Bell developed a specialized point partitioning process called
-:ref:`lasblock <lasblock>` to bucketize point data.The process that aims to
-optimize the fill capacity, shape, and speed of processing. More specifically,
-it attempts to keep the blocks as full as possible and as square as possible
-to augment querying characteristics for `Oracle Point Cloud`_. This
-pre-processing is needed as precursor step in the processing chain that ends
-with actually loading the data into Oracle via :ref:`las2oci`. :ref:`lasblock
-<lasblock>` can also be used as a LAS tiling process, although it is not so
-memory efficient.
-
-
-Indexing
-..............................................................................
-
-Gary Huber developed an octree-based spatial index for libLAS to speed up random,
-bounding-box-based queries to LAS files. It is released as part of libLAS 1.6,
-but its full implementation within the library is not yet complete. The index
-can store its data within VLRs (requires a file rewrite) in addition to
-in a file alongside the .las file.
-
-
-
-CMake
-..............................................................................
-
-libLAS was migrated to using `CMake`_ for its configuration system. CMake
-allows easy generation of MSVC project files, XCode project files, and make
-files under a common configuration. This effort eliminated three parallel
-build system configurations (MSVC projects, GNU autoconf, MSVC makefiles) and
-provided more flexibility for packaging, testing, and build types. In my
-opinion, its use has been a boon to the project.
-
-OSGeo4W
-..............................................................................
-
-For the first time ever, we have released fully-capable Windows libLAS
-packages in the form of an OSGeo4W release. These releases contain the full
-range of libLAS functionality including coordinate system support, Oracle
-support, vertical datum transformation, and chipping. Head to
-http://trac.osgeo.org/osgeo4w to obtain your copy and start testing libLAS
-immediately.
-
-New Website
-..............................................................................
-
-We rewrote the libLAS website and transformed it from a bunch of wiki pages 
-in Trac to a Sphinx-backed HTML website.  We have added tons more documentation, 
-provided it in formats such as `PDF`_, and organized things significantly.  
-
-Generic LAS Schema Support
-..............................................................................
-
-Though it is specifically allowed by the standard but not widely implemented,
-it is possible to store extra data attached to each point after the requisite
-PointFormat data are stored. There is neither a regularized way to describe
-these data nor a way to capture metadata about this. To this end, I have
-proposed an XML schema document that could be stored in a VLR as well as
-schema-aware reader and writer implementations that can utilize that VLR to
-work with the data. See <https://lidarbb.cr.usgs.gov/index.php?showtopic=9075>
-for more details on the initial proposal of schema support.
-
-libLAS now implements a class called liblas::Schema that is driven 
-by the Point Data Format ID of the header in addition to any extra dimensions 
-you wish to store with the point.  This work is used for both the `Oracle Point Cloud`_ 
-effort and upcoming LASzip compression integration.
-
-
-
-Refactoring of liblas::Point class
-..............................................................................
-
-We significantly refactored the liblas::Point class the 1.6.0 release.  The 
-first thing that was done was to make it "thinner" in the sense that it doesn't 
-store a union of all point-format-derived dimensions on it, and instead 
-stores a reference to a schema that informs the class about which dimensions 
-exist.  Additionally, data are interpreted on-the-fly from the raw bytes 
-which compose the point, eliminating the fidelity issues.
-
-libLAS 1.2.1 and below utilized a liblas::Point that was kind of fat. It
-carried around interpreted data members for all of the dimensions on the point
--- x, y, z, intensity, etc -- and if you asked for one of these, it just
-returned it to you directly. The interpretation of those data happened as the
-data were read, and again as the data were written (back into raw bytes).
-
-libLAS 1.6+ has changed liblas::Point in a number of important ways.
-liblas::Point now only carries along the raw bytes for the point, and if you
-ask for one of the dimensions, it interprets it on-the-fly. For example, a
-GetX() call now requires going into the liblas::Point byte array, pulling the
-first four bytes off of it, asking the point's header for scaling information,
-and rescaling the integer data into double data. If you only call GetX() one
-time, things are roughly equivalent to what we were doing before --
-interpreting and caching interpreted data directly on the liblas::Point -- but
-every one of your subsequent calls to GetX() have this interpretation
-performance hit. You need to cache your calls to interpreted data if you are
-reusing things.  Alternatively, you can control when your data have scaling 
-applied by using GetRawX(), which was not possible before libLAS 1.6.
-
-The rationale for moving to this approach was three-fold. First, the LAS
-committee continually adds new dimensions onto the specification, and I wanted
-an extendable way to add them to libLAS without causing a full re-engineering
-of the liblas::Point class every time they do. Second, liblas::Point now has a
-schema attached to it (based on the list of dimensions that a LAS file's point
-format defines plus any custom dimensions you wish to add to the point
-record). The schema allows you to extend the point format and add your own
-dimensions and it provides generic descriptive information about what exists
-in the file. You can see the description of these schemas in the new
-:ref:`lasinfo <lasinfo>` output from libLAS. Lastly, previous versions of
-libLAS did not allow you to work with raw data, and did not allow the user to
-transform the data (coordinate data, especially) with perfect fidelity. The
-new approach explicitly supports this out-of-the-box. Here's something that is
-now possible with the new (C++) API that was not previously:
-
-::
-
-    liblas::Point const& p = reader.GetPoint();
-    std::vector<uint8_t> data = p.GetData();
-    ... // do something with the raw data like stuff it into a database.
-
-Refactoring of internal Reader and Writer code
-..............................................................................
-
-The previous (< libLAS 1.2) C++ reader and writer code of libLAS was a bit
-inflexible, and contained significant duplication for each file format
-version. Giant updates would be required to the code as the ASPRS LAS standard
-committee added new specification versions with new required point formats.
-Additionally, the old code's design was a bit rigid for adding things like
-generic schema support.
-
-Both the liblas::Reader and liblas::Writer have been significantly `refactored`_
-
-The reduction in duplication means going to only one place to make changes to 
-the code.  In addition to not repeating ourselves, it provides us more 
-flexibility to add new features and extensibility to allow the reader and 
-writers to be overridden by user code.  
-
-Generic interfaces
-..............................................................................
-
-A number of generic interfaces have been added to libLAS to support dynamic
-polymorphism. See <liblas/liblas.hpp> for the C++ interfaces. By implementing
-these interfaces, you can add your own reader/writer implementations as well
-as provide custom filtering and transformation capability.
-
-Faster binary i/o
-..............................................................................
-
-Mateusz Loskot developed a more savvy implementation for its binary i/o which
-provides some significant performance improvements. 
-
-Caching reader
-..............................................................................
-
-A reader implementation that provides data caching will be provided at 
-libLAS 1.6. If your data reading involves reading the data in multiple passes 
-through the file, you can utilize the cached reader to cache the points 
-(up to the size of the entire file) for faster repeated and random access.  
-
-Seek support
-..............................................................................
-
-It is now possible to seek to a specific point in the file and start reading 
-points.  This can significantly speed up the "random sampling" access strategy 
-where one starts reading a run of points at a specific location in the file 
-and then moves to a different location.
-
-Classification class
-..............................................................................
-
-A class is now provided to abstract the LAS classification value and help 
-interpret the bit fields that are present for synthetic, key point, and withheld 
-types.  
-
-.. _refactored: http://en.wikipedia.org/wiki/Code_refactoring
-.. _`Oracle Point Cloud`: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28400/sdo_pc_pkg_ref.htm
-.. _`PDF`: http://liblas.org/pdf/libLAS.pdf
\ No newline at end of file
diff --git a/doc/download.txt b/doc/download.txt
index 4c41830..4937609 100644
--- a/doc/download.txt
+++ b/doc/download.txt
@@ -8,10 +8,17 @@ Download
 Current Release(s)
 ------------------------------------------------------------------------------
 
+* **2016-08-23**
+
+  - `libLAS-1.8.1-src.tar.bz2 <http://download.osgeo.org/liblas/libLAS-1.8.1.tar.bz2>`__
+    `(md5) <http://download2.osgeo.org/liblas/libLAS-1.8.1.tar.bz2.md5>`__
+
+Past Release
+------------------------------------------------------------------------------
+
 * **2014-08-01**
 
   - `libLAS-1.8.0-src.tar.bz2 <http://download.osgeo.org/liblas/libLAS-1.8.0.tar.bz2>`__
-    `(md5) <http://download2.osgeo.org/liblas/libLAS-1.8.0.tar.bz2.md5>`__
 
   - See `OSGeo4W <http://trac.osgeo.org/osgeo4w>`__ for Windows release.
 
diff --git a/doc/python.txt b/doc/python.txt
index ba2b41f..3fd12fb 100644
--- a/doc/python.txt
+++ b/doc/python.txt
@@ -1,7 +1,3 @@
-.. raw:: pdf
-
-    PageBreak
-    
 .. _class_documentation:
 
 ****************************************************************
@@ -9,7 +5,12 @@
 ****************************************************************
 
 
+.. warning::
 
+    laspy https://github.com/grantbrown/laspy provides a pure-Python
+    implementation that is compatible with libLAS' API. Unless you are
+    already using libLAS, we suggest that you utlize laspy for more
+    complete Python LAS operations.
 
 
 =============================================
@@ -17,7 +18,7 @@ liblas.color.Color
 =============================================
 
 .. autoclass:: liblas.color.Color
-    :members:   __init__, 
+    :members:   __init__,
                 red,
                 green,
                 blue,
@@ -30,17 +31,17 @@ liblas.file.File
 =============================================
 
 .. autoclass:: liblas.file.File
-    :members:   __init__, 
-                close, 
-                header, 
-                read, 
+    :members:   __init__,
+                close,
+                header,
+                read,
                 write,
                 output_srs,
                 input_srs,
-                __iter__, 
+                __iter__,
                 __getitem__,
                 __len__
-                
+
 
 =============================================
 liblas.guid.GUID
@@ -84,24 +85,24 @@ liblas.point.Point
 =============================================
 
 .. autoclass:: liblas.point.Point
-    :members:   __init__, 
-                x, 
-                y, 
-                z, 
-                time, 
-                raw_time, 
-                scan_angle, 
-                scan_direction, 
-                scan_flags, 
-                flightline_edge, 
-                number_of_returns, 
+    :members:   __init__,
+                x,
+                y,
+                z,
+                time,
+                raw_time,
+                scan_angle,
+                scan_direction,
+                scan_flags,
+                flightline_edge,
+                number_of_returns,
                 return_number,
                 classification,
                 user_data,
                 point_source_id,
                 color,
                 data
-                
+
 
 =============================================
 liblas.srs.SRS
@@ -118,7 +119,7 @@ liblas.srs.SRS
                 set_proj4,
                 get_wkt_compoundok,
                 set_userinput
-                
+
 
 =============================================
 liblas.vlr.VLR
diff --git a/doc/utilities/index.txt b/doc/utilities/index.txt
index de657b0..28c723e 100644
--- a/doc/utilities/index.txt
+++ b/doc/utilities/index.txt
@@ -11,6 +11,6 @@
    las2las
    las2txt
    las2ogr
+   las2tindex
    txt2las
-   lasblock
    ts2las
diff --git a/doc/utilities/las2tindex.txt b/doc/utilities/las2tindex.txt
index 820c060..119c74d 100644
--- a/doc/utilities/las2tindex.txt
+++ b/doc/utilities/las2tindex.txt
@@ -1,10 +1,5 @@
-
-.. raw:: pdf
-
-    PageBreak
-    
 .. _las2tindex:
-    
+
 ****************************************************************
   las2tindex
 ****************************************************************
diff --git a/doc/utilities/lasblock.txt b/doc/utilities/lasblock.txt
deleted file mode 100644
index b390f10..0000000
--- a/doc/utilities/lasblock.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-
-.. raw:: pdf
-
-    PageBreak
-    
-.. _lasblock:
-    
-****************************************************************
-  lasblock
-****************************************************************
-
-:Author: Howard Butler
-:Contact: hobu.inc at gmail.com
-
-
-lasblock is a utility for pre-processing an LAS file into "chips" or "blocks".  
-These blocks are a custom point partitioning process that aims to optimize 
-the fill capacity, shape, and speed of processing.  More specifically, 
-it attempts to keep the blocks as full as possible and as square as possible 
-to augment querying characteristics for `Oracle Point Cloud`_. 
-This pre-processing is needed as precursor 
-step in the processing chain that ends with actually loading the data via 
-:ref:`las2oci`.
-
-
-Usage
-------------------------------------------------------------------------------
-
-
-Block a file, and write out blocks with 6 decimals of precision with 
-a nominal capacity of 3000 points per block:
-
-::
-
-    $ lasblock -c 3000  -p 6 myfile.las
-
-.. note::
-    If no capacity is specified with ``-c``, 10000 is assumed.  
-
-.. note::
-    lasblock will always write out a myfile.las.kdx file name by default, 
-    but you can override the output name with a ``-o`` command-line switch.
-
-Arguments
-------------------------------------------------------------------------------
-
-::
-
-    Allowed lasblock options:
-      -h [ --help ]                 Produce this help message
-      -c [ --capacity ] arg (=3000) Number of points to nominally put into each 
-                                    block (note that this number will not be exact)
-      -p [ --precision ] arg (=8)   Number of decimal points to write for each bbox
-      -i [ --input ] arg            input LAS file
-      -o [ --output ] arg           The output .kdx file (defaults to input 
-                                    filename + .kdx)
-      -v [ --verbose ]              Verbose message output
-
-
-
-
-.. figure:: ../images/lasblock_small.png
-    :alt: lasblock output
-
-.. figure:: ../images/lasblock_big.png
-    :alt: lasblock output
-
-
-Format
-------------------------------------------------------------------------------
-
-lasblock's format is quite simple.  It contains an id, a point count, a 2d block, and 
-a list of all the point ids that exist within that block in a simple text file.
-These files are called ``.kdx`` files for :ref:`las2oci` to be able to 
-consume, but there's nothing preventing you from giving them your own name.
-
-::
-
-    id count minx miny maxx maxy {id1 id2 ... idx}
-    0 9686 630250 4834500 630305.47 4834543.1 41357 ...
-    1 9686 630250.01 4834543.1 630305.47 4834617.4 210093 ...
-
-.. _`Oracle Point Cloud`: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28400/sdo_pc_pkg_ref.htm
-
diff --git a/doc/utilities/lasdiff.txt b/doc/utilities/lasdiff.txt
deleted file mode 100644
index 881e850..0000000
--- a/doc/utilities/lasdiff.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-.. raw:: pdf
-
-    PageBreak
-    
-.. _lasdiff:
-
-****************************************************************
-  lasdiff
-****************************************************************
-
-:Author: Martin Isenburg
-:Contact: isenburg at cs.unc.edu
-
-
-lasdiff compares two LAS files and reports whether they are identical 
-or whether they are different.
-
-Usage
------
-
-::
-
-    C:\lastools\bin>lasdiff  -h
-    usage:
-    lasdiff lidar1.las lidar2.las
-    lasdiff lidar1.las lidar1.laz
-    lasdiff -i lidar1.las -i lidar1.laz
-    lasdiff -h
diff --git a/doc/utilities/lasmerge.txt b/doc/utilities/lasmerge.txt
deleted file mode 100644
index c790f50..0000000
--- a/doc/utilities/lasmerge.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-.. raw:: pdf
-
-    PageBreak
-    
-.. _lasmerge:
-    
-****************************************************************
-  lasmerge: merge multiple LAS files into a single file
-****************************************************************
-
-:Author: Martin Isenburg
-:Contact: isenburg at cs.unc.edu
-
-    
-lasmerge reads multiple LIDAR data files in the LAS format and merges them 
-into a single file. The filenames can either be provided one by one or in 
-form of a text file.
-
-All the header information of the first file provided is used including 
-variable and user_defined headers. but some records are updated by 
-integrating the corresponding information from other headers. these are:
-
-* number_of_point_records
-* number_of_points_by_return[5]
-* max_x, min_x, max_y, min_y, max_z, and min_z
-
-In addition x_scale_factor, y_scale_factor, z_scale_factor may need to be 
-increased to accommodate a possibly larger bounding box. The user can 
-also set those in the command line with
-
-  -scale 0.01     or     -scale_xyz  0.01 0.01 0.001
-
-Similarly a new offset can be specified
-
-  -xyz_offset 63025000 483450000 0
-
-Usage
------
-
-::
-
-  $ lasmerge -i in1.las -i in2.las -i in3.las -o out.las
-
-merge the three inX.las files into one out.las file. 
-
-::
-
-  $ lasmerge -i las_file_list.txt -o out.las
-
-merges all LAS files listed in the text file into one out.las file
-
-::
-
-  $ lasmerge -i las_file_list.txt -o out.las -scale 0.01 -verbose
-
-merges the file and stores the LIDAR points with 0.01 accuracy in x, y, and 
-z and prints out control information.
-
-::
-
-  $ lasmerge -i las_file_list.txt -o out.las -scale_xyz 0.01 0.01 0.001
-
-same but with a different accuracy for z.
-
-Help
-~~~~
-
-::
-
-    C:\lastools\bin>lasmerge -h
-    usage:
-    lasmerge -i lasfiles.txt -o out.las
-    lasmerge -i file1.las -i file2.las -i file3.las -o out.las
-    lasmerge -i file1.las -i file2.las -olas > out.las
-    lasmerge -i lasfiles.txt -scale 0.01 -verbose -o out.las
-    lasmerge -h
diff --git a/include/liblas/external/property_tree/detail/rapidxml.hpp b/include/liblas/external/property_tree/detail/rapidxml.hpp
index a6e9cd4..985081d 100644
--- a/include/liblas/external/property_tree/detail/rapidxml.hpp
+++ b/include/liblas/external/property_tree/detail/rapidxml.hpp
@@ -1,2571 +1,2571 @@
-// ----------------------------------------------------------------------------
-// Copyright (C) 2006, 2009 Marcin Kalicinski
-//
-// Distributed under the Boost Software License, Version 1.0. 
-// (See accompanying file LICENSE_1_0.txt or copy at 
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// For more information, see www.boost.org
-// ----------------------------------------------------------------------------
-#ifndef LIBLAS_BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
-#define LIBLAS_BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
-
-//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
-
-#include <cstdlib>      // For std::size_t
-#include <cassert>      // For assert
-#include <new>          // For placement new
-
-// On MSVC, disable "conditional expression is constant" warning (level 4). 
-// This warning is almost impossible to avoid with certain types of templated code
-#ifdef _MSC_VER
-    #pragma warning(push)
-    #pragma warning(disable:4127)   // Conditional expression is constant
-#endif
-
-///////////////////////////////////////////////////////////////////////////
-// BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
-    
-#include <exception>    // For std::exception
-
-#define BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
-
-namespace liblas { namespace property_tree { namespace detail {namespace rapidxml
-{
-
-    //! Parse error exception. 
-    //! This exception is thrown by the parser when an error occurs. 
-    //! Use what() function to get human-readable error message. 
-    //! Use where() function to get a pointer to position within source text where error was detected.
-    //! <br><br>
-    //! If throwing exceptions by the parser is undesirable, 
-    //! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.
-    //! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.
-    //! This function must be defined by the user.
-    //! <br><br>
-    //! This class derives from <code>std::exception</code> class.
-    class parse_error: public std::exception
-    {
-    
-    public:
-    
-        //! Constructs parse error
-        parse_error(const char *wa, void *we)
-            : m_what(wa)
-            , m_where(we)
-        {
-        }
-
-        //! Gets human readable description of error.
-        //! \return Pointer to null terminated description of the error.
-        virtual const char *what() const throw()
-        {
-            return m_what;
-        }
-
-        //! Gets pointer to character data where error happened.
-        //! Ch should be the same as char type of xml_document that produced the error.
-        //! \return Pointer to location within the parsed string where error occured.
-        template<class Ch>
-        Ch *where() const
-        {
-            return reinterpret_cast<Ch *>(m_where);
-        }
-
-    private:  
-
-        const char *m_what;
-        void *m_where;
-
-    };
-}}}}
-
-///////////////////////////////////////////////////////////////////////////
-// Pool sizes
-
-#ifndef BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE
-    // Size of static memory block of memory_pool.
-    // Define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
-    // No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
-    #define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
-#endif
-
-#ifndef BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE
-    // Size of dynamic memory block of memory_pool.
-    // Define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
-    // After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
-    #define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
-#endif
-
-#ifndef BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT
-    // Memory allocation alignment.
-    // Define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
-    // All memory allocations for nodes, attributes and strings will be aligned to this value.
-    // This must be a power of 2 and at least 1, otherwise memory_pool will not work.
-    #define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT sizeof(void *)
-#endif
-
-namespace liblas { namespace property_tree { namespace detail {namespace rapidxml
-{
-    // Forward declarations
-    template<class Ch> class xml_node;
-    template<class Ch> class xml_attribute;
-    template<class Ch> class xml_document;
-    
-    //! Enumeration listing all node types produced by the parser.
-    //! Use xml_node::type() function to query node type.
-    enum node_type
-    {
-        node_document,      //!< A document node. Name and value are empty.
-        node_element,       //!< An element node. Name contains element name. Value contains text of first data node.
-        node_data,          //!< A data node. Name is empty. Value contains data text.
-        node_cdata,         //!< A CDATA node. Name is empty. Value contains data text.
-        node_comment,       //!< A comment node. Name is empty. Value contains comment text.
-        node_declaration,   //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
-        node_doctype,       //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
-        node_pi             //!< A PI node. Name contains target. Value contains instructions.
-    };
-
-    ///////////////////////////////////////////////////////////////////////
-    // Parsing flags
-
-    //! Parse flag instructing the parser to not create data nodes. 
-    //! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_no_data_nodes = 0x1;            
-
-    //! Parse flag instructing the parser to not use text of first data node as a value of parent element.
-    //! Can be combined with other flags by use of | operator.
-    //! Note that child data nodes of element node take precendence over its value when printing. 
-    //! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.
-    //! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_no_element_values = 0x2;
-    
-    //! Parse flag instructing the parser to not place zero terminators after strings in the source text.
-    //! By default zero terminators are placed, modifying source text.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_no_string_terminators = 0x4;
-    
-    //! Parse flag instructing the parser to not translate entities in the source text.
-    //! By default entities are translated, modifying source text.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_no_entity_translation = 0x8;
-    
-    //! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.
-    //! By default, UTF-8 handling is enabled.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_no_utf8 = 0x10;
-    
-    //! Parse flag instructing the parser to create XML declaration node.
-    //! By default, declaration node is not created.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_declaration_node = 0x20;
-    
-    //! Parse flag instructing the parser to create comments nodes.
-    //! By default, comment nodes are not created.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_comment_nodes = 0x40;
-    
-    //! Parse flag instructing the parser to create DOCTYPE node.
-    //! By default, doctype node is not created.
-    //! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_doctype_node = 0x80;
-    
-    //! Parse flag instructing the parser to create PI nodes.
-    //! By default, PI nodes are not created.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_pi_nodes = 0x100;
-    
-    //! Parse flag instructing the parser to validate closing tag names. 
-    //! If not set, name inside closing tag is irrelevant to the parser.
-    //! By default, closing tags are not validated.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_validate_closing_tags = 0x200;
-    
-    //! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.
-    //! By default, whitespace is not trimmed. 
-    //! This flag does not cause the parser to modify source text.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_trim_whitespace = 0x400;
-
-    //! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.
-    //! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.
-    //! By default, whitespace is not normalized. 
-    //! If this flag is specified, source text will be modified.
-    //! Can be combined with other flags by use of | operator.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_normalize_whitespace = 0x800;
-
-    // Compound flags
-    
-    //! Parse flags which represent default behaviour of the parser. 
-    //! This is always equal to 0, so that all other flags can be simply ored together.
-    //! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.
-    //! This also means that meaning of each flag is a <i>negation</i> of the default setting. 
-    //! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,
-    //! and using the flag will disable it.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_default = 0;
-    
-    //! A combination of parse flags that forbids any modifications of the source text. 
-    //! This also results in faster parsing. However, note that the following will occur:
-    //! <ul>
-    //! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>
-    //! <li>entities will not be translated</li>
-    //! <li>whitespace will not be normalized</li>
-    //! </ul>
-    //! See xml_document::parse() function.
-    const int parse_non_destructive = parse_no_string_terminators | parse_no_entity_translation;
-    
-    //! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_fastest = parse_non_destructive | parse_no_data_nodes;
-    
-    //! A combination of parse flags resulting in largest amount of data being extracted. 
-    //! This usually results in slowest parsing.
-    //! <br><br>
-    //! See xml_document::parse() function.
-    const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;
-
-    ///////////////////////////////////////////////////////////////////////
-    // Internals
-
-    //! \cond internal
-    namespace internal
-    {
-
-        // Struct that contains lookup tables for the parser
-        // It must be a template to allow correct linking (because it has static data members, which are defined in a header file).
-        template<int Dummy>
-        struct lookup_tables
-        {
-            static const unsigned char lookup_whitespace[256];              // Whitespace table
-            static const unsigned char lookup_node_name[256];               // Node name table
-            static const unsigned char lookup_text[256];                    // Text table
-            static const unsigned char lookup_text_pure_no_ws[256];         // Text table
-            static const unsigned char lookup_text_pure_with_ws[256];       // Text table
-            static const unsigned char lookup_attribute_name[256];          // Attribute name table
-            static const unsigned char lookup_attribute_data_1[256];        // Attribute data table with single quote
-            static const unsigned char lookup_attribute_data_1_pure[256];   // Attribute data table with single quote
-            static const unsigned char lookup_attribute_data_2[256];        // Attribute data table with double quotes
-            static const unsigned char lookup_attribute_data_2_pure[256];   // Attribute data table with double quotes
-            static const unsigned char lookup_digits[256];                  // Digits
-            static const unsigned char lookup_upcase[256];                  // To uppercase conversion table for ASCII characters
-        };
-
-        // Find length of the string
-        template<class Ch>
-        inline std::size_t measure(const Ch *p)
-        {
-            const Ch *tmp = p;
-            while (*tmp) 
-                ++tmp;
-            return tmp - p;
-        }
-
-        // Compare strings for equality
-        template<class Ch>
-        inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2, std::size_t size2, bool case_sensitive)
-        {
-            if (size1 != size2)
-                return false;
-            if (case_sensitive)
-            {
-                for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
-                    if (*p1 != *p2)
-                        return false;
-            }
-            else
-            {
-                for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
-                    if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)] != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])
-                        return false;
-            }
-            return true;
-        }
-    }
-    //! \endcond
-
-    ///////////////////////////////////////////////////////////////////////
-    // Memory pool
-    
-    //! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.
-    //! In most cases, you will not need to use this class directly. 
-    //! However, if you need to create nodes manually or modify names/values of nodes, 
-    //! you are encouraged to use memory_pool of relevant xml_document to allocate the memory. 
-    //! Not only is this faster than allocating them by using <code>new</code> operator, 
-    //! but also their lifetime will be tied to the lifetime of document, 
-    //! possibly simplyfing memory management. 
-    //! <br><br>
-    //! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool. 
-    //! You can also call allocate_string() function to allocate strings.
-    //! Such strings can then be used as names or values of nodes without worrying about their lifetime.
-    //! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called, 
-    //! or when the pool is destroyed.
-    //! <br><br>
-    //! It is also possible to create a standalone memory_pool, and use it 
-    //! to allocate nodes, whose lifetime will not be tied to any document.
-    //! <br><br>
-    //! Pool maintains <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory. 
-    //! Until static memory is exhausted, no dynamic memory allocations are done.
-    //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
-    //! by using global <code>new[]</code> and <code>delete[]</code> operators. 
-    //! This behaviour can be changed by setting custom allocation routines. 
-    //! Use set_allocator() function to set them.
-    //! <br><br>
-    //! Allocations for nodes, attributes and strings are aligned at <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> bytes.
-    //! This value defaults to the size of pointer on target architecture.
-    //! <br><br>
-    //! To obtain absolutely top performance from the parser,
-    //! it is important that all nodes are allocated from a single, contiguous block of memory.
-    //! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
-    //! If required, you can tweak <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code>, <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> 
-    //! to obtain best wasted memory to performance compromise.
-    //! To do it, define their values before rapidxml.hpp file is included.
-    //! \param Ch Character type of created nodes. 
-    template<class Ch = char>
-    class memory_pool
-    {
-        
-    public:
-
-        //! \cond internal
-        typedef void *(alloc_func)(std::size_t);       // Type of user-defined function used to allocate memory
-        typedef void (free_func)(void *);              // Type of user-defined function used to free memory
-        //! \endcond
-        
-        //! Constructs empty pool with default allocator functions.
-        memory_pool()
-            : m_alloc_func(0)
-            , m_free_func(0)
-        {
-            init();
-        }
-
-        //! Destroys pool and frees all the memory. 
-        //! This causes memory occupied by nodes allocated by the pool to be freed.
-        //! Nodes allocated from the pool are no longer valid.
-        ~memory_pool()
-        {
-            clear();
-        }
-
-        //! Allocates a new node from the pool, and optionally assigns name and value to it. 
-        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
-        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
-        //! will call rapidxml::parse_error_handler() function.
-        //! \param type Type of node to create.
-        //! \param name Name to assign to the node, or 0 to assign no name.
-        //! \param value Value to assign to the node, or 0 to assign no value.
-        //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
-        //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
-        //! \return Pointer to allocated node. This pointer will never be NULL.
-        xml_node<Ch> *allocate_node(node_type type, 
-                                    const Ch *name = 0, const Ch *value = 0, 
-                                    std::size_t name_size = 0, std::size_t value_size = 0)
-        {
-            void *memory = allocate_aligned(sizeof(xml_node<Ch>));
-            xml_node<Ch> *node = new(memory) xml_node<Ch>(type);
-            if (name)
-            {
-                if (name_size > 0)
-                    node->name(name, name_size);
-                else
-                    node->name(name);
-            }
-            if (value)
-            {
-                if (value_size > 0)
-                    node->value(value, value_size);
-                else
-                    node->value(value);
-            }
-            return node;
-        }
-
-        //! Allocates a new attribute from the pool, and optionally assigns name and value to it.
-        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
-        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
-        //! will call rapidxml::parse_error_handler() function.
-        //! \param name Name to assign to the attribute, or 0 to assign no name.
-        //! \param value Value to assign to the attribute, or 0 to assign no value.
-        //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
-        //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
-        //! \return Pointer to allocated attribute. This pointer will never be NULL.
-        xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0, 
-                                              std::size_t name_size = 0, std::size_t value_size = 0)
-        {
-            void *memory = allocate_aligned(sizeof(xml_attribute<Ch>));
-            xml_attribute<Ch> *attribute = new(memory) xml_attribute<Ch>;
-            if (name)
-            {
-                if (name_size > 0)
-                    attribute->name(name, name_size);
-                else
-                    attribute->name(name);
-            }
-            if (value)
-            {
-                if (value_size > 0)
-                    attribute->value(value, value_size);
-                else
-                    attribute->value(value);
-            }
-            return attribute;
-        }
-
-        //! Allocates a char array of given size from the pool, and optionally copies a given string to it.
-        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
-        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
-        //! will call rapidxml::parse_error_handler() function.
-        //! \param source String to initialize the allocated memory with, or 0 to not initialize it.
-        //! \param size Number of characters to allocate, or zero to calculate it automatically from source string length; if size is 0, source string must be specified and null terminated.
-        //! \return Pointer to allocated char array. This pointer will never be NULL.
-        Ch *allocate_string(const Ch *source = 0, std::size_t size = 0)
-        {
-            assert(source || size);     // Either source or size (or both) must be specified
-            if (size == 0)
-                size = internal::measure(source) + 1;
-            Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));
-            if (source)
-                for (std::size_t i = 0; i < size; ++i)
-                    result[i] = source[i];
-            return result;
-        }
-
-        //! Clones an xml_node and its hierarchy of child nodes and attributes.
-        //! Nodes and attributes are allocated from this memory pool.
-        //! Names and values are not cloned, they are shared between the clone and the source.
-        //! Result node can be optionally specified as a second parameter, 
-        //! in which case its contents will be replaced with cloned source node.
-        //! This is useful when you want to clone entire document.
-        //! \param source Node to clone.
-        //! \param result Node to put results in, or 0 to automatically allocate result node
-        //! \return Pointer to cloned node. This pointer will never be NULL.
-        xml_node<Ch> *clone_node(const xml_node<Ch> *source, xml_node<Ch> *result = 0)
-        {
-            // Prepare result node
-            if (result)
-            {
-                result->remove_all_attributes();
-                result->remove_all_nodes();
-                result->type(source->type());
-            }
-            else
-                result = allocate_node(source->type());
-
-            // Clone name and value
-            result->name(source->name(), source->name_size());
-            result->value(source->value(), source->value_size());
-
-            // Clone child nodes and attributes
-            for (xml_node<Ch> *child = source->first_node(); child; child = child->next_sibling())
-                result->append_node(clone_node(child));
-            for (xml_attribute<Ch> *attr = source->first_attribute(); attr; attr = attr->next_attribute())
-                result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size()));
-
-            return result;
-        }
-
-        //! Clears the pool. 
-        //! This causes memory occupied by nodes allocated by the pool to be freed.
-        //! Any nodes or strings allocated from the pool will no longer be valid.
-        void clear()
-        {
-            while (m_begin != m_static_memory)
-            {
-                char *previous_begin = reinterpret_cast<header *>(align(m_begin))->previous_begin;
-                if (m_free_func)
-                    m_free_func(m_begin);
-                else
-                    delete[] m_begin;
-                m_begin = previous_begin;
-            }
-            init();
-        }
-
-        //! Sets or resets the user-defined memory allocation functions for the pool.
-        //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.
-        //! Allocation function must not return invalid pointer on failure. It should either throw,
-        //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program. 
-        //! If it returns invalid pointer, results are undefined.
-        //! <br><br>
-        //! User defined allocation functions must have the following forms:
-        //! <br><code>
-        //! <br>void *allocate(std::size_t size);
-        //! <br>void free(void *pointer);
-        //! </code><br>
-        //! \param af Allocation function, or 0 to restore default function
-        //! \param ff Free function, or 0 to restore default function
-        void set_allocator(alloc_func *af, free_func *ff)
-        {
-            assert(m_begin == m_static_memory && m_ptr == align(m_begin));    // Verify that no memory is allocated yet
-            m_alloc_func = af;
-            m_free_func = ff;
-        }
-
-    private:
-
-        struct header
-        {
-            char *previous_begin;
-        };
-
-        void init()
-        {
-            m_begin = m_static_memory;
-            m_ptr = align(m_begin);
-            m_end = m_static_memory + sizeof(m_static_memory);
-        }
-        
-        char *align(char *ptr)
-        {
-            std::size_t alignment = ((BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1))) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1));
-            return ptr + alignment;
-        }
-        
-        char *allocate_raw(std::size_t size)
-        {
-            // Allocate
-            void *memory;   
-            if (m_alloc_func)   // Allocate memory using either user-specified allocation function or global operator new[]
-            {
-                memory = m_alloc_func(size);
-                assert(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp
-            }
-            else
-            {
-                memory = new char[size];
-            }
-            return static_cast<char *>(memory);
-        }
-        
-        void *allocate_aligned(std::size_t size)
-        {
-            // Calculate aligned pointer
-            char *result = align(m_ptr);
-
-            // If not enough memory left in current pool, allocate a new pool
-            if (result + size > m_end)
-            {
-                // Calculate required pool size (may be bigger than BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE)
-                std::size_t pool_size = BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE;
-                if (pool_size < size)
-                    pool_size = size;
-                
-                // Allocate
-                std::size_t alloc_size = sizeof(header) + (2 * BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 2) + pool_size;     // 2 alignments required in worst case: one for header, one for actual allocation
-                char *raw_memory = allocate_raw(alloc_size);
-                    
-                // Setup new pool in allocated memory
-                char *pool = align(raw_memory);
-                header *new_header = reinterpret_cast<header *>(pool);
-                new_header->previous_begin = m_begin;
-                m_begin = raw_memory;
-                m_ptr = pool + sizeof(header);
-                m_end = raw_memory + alloc_size;
-
-                // Calculate aligned pointer again using new pool
-                result = align(m_ptr);
-            }
-
-            // Update pool and return aligned pointer
-            m_ptr = result + size;
-            return result;
-        }
-
-        char *m_begin;                                      // Start of raw memory making up current pool
-        char *m_ptr;                                        // First free byte in current pool
-        char *m_end;                                        // One past last available byte in current pool
-        char m_static_memory[BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE];    // Static raw memory
-        alloc_func *m_alloc_func;                           // Allocator function, or 0 if default is to be used
-        free_func *m_free_func;                             // Free function, or 0 if default is to be used
-    };
-
-    ///////////////////////////////////////////////////////////////////////////
-    // XML base
-
-    //! Base class for xml_node and xml_attribute implementing common functions: 
-    //! name(), name_size(), value(), value_size() and parent().
-    //! \param Ch Character type to use
-    template<class Ch = char>
-    class xml_base
-    {
-
-    public:
-        
-        ///////////////////////////////////////////////////////////////////////////
-        // Construction & destruction
-    
-        // Construct a base with empty name, value and parent
-        xml_base()
-            : m_name(0)
-            , m_value(0)
-            , m_parent(0)
-        {
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Node data access
-    
-        //! Gets name of the node. 
-        //! Interpretation of name depends on type of node.
-        //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
-        //! <br><br>
-        //! Use name_size() function to determine length of the name.
-        //! \return Name of node, or empty string if node has no name.
-        Ch *name() const
-        {
-            return m_name ? m_name : nullstr();
-        }
-
-        //! Gets size of node name, not including terminator character.
-        //! This function works correctly irrespective of whether name is or is not zero terminated.
-        //! \return Size of node name, in characters.
-        std::size_t name_size() const
-        {
-            return m_name ? m_name_size : 0;
-        }
-
-        //! Gets value of node. 
-        //! Interpretation of value depends on type of node.
-        //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
-        //! <br><br>
-        //! Use value_size() function to determine length of the value.
-        //! \return Value of node, or empty string if node has no value.
-        Ch *value() const
-        {
-            return m_value ? m_value : nullstr();
-        }
-
-        //! Gets size of node value, not including terminator character.
-        //! This function works correctly irrespective of whether value is or is not zero terminated.
-        //! \return Size of node value, in characters.
-        std::size_t value_size() const
-        {
-            return m_value ? m_value_size : 0;
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Node modification
-    
-        //! Sets name of node to a non zero-terminated string.
-        //! See \ref ownership_of_strings.
-        //! <br><br>
-        //! Note that node does not own its name or value, it only stores a pointer to it. 
-        //! It will not delete or otherwise free the pointer on destruction.
-        //! It is reponsibility of the user to properly manage lifetime of the string.
-        //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
-        //! on destruction of the document the string will be automatically freed.
-        //! <br><br>
-        //! Size of name must be specified separately, because name does not have to be zero terminated.
-        //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).
-        //! \param n Name of node to set. Does not have to be zero terminated.
-        //! \param size Size of name, in characters. This does not include zero terminator, if one is present.
-        void name(const Ch *n, std::size_t size)
-        {
-            m_name = const_cast<Ch *>(n);
-            m_name_size = size;
-        }
-
-        //! Sets name of node to a zero-terminated string.
-        //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).
-        //! \param n Name of node to set. Must be zero terminated.
-        void name(const Ch *n)
-        {
-            name(n, internal::measure(n));
-        }
-
-        //! Sets value of node to a non zero-terminated string.
-        //! See \ref ownership_of_strings.
-        //! <br><br>
-        //! Note that node does not own its name or value, it only stores a pointer to it. 
-        //! It will not delete or otherwise free the pointer on destruction.
-        //! It is reponsibility of the user to properly manage lifetime of the string.
-        //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
-        //! on destruction of the document the string will be automatically freed.
-        //! <br><br>
-        //! Size of value must be specified separately, because it does not have to be zero terminated.
-        //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).
-        //! <br><br>
-        //! If an element has a child node of type node_data, it will take precedence over element value when printing.
-        //! If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser.
-        //! \param val value of node to set. Does not have to be zero terminated.
-        //! \param size Size of value, in characters. This does not include zero terminator, if one is present.
-        void value(const Ch *val, std::size_t size)
-        {
-            m_value = const_cast<Ch *>(val);
-            m_value_size = size;
-        }
-
-        //! Sets value of node to a zero-terminated string.
-        //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).
-        //! \param val Vame of node to set. Must be zero terminated.
-        void value(const Ch *val)
-        {
-            this->value(val, internal::measure(val));
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Related nodes access
-    
-        //! Gets node parent.
-        //! \return Pointer to parent node, or 0 if there is no parent.
-        xml_node<Ch> *parent() const
-        {
-            return m_parent;
-        }
-
-    protected:
-
-        // Return empty string
-        static Ch *nullstr()
-        {
-            static Ch zero = Ch('\0');
-            return &zero;
-        }
-
-        Ch *m_name;                         // Name of node, or 0 if no name
-        Ch *m_value;                        // Value of node, or 0 if no value
-        std::size_t m_name_size;            // Length of node name, or undefined of no name
-        std::size_t m_value_size;           // Length of node value, or undefined if no value
-        xml_node<Ch> *m_parent;             // Pointer to parent node, or 0 if none
-
-    };
-
-    //! Class representing attribute node of XML document. 
-    //! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).
-    //! Note that after parse, both name and value of attribute will point to interior of source text used for parsing. 
-    //! Thus, this text must persist in memory for the lifetime of attribute.
-    //! \param Ch Character type to use.
-    template<class Ch = char>
-    class xml_attribute: public xml_base<Ch>
-    {
-
-        friend class xml_node<Ch>;
-    
-    public:
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Construction & destruction
-    
-        //! Constructs an empty attribute with the specified type. 
-        //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.
-        xml_attribute()
-        {
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Related nodes access
-    
-        //! Gets document of which attribute is a child.
-        //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.
-        xml_document<Ch> *document() const
-        {
-            if (xml_node<Ch> *node = this->parent())
-            {
-                while (node->parent())
-                    node = node->parent();
-                return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
-            }
-            else
-                return 0;
-        }
-
-        //! Gets previous attribute, optionally matching attribute name. 
-        //! \param n Name of attribute to find, or 0 to return previous attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found attribute, or 0 if not found.
-        xml_attribute<Ch> *previous_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute; attribute = attribute->m_prev_attribute)
-                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
-                        return attribute;
-                return 0;
-            }
-            else
-                return this->m_parent ? m_prev_attribute : 0;
-        }
-
-        //! Gets next attribute, optionally matching attribute name. 
-        //! \param n Name of attribute to find, or 0 to return next attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found attribute, or 0 if not found.
-        xml_attribute<Ch> *next_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_attribute<Ch> *attribute = m_next_attribute; attribute; attribute = attribute->m_next_attribute)
-                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
-                        return attribute;
-                return 0;
-            }
-            else
-                return this->m_parent ? m_next_attribute : 0;
-        }
-
-    private:
-
-        xml_attribute<Ch> *m_prev_attribute;        // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero
-        xml_attribute<Ch> *m_next_attribute;        // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero
-    
-    };
-
-    ///////////////////////////////////////////////////////////////////////////
-    // XML node
-
-    //! Class representing a node of XML document. 
-    //! Each node may have associated name and value strings, which are available through name() and value() functions. 
-    //! Interpretation of name and value depends on type of the node.
-    //! Type of node can be determined by using type() function.
-    //! <br><br>
-    //! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing. 
-    //! Thus, this text must persist in the memory for the lifetime of node.
-    //! \param Ch Character type to use.
-    template<class Ch = char>
-    class xml_node: public xml_base<Ch>
-    {
-
-    public:
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Construction & destruction
-    
-        //! Constructs an empty node with the specified type. 
-        //! Consider using memory_pool of appropriate document to allocate nodes manually.
-        //! \param t Type of node to construct.
-        xml_node(node_type t)
-            : m_type(t)
-            , m_first_node(0)
-            , m_first_attribute(0)
-        {
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Node data access
-    
-        //! Gets type of node.
-        //! \return Type of node.
-        node_type type() const
-        {
-            return m_type;
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Related nodes access
-    
-        //! Gets document of which node is a child.
-        //! \return Pointer to document that contains this node, or 0 if there is no parent document.
-        xml_document<Ch> *document() const
-        {
-            xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);
-            while (node->parent())
-                node = node->parent();
-            return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
-        }
-
-        //! Gets first child node, optionally matching node name.
-        //! \param n Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found child, or 0 if not found.
-        xml_node<Ch> *first_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_node<Ch> *child = m_first_node; child; child = child->next_sibling())
-                    if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
-                        return child;
-                return 0;
-            }
-            else
-                return m_first_node;
-        }
-
-        //! Gets last child node, optionally matching node name. 
-        //! Behaviour is undefined if node has no children.
-        //! Use first_node() to test if node has children.
-        //! \param n Name of child to find, or 0 to return last child regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found child, or 0 if not found.
-        xml_node<Ch> *last_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            assert(m_first_node);  // Cannot query for last child if node has no children
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_node<Ch> *child = m_last_node; child; child = child->previous_sibling())
-                    if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
-                        return child;
-                return 0;
-            }
-            else
-                return m_last_node;
-        }
-
-        //! Gets previous sibling node, optionally matching node name. 
-        //! Behaviour is undefined if node has no parent.
-        //! Use parent() to test if node has a parent.
-        //! \param n Name of sibling to find, or 0 to return previous sibling regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found sibling, or 0 if not found.
-        xml_node<Ch> *previous_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            assert(this->m_parent);     // Cannot query for siblings if node has no parent
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_node<Ch> *sibling = m_prev_sibling; sibling; sibling = sibling->m_prev_sibling)
-                    if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
-                        return sibling;
-                return 0;
-            }
-            else
-                return m_prev_sibling;
-        }
-
-        //! Gets next sibling node, optionally matching node name. 
-        //! Behaviour is undefined if node has no parent.
-        //! Use parent() to test if node has a parent.
-        //! \param n Name of sibling to find, or 0 to return next sibling regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found sibling, or 0 if not found.
-        xml_node<Ch> *next_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            assert(this->m_parent);     // Cannot query for siblings if node has no parent
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_node<Ch> *sibling = m_next_sibling; sibling; sibling = sibling->m_next_sibling)
-                    if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
-                        return sibling;
-                return 0;
-            }
-            else
-                return m_next_sibling;
-        }
-
-        //! Gets first attribute of node, optionally matching attribute name.
-        //! \param n Name of attribute to find, or 0 to return first attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found attribute, or 0 if not found.
-        xml_attribute<Ch> *first_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_attribute<Ch> *attribute = m_first_attribute; attribute; attribute = attribute->m_next_attribute)
-                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
-                        return attribute;
-                return 0;
-            }
-            else
-                return m_first_attribute;
-        }
-
-        //! Gets last attribute of node, optionally matching attribute name.
-        //! \param n Name of attribute to find, or 0 to return last attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
-        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
-        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
-        //! \return Pointer to found attribute, or 0 if not found.
-        xml_attribute<Ch> *last_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
-        {
-            if (n)
-            {
-                if (nsize == 0)
-                    nsize = internal::measure(n);
-                for (xml_attribute<Ch> *attribute = m_last_attribute; attribute; attribute = attribute->m_prev_attribute)
-                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
-                        return attribute;
-                return 0;
-            }
-            else
-                return m_first_attribute ? m_last_attribute : 0;
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Node modification
-    
-        //! Sets type of node.
-        //! \param t Type of node to set.
-        void type(node_type t)
-        {
-            m_type = t;
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Node manipulation
-
-        //! Prepends a new child node.
-        //! The prepended child becomes the first child, and all existing children are moved one position back.
-        //! \param child Node to prepend.
-        void prepend_node(xml_node<Ch> *child)
-        {
-            assert(child && !child->parent() && child->type() != node_document);
-            if (first_node())
-            {
-                child->m_next_sibling = m_first_node;
-                m_first_node->m_prev_sibling = child;
-            }
-            else
-            {
-                child->m_next_sibling = 0;
-                m_last_node = child;
-            }
-            m_first_node = child;
-            child->m_parent = this;
-            child->m_prev_sibling = 0;
-        }
-
-        //! Appends a new child node. 
-        //! The appended child becomes the last child.
-        //! \param child Node to append.
-        void append_node(xml_node<Ch> *child)
-        {
-            assert(child && !child->parent() && child->type() != node_document);
-            if (first_node())
-            {
-                child->m_prev_sibling = m_last_node;
-                m_last_node->m_next_sibling = child;
-            }
-            else
-            {
-                child->m_prev_sibling = 0;
-                m_first_node = child;
-            }
-            m_last_node = child;
-            child->m_parent = this;
-            child->m_next_sibling = 0;
-        }
-
-        //! Inserts a new child node at specified place inside the node. 
-        //! All children after and including the specified node are moved one position back.
-        //! \param where Place where to insert the child, or 0 to insert at the back.
-        //! \param child Node to insert.
-        void insert_node(xml_node<Ch> *where, xml_node<Ch> *child)
-        {
-            assert(!where || where->parent() == this);
-            assert(child && !child->parent() && child->type() != node_document);
-            if (where == m_first_node)
-                prepend_node(child);
-            else if (where == 0)
-                append_node(child);
-            else
-            {
-                child->m_prev_sibling = where->m_prev_sibling;
-                child->m_next_sibling = where;
-                where->m_prev_sibling->m_next_sibling = child;
-                where->m_prev_sibling = child;
-                child->m_parent = this;
-            }
-        }
-
-        //! Removes first child node. 
-        //! If node has no children, behaviour is undefined.
-        //! Use first_node() to test if node has children.
-        void remove_first_node()
-        {
-            assert(first_node());
-            xml_node<Ch> *child = m_first_node;
-            m_first_node = child->m_next_sibling;
-            if (child->m_next_sibling)
-                child->m_next_sibling->m_prev_sibling = 0;
-            else
-                m_last_node = 0;
-            child->m_parent = 0;
-        }
-
-        //! Removes last child of the node. 
-        //! If node has no children, behaviour is undefined.
-        //! Use first_node() to test if node has children.
-        void remove_last_node()
-        {
-            assert(first_node());
-            xml_node<Ch> *child = m_last_node;
-            if (child->m_prev_sibling)
-            {
-                m_last_node = child->m_prev_sibling;
-                child->m_prev_sibling->m_next_sibling = 0;
-            }
-            else
-                m_first_node = 0;
-            child->m_parent = 0;
-        }
-
-        //! Removes specified child from the node
-        // \param where Pointer to child to be removed.
-        void remove_node(xml_node<Ch> *where)
-        {
-            assert(where && where->parent() == this);
-            assert(first_node());
-            if (where == m_first_node)
-                remove_first_node();
-            else if (where == m_last_node)
-                remove_last_node();
-            else
-            {
-                where->m_prev_sibling->m_next_sibling = where->m_next_sibling;
-                where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;
-                where->m_parent = 0;
-            }
-        }
-
-        //! Removes all child nodes (but not attributes).
-        void remove_all_nodes()
-        {
-            for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)
-                node->m_parent = 0;
-            m_first_node = 0;
-        }
-
-        //! Prepends a new attribute to the node.
-        //! \param attribute Attribute to prepend.
-        void prepend_attribute(xml_attribute<Ch> *attribute)
-        {
-            assert(attribute && !attribute->parent());
-            if (first_attribute())
-            {
-                attribute->m_next_attribute = m_first_attribute;
-                m_first_attribute->m_prev_attribute = attribute;
-            }
-            else
-            {
-                attribute->m_next_attribute = 0;
-                m_last_attribute = attribute;
-            }
-            m_first_attribute = attribute;
-            attribute->m_parent = this;
-            attribute->m_prev_attribute = 0;
-        }
-
-        //! Appends a new attribute to the node.
-        //! \param attribute Attribute to append.
-        void append_attribute(xml_attribute<Ch> *attribute)
-        {
-            assert(attribute && !attribute->parent());
-            if (first_attribute())
-            {
-                attribute->m_prev_attribute = m_last_attribute;
-                m_last_attribute->m_next_attribute = attribute;
-            }
-            else
-            {
-                attribute->m_prev_attribute = 0;
-                m_first_attribute = attribute;
-            }
-            m_last_attribute = attribute;
-            attribute->m_parent = this;
-            attribute->m_next_attribute = 0;
-        }
-
-        //! Inserts a new attribute at specified place inside the node. 
-        //! All attributes after and including the specified attribute are moved one position back.
-        //! \param where Place where to insert the attribute, or 0 to insert at the back.
-        //! \param attribute Attribute to insert.
-        void insert_attribute(xml_attribute<Ch> *where, xml_attribute<Ch> *attribute)
-        {
-            assert(!where || where->parent() == this);
-            assert(attribute && !attribute->parent());
-            if (where == m_first_attribute)
-                prepend_attribute(attribute);
-            else if (where == 0)
-                append_attribute(attribute);
-            else
-            {
-                attribute->m_prev_attribute = where->m_prev_attribute;
-                attribute->m_next_attribute = where;
-                where->m_prev_attribute->m_next_attribute = attribute;
-                where->m_prev_attribute = attribute;
-                attribute->m_parent = this;
-            }
-        }
-
-        //! Removes first attribute of the node. 
-        //! If node has no attributes, behaviour is undefined.
-        //! Use first_attribute() to test if node has attributes.
-        void remove_first_attribute()
-        {
-            assert(first_attribute());
-            xml_attribute<Ch> *attribute = m_first_attribute;
-            if (attribute->m_next_attribute)
-            {
-                attribute->m_next_attribute->m_prev_attribute = 0;
-            }
-            else
-                m_last_attribute = 0;
-            attribute->m_parent = 0;
-            m_first_attribute = attribute->m_next_attribute;
-        }
-
-        //! Removes last attribute of the node. 
-        //! If node has no attributes, behaviour is undefined.
-        //! Use first_attribute() to test if node has attributes.
-        void remove_last_attribute()
-        {
-            assert(first_attribute());
-            xml_attribute<Ch> *attribute = m_last_attribute;
-            if (attribute->m_prev_attribute)
-            {
-                attribute->m_prev_attribute->m_next_attribute = 0;
-                m_last_attribute = attribute->m_prev_attribute;
-            }
-            else
-                m_first_attribute = 0;
-            attribute->m_parent = 0;
-        }
-
-        //! Removes specified attribute from node.
-        //! \param where Pointer to attribute to be removed.
-        void remove_attribute(xml_attribute<Ch> *where)
-        {
-            assert(first_attribute() && where->parent() == this);
-            if (where == m_first_attribute)
-                remove_first_attribute();
-            else if (where == m_last_attribute)
-                remove_last_attribute();
-            else
-            {
-                where->m_prev_attribute->m_next_attribute = where->m_next_attribute;
-                where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;
-                where->m_parent = 0;
-            }
-        }
-
-        //! Removes all attributes of node.
-        void remove_all_attributes()
-        {
-            for (xml_attribute<Ch> *attribute = first_attribute(); attribute; attribute = attribute->m_next_attribute)
-                attribute->m_parent = 0;
-            m_first_attribute = 0;
-        }
-        
-    private:
-
-        ///////////////////////////////////////////////////////////////////////////
-        // Restrictions
-
-        // No copying
-        xml_node(const xml_node &);
-        void operator =(const xml_node &);
-    
-        ///////////////////////////////////////////////////////////////////////////
-        // Data members
-    
-        // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.
-        // This is required for maximum performance, as it allows the parser to omit initialization of 
-        // unneded/redundant values.
-        //
-        // The rules are as follows:
-        // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively
-        // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage
-        // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage
-
-        node_type m_type;                       // Type of node; always valid
-        xml_node<Ch> *m_first_node;             // Pointer to first child node, or 0 if none; always valid
-        xml_node<Ch> *m_last_node;              // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero
-        xml_attribute<Ch> *m_first_attribute;   // Pointer to first attribute of node, or 0 if none; always valid
-        xml_attribute<Ch> *m_last_attribute;    // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero
-        xml_node<Ch> *m_prev_sibling;           // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
-        xml_node<Ch> *m_next_sibling;           // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
-
-    };
-
-    ///////////////////////////////////////////////////////////////////////////
-    // XML document
-    
-    //! This class represents root of the DOM hierarchy. 
-    //! It is also an xml_node and a memory_pool through public inheritance.
-    //! Use parse() function to build a DOM tree from a zero-terminated XML text string.
-    //! parse() function allocates memory for nodes and attributes by using functions of xml_document, 
-    //! which are inherited from memory_pool.
-    //! To access root node of the document, use the document itself, as if it was an xml_node.
-    //! \param Ch Character type to use.
-    template<class Ch = char>
-    class xml_document: public xml_node<Ch>, public memory_pool<Ch>
-    {
-    
-    public:
-
-        //! Constructs empty XML document
-        xml_document()
-            : xml_node<Ch>(node_document)
-        {
-        }
-
-        //! Parses zero-terminated XML string according to given flags.
-        //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.
-        //! The string must persist for the lifetime of the document.
-        //! In case of error, rapidxml::parse_error exception will be thrown.
-        //! <br><br>
-        //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.
-        //! Make sure that data is zero-terminated.
-        //! <br><br>
-        //! Document can be parsed into multiple times. 
-        //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.
-        //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.
-        template<int Flags>
-        void parse(Ch *text)
-        {
-            assert(text);
-            
-            // Remove current contents
-            this->remove_all_nodes();
-            this->remove_all_attributes();
-            
-            // Parse BOM, if any
-            parse_bom<Flags>(text);
-            
-            // Parse children
-            while (1)
-            {
-                // Skip whitespace before node
-                skip<whitespace_pred, Flags>(text);
-                if (*text == 0)
-                    break;
-
-                // Parse and append new child
-                if (*text == Ch('<'))
-                {
-                    ++text;     // Skip '<'
-                    if (xml_node<Ch> *node = parse_node<Flags>(text))
-                        this->append_node(node);
-                }
-                else
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected <", text);
-            }
-
-        }
-
-        //! Clears the document by deleting all nodes and clearing the memory pool.
-        //! All nodes owned by document pool are destroyed.
-        void clear()
-        {
-            this->remove_all_nodes();
-            this->remove_all_attributes();
-            memory_pool<Ch>::clear();
-        }
-        
-    private:
-
-        ///////////////////////////////////////////////////////////////////////
-        // Internal character utility functions
-        
-        // Detect whitespace character
-        struct whitespace_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_whitespace[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect node name character
-        struct node_name_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_node_name[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect attribute name character
-        struct attribute_name_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_attribute_name[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect text character (PCDATA)
-        struct text_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_text[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect text character (PCDATA) that does not require processing
-        struct text_pure_no_ws_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect text character (PCDATA) that does not require processing
-        struct text_pure_with_ws_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                return internal::lookup_tables<0>::lookup_text_pure_with_ws[static_cast<unsigned char>(ch)];
-            }
-        };
-
-        // Detect attribute value character
-        template<Ch Quote>
-        struct attribute_value_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                if (Quote == Ch('\''))
-                    return internal::lookup_tables<0>::lookup_attribute_data_1[static_cast<unsigned char>(ch)];
-                if (Quote == Ch('\"'))
-                    return internal::lookup_tables<0>::lookup_attribute_data_2[static_cast<unsigned char>(ch)];
-                return 0;       // Should never be executed, to avoid warnings on Comeau
-            }
-        };
-
-        // Detect attribute value character
-        template<Ch Quote>
-        struct attribute_value_pure_pred
-        {
-            static unsigned char test(Ch ch)
-            {
-                if (Quote == Ch('\''))
-                    return internal::lookup_tables<0>::lookup_attribute_data_1_pure[static_cast<unsigned char>(ch)];
-                if (Quote == Ch('\"'))
-                    return internal::lookup_tables<0>::lookup_attribute_data_2_pure[static_cast<unsigned char>(ch)];
-                return 0;       // Should never be executed, to avoid warnings on Comeau
-            }
-        };
-
-        // Insert coded character, using UTF8 or 8-bit ASCII
-        template<int Flags>
-        static void insert_coded_character(Ch *&text, unsigned long code)
-        {
-            if (Flags & parse_no_utf8)
-            {
-                // Insert 8-bit ASCII character
-                // Todo: possibly verify that code is less than 256 and use replacement char otherwise?
-                text[0] = static_cast<unsigned char>(code);
-                text += 1;
-            }
-            else
-            {
-                // Insert UTF8 sequence
-                if (code < 0x80)    // 1 byte sequence
-                {
-                    text[0] = static_cast<unsigned char>(code);
-                    text += 1;
-                }
-                else if (code < 0x800)  // 2 byte sequence
-                {
-                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[0] = static_cast<unsigned char>(code | 0xC0);
-                    text += 2;
-                }
-                else if (code < 0x10000)    // 3 byte sequence
-                {
-                    text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[0] = static_cast<unsigned char>(code | 0xE0);
-                    text += 3;
-                }
-                else if (code < 0x110000)   // 4 byte sequence
-                {
-                    text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
-                    text[0] = static_cast<unsigned char>(code | 0xF0);
-                    text += 4;
-                }
-                else    // Invalid, only codes up to 0x10FFFF are allowed in Unicode
-                {
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
-                }
-            }
-        }
-
-        // Skip characters until predicate evaluates to true
-        template<class StopPred, int Flags>
-        static void skip(Ch *&text)
-        {
-            Ch *tmp = text;
-            while (StopPred::test(*tmp))
-                ++tmp;
-            text = tmp;
-        }
-
-        // Skip characters until predicate evaluates to true while doing the following:
-        // - replacing XML character entity references with proper characters (' & " < > &#...;)
-        // - condensing whitespace sequences to single space character
-        template<class StopPred, class StopPredPure, int Flags>
-        static Ch *skip_and_expand_character_refs(Ch *&text)
-        {
-            // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip
-            if (Flags & parse_no_entity_translation && 
-                !(Flags & parse_normalize_whitespace) &&
-                !(Flags & parse_trim_whitespace))
-            {
-                skip<StopPred, Flags>(text);
-                return text;
-            }
-            
-            // Use simple skip until first modification is detected
-            skip<StopPredPure, Flags>(text);
-
-            // Use translation skip
-            Ch *src = text;
-            Ch *dest = src;
-            while (StopPred::test(*src))
-            {
-                // If entity translation is enabled    
-                if (!(Flags & parse_no_entity_translation))
-                {
-                    // Test if replacement is needed
-                    if (src[0] == Ch('&'))
-                    {
-                        switch (src[1])
-                        {
-
-                        // & '
-                        case Ch('a'): 
-                            if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';'))
-                            {
-                                *dest = Ch('&');
-                                ++dest;
-                                src += 5;
-                                continue;
-                            }
-                            if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s') && src[5] == Ch(';'))
-                            {
-                                *dest = Ch('\'');
-                                ++dest;
-                                src += 6;
-                                continue;
-                            }
-                            break;
-
-                        // "
-                        case Ch('q'): 
-                            if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t') && src[5] == Ch(';'))
-                            {
-                                *dest = Ch('"');
-                                ++dest;
-                                src += 6;
-                                continue;
-                            }
-                            break;
-
-                        // >
-                        case Ch('g'): 
-                            if (src[2] == Ch('t') && src[3] == Ch(';'))
-                            {
-                                *dest = Ch('>');
-                                ++dest;
-                                src += 4;
-                                continue;
-                            }
-                            break;
-
-                        // <
-                        case Ch('l'): 
-                            if (src[2] == Ch('t') && src[3] == Ch(';'))
-                            {
-                                *dest = Ch('<');
-                                ++dest;
-                                src += 4;
-                                continue;
-                            }
-                            break;
-
-                        // &#...; - assumes ASCII
-                        case Ch('#'): 
-                            if (src[2] == Ch('x'))
-                            {
-                                unsigned long code = 0;
-                                src += 3;   // Skip &#x
-                                while (1)
-                                {
-                                    unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
-                                    if (digit == 0xFF)
-                                        break;
-                                    code = code * 16 + digit;
-                                    ++src;
-                                }
-                                insert_coded_character<Flags>(dest, code);    // Put character in output
-                            }
-                            else
-                            {
-                                unsigned long code = 0;
-                                src += 2;   // Skip &#
-                                while (1)
-                                {
-                                    unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
-                                    if (digit == 0xFF)
-                                        break;
-                                    code = code * 10 + digit;
-                                    ++src;
-                                }
-                                insert_coded_character<Flags>(dest, code);    // Put character in output
-                            }
-                            if (*src == Ch(';'))
-                                ++src;
-                            else
-                                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ;", src);
-                            continue;
-
-                        // Something else
-                        default:
-                            // Ignore, just copy '&' verbatim
-                            break;
-
-                        }
-                    }
-                }
-                
-                // If whitespace condensing is enabled
-                if (Flags & parse_normalize_whitespace)
-                {
-                    // Test if condensing is needed                 
-                    if (whitespace_pred::test(*src))
-                    {
-                        *dest = Ch(' '); ++dest;    // Put single space in dest
-                        ++src;                      // Skip first whitespace char
-                        // Skip remaining whitespace chars
-                        while (whitespace_pred::test(*src))
-                            ++src;
-                        continue;
-                    }
-                }
-
-                // No replacement, only copy character
-                *dest++ = *src++;
-
-            }
-
-            // Return new end
-            text = src;
-            return dest;
-
-        }
-
-        ///////////////////////////////////////////////////////////////////////
-        // Internal parsing functions
-        
-        // Parse BOM, if any
-        template<int Flags>
-        void parse_bom(Ch *&text)
-        {
-            // UTF-8?
-            if (static_cast<unsigned char>(text[0]) == 0xEF && 
-                static_cast<unsigned char>(text[1]) == 0xBB && 
-                static_cast<unsigned char>(text[2]) == 0xBF)
-            {
-                text += 3;      // Skip utf-8 bom
-            }
-        }
-
-        // Parse XML declaration (<?xml...)
-        template<int Flags>
-        xml_node<Ch> *parse_xml_declaration(Ch *&text)
-        {
-            // If parsing of declaration is disabled
-            if (!(Flags & parse_declaration_node))
-            {
-                // Skip until end of declaration
-                while (text[0] != Ch('?') || text[1] != Ch('>'))
-                {
-                    if (!text[0])
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-                text += 2;    // Skip '?>'
-                return 0;
-            }
-
-            // Create declaration
-            xml_node<Ch> *declaration = this->allocate_node(node_declaration);
-
-            // Skip whitespace before attributes or ?>
-            skip<whitespace_pred, Flags>(text);
-
-            // Parse declaration attributes
-            parse_node_attributes<Flags>(text, declaration);
-            
-            // Skip ?>
-            if (text[0] != Ch('?') || text[1] != Ch('>'))
-                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ?>", text);
-            text += 2;
-            
-            return declaration;
-        }
-
-        // Parse XML comment (<!--...)
-        template<int Flags>
-        xml_node<Ch> *parse_comment(Ch *&text)
-        {
-            // If parsing of comments is disabled
-            if (!(Flags & parse_comment_nodes))
-            {
-                // Skip until end of comment
-                while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
-                {
-                    if (!text[0])
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-                text += 3;     // Skip '-->'
-                return 0;      // Do not produce comment node
-            }
-
-            // Remember value start
-            Ch *val = text;
-
-            // Skip until end of comment
-            while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
-            {
-                if (!text[0])
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                ++text;
-            }
-
-            // Create comment node
-            xml_node<Ch> *comment = this->allocate_node(node_comment);
-            comment->value(val, text - val);
-            
-            // Place zero terminator after comment value
-            if (!(Flags & parse_no_string_terminators))
-                *text = Ch('\0');
-            
-            text += 3;     // Skip '-->'
-            return comment;
-        }
-
-        // Parse DOCTYPE
-        template<int Flags>
-        xml_node<Ch> *parse_doctype(Ch *&text)
-        {
-            // Remember value start
-            Ch *val = text;
-
-            // Skip to >
-            while (*text != Ch('>'))
-            {
-                // Determine character type
-                switch (*text)
-                {
-                
-                // If '[' encountered, scan for matching ending ']' using naive algorithm with depth
-                // This works for all W3C test files except for 2 most wicked
-                case Ch('['):
-                {
-                    ++text;     // Skip '['
-                    int depth = 1;
-                    while (depth > 0)
-                    {
-                        switch (*text)
-                        {
-                            case Ch('['): ++depth; break;
-                            case Ch(']'): --depth; break;
-                            case 0: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                            default: break;
-                        }
-                        ++text;
-                    }
-                    break;
-                }
-                
-                // Error on end of text
-                case Ch('\0'):
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                
-                // Other character, skip it
-                default:
-                    ++text;
-
-                }
-            }
-            
-            // If DOCTYPE nodes enabled
-            if (Flags & parse_doctype_node)
-            {
-                // Create a new doctype node
-                xml_node<Ch> *doctype = this->allocate_node(node_doctype);
-                doctype->value(val, text - val);
-                
-                // Place zero terminator after value
-                if (!(Flags & parse_no_string_terminators))
-                    *text = Ch('\0');
-
-                text += 1;      // skip '>'
-                return doctype;
-            }
-            else
-            {
-                text += 1;      // skip '>'
-                return 0;
-            }
-
-        }
-
-        // Parse PI
-        template<int Flags>
-        xml_node<Ch> *parse_pi(Ch *&text)
-        {
-            // If creation of PI nodes is enabled
-            if (Flags & parse_pi_nodes)
-            {
-                // Create pi node
-                xml_node<Ch> *pi = this->allocate_node(node_pi);
-
-                // Extract PI target name
-                Ch *n = text;
-                skip<node_name_pred, Flags>(text);
-                if (text == n)
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected PI target", text);
-                pi->name(n, text - n);
-                
-                // Skip whitespace between pi target and pi
-                skip<whitespace_pred, Flags>(text);
-
-                // Remember start of pi
-                Ch *val = text;
-                
-                // Skip to '?>'
-                while (text[0] != Ch('?') || text[1] != Ch('>'))
-                {
-                    if (*text == Ch('\0'))
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-
-                // Set pi value (verbatim, no entity expansion or whitespace normalization)
-                pi->value(val, text - val);
-
-                // Place zero terminator after name and value
-                if (!(Flags & parse_no_string_terminators))
-                {
-                    pi->name()[pi->name_size()] = Ch('\0');
-                    pi->value()[pi->value_size()] = Ch('\0');
-                }
-                
-                text += 2;                          // Skip '?>'
-                return pi;
-            }
-            else
-            {
-                // Skip to '?>'
-                while (text[0] != Ch('?') || text[1] != Ch('>'))
-                {
-                    if (*text == Ch('\0'))
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-                text += 2;    // Skip '?>'
-                return 0;
-            }
-        }
-
-        // Parse and append data
-        // Return character that ends data.
-        // This is necessary because this character might have been overwritten by a terminating 0
-        template<int Flags>
-        Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start)
-        {
-            // Backup to contents start if whitespace trimming is disabled
-            if (!(Flags & parse_trim_whitespace))
-                text = contents_start;     
-            
-            // Skip until end of data
-            Ch *val = text, *end;
-            if (Flags & parse_normalize_whitespace)
-                end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred, Flags>(text);   
-            else
-                end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred, Flags>(text);
-
-            // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >
-            if (Flags & parse_trim_whitespace)
-            {
-                if (Flags & parse_normalize_whitespace)
-                {
-                    // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end
-                    if (*(end - 1) == Ch(' '))
-                        --end;
-                }
-                else
-                {
-                    // Backup until non-whitespace character is found
-                    while (whitespace_pred::test(*(end - 1)))
-                        --end;
-                }
-            }
-            
-            // If characters are still left between end and value (this test is only necessary if normalization is enabled)
-            // Create new data node
-            if (!(Flags & parse_no_data_nodes))
-            {
-                xml_node<Ch> *data = this->allocate_node(node_data);
-                data->value(val, end - val);
-                node->append_node(data);
-            }
-
-            // Add data to parent node if no data exists yet
-            if (!(Flags & parse_no_element_values)) 
-                if (*node->value() == Ch('\0'))
-                    node->value(val, end - val);
-
-            // Place zero terminator after value
-            if (!(Flags & parse_no_string_terminators))
-            {
-                Ch ch = *text;
-                *end = Ch('\0');
-                return ch;      // Return character that ends data; this is required because zero terminator overwritten it
-            }
-
-            // Return character that ends data
-            return *text;
-        }
-
-        // Parse CDATA
-        template<int Flags>
-        xml_node<Ch> *parse_cdata(Ch *&text)
-        {
-            // If CDATA is disabled
-            if (Flags & parse_no_data_nodes)
-            {
-                // Skip until end of cdata
-                while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
-                {
-                    if (!text[0])
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-                text += 3;      // Skip ]]>
-                return 0;       // Do not produce CDATA node
-            }
-
-            // Skip until end of cdata
-            Ch *val = text;
-            while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
-            {
-                if (!text[0])
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                ++text;
-            }
-
-            // Create new cdata node
-            xml_node<Ch> *cdata = this->allocate_node(node_cdata);
-            cdata->value(val, text - val);
-
-            // Place zero terminator after value
-            if (!(Flags & parse_no_string_terminators))
-                *text = Ch('\0');
-
-            text += 3;      // Skip ]]>
-            return cdata;
-        }
-        
-        // Parse element node
-        template<int Flags>
-        xml_node<Ch> *parse_element(Ch *&text)
-        {
-            // Create element node
-            xml_node<Ch> *element = this->allocate_node(node_element);
-
-            // Extract element name
-            Ch *n = text;
-            skip<node_name_pred, Flags>(text);
-            if (text == n)
-                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected element name", text);
-            element->name(n, text - n);
-            
-            // Skip whitespace between element name and attributes or >
-            skip<whitespace_pred, Flags>(text);
-
-            // Parse attributes, if any
-            parse_node_attributes<Flags>(text, element);
-
-            // Determine ending type
-            if (*text == Ch('>'))
-            {
-                ++text;
-                parse_node_contents<Flags>(text, element);
-            }
-            else if (*text == Ch('/'))
-            {
-                ++text;
-                if (*text != Ch('>'))
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
-                ++text;
-            }
-            else
-                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
-
-            // Place zero terminator after name
-            if (!(Flags & parse_no_string_terminators))
-                element->name()[element->name_size()] = Ch('\0');
-
-            // Return parsed element
-            return element;
-        }
-
-        // Determine node type, and parse it
-        template<int Flags>
-        xml_node<Ch> *parse_node(Ch *&text)
-        {
-            // Parse proper node type
-            switch (text[0])
-            {
-
-            // <...
-            default: 
-                // Parse and append element node
-                return parse_element<Flags>(text);
-
-            // <?...
-            case Ch('?'): 
-                ++text;     // Skip ?
-                if ((text[0] == Ch('x') || text[0] == Ch('X')) &&
-                    (text[1] == Ch('m') || text[1] == Ch('M')) && 
-                    (text[2] == Ch('l') || text[2] == Ch('L')) &&
-                    whitespace_pred::test(text[3]))
-                {
-                    // '<?xml ' - xml declaration
-                    text += 4;      // Skip 'xml '
-                    return parse_xml_declaration<Flags>(text);
-                }
-                else
-                {
-                    // Parse PI
-                    return parse_pi<Flags>(text);
-                }
-            
-            // <!...
-            case Ch('!'): 
-
-                // Parse proper subset of <! node
-                switch (text[1])    
-                {
-                
-                // <!-
-                case Ch('-'):
-                    if (text[2] == Ch('-'))
-                    {
-                        // '<!--' - xml comment
-                        text += 3;     // Skip '!--'
-                        return parse_comment<Flags>(text);
-                    }
-                    break;
-
-                // <![
-                case Ch('['):
-                    if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A') && 
-                        text[5] == Ch('T') && text[6] == Ch('A') && text[7] == Ch('['))
-                    {
-                        // '<![CDATA[' - cdata
-                        text += 8;     // Skip '![CDATA['
-                        return parse_cdata<Flags>(text);
-                    }
-                    break;
-
-                // <!D
-                case Ch('D'):
-                    if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T') && 
-                        text[5] == Ch('Y') && text[6] == Ch('P') && text[7] == Ch('E') && 
-                        whitespace_pred::test(text[8]))
-                    {
-                        // '<!DOCTYPE ' - doctype
-                        text += 9;      // skip '!DOCTYPE '
-                        return parse_doctype<Flags>(text);
-                    }
-                    break;
-
-                default: break;
-
-                }   // switch
-
-                // Attempt to skip other, unrecognized node types starting with <!
-                ++text;     // Skip !
-                while (*text != Ch('>'))
-                {
-                    if (*text == 0)
-                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-                    ++text;
-                }
-                ++text;     // Skip '>'
-                return 0;   // No node recognized
-
-            }
-        }
-
-        // Parse contents of the node - children, data etc.
-        template<int Flags>
-        void parse_node_contents(Ch *&text, xml_node<Ch> *node)
-        {
-            // For all children and text
-            while (1)
-            {
-                // Skip whitespace between > and node contents
-                Ch *contents_start = text;      // Store start of node contents before whitespace is skipped
-                if (Flags & parse_trim_whitespace)
-                    skip<whitespace_pred, Flags>(text);
-                Ch next_char = *text;
-
-            // After data nodes, instead of continuing the loop, control jumps here.
-            // This is because zero termination inside parse_and_append_data() function
-            // would wreak havoc with the above code.
-            // Also, skipping whitespace after data nodes is unnecessary.
-            after_data_node:    
-                
-                // Determine what comes next: node closing, child node, data node, or 0?
-                switch (next_char)
-                {
-                
-                // Node closing or child node
-                case Ch('<'):
-                    if (text[1] == Ch('/'))
-                    {
-                        // Node closing
-                        text += 2;      // Skip '</'
-                        if (Flags & parse_validate_closing_tags)
-                        {
-                            // Skip and validate closing tag name
-                            Ch *closing_name = text;
-                            skip<node_name_pred, Flags>(text);
-                            if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true))
-                                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
-                        }
-                        else
-                        {
-                            // No validation, just skip name
-                            skip<node_name_pred, Flags>(text);
-                        }
-                        // Skip remaining whitespace after node name
-                        skip<whitespace_pred, Flags>(text);
-                        if (*text != Ch('>'))
-                            BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
-                        ++text;     // Skip '>'
-                        return;     // Node closed, finished parsing contents
-                    }
-                    else
-                    {
-                        // Child node
-                        ++text;     // Skip '<'
-                        if (xml_node<Ch> *child = parse_node<Flags>(text))
-                            node->append_node(child);
-                    }
-                    break;
-
-                // End of data - error
-                case Ch('\0'):
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-
-                // Data node
-                default:
-                    next_char = parse_and_append_data<Flags>(node, text, contents_start);
-                    goto after_data_node;   // Bypass regular processing after data nodes
-
-                }
-            }
-        }
-        
-        // Parse XML attributes of the node
-        template<int Flags>
-        void parse_node_attributes(Ch *&text, xml_node<Ch> *node)
-        {
-            // For all attributes 
-            while (attribute_name_pred::test(*text))
-            {
-                // Extract attribute name
-                Ch *n = text;
-                ++text;     // Skip first character of attribute name
-                skip<attribute_name_pred, Flags>(text);
-                if (text == n)
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected attribute name", n);
-
-                // Create new attribute
-                xml_attribute<Ch> *attribute = this->allocate_attribute();
-                attribute->name(n, text - n);
-                node->append_attribute(attribute);
-
-                // Skip whitespace after attribute name
-                skip<whitespace_pred, Flags>(text);
-
-                // Skip =
-                if (*text != Ch('='))
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected =", text);
-                ++text;
-
-                // Add terminating zero after name
-                if (!(Flags & parse_no_string_terminators))
-                    attribute->name()[attribute->name_size()] = 0;
-
-                // Skip whitespace after =
-                skip<whitespace_pred, Flags>(text);
-
-                // Skip quote and remember if it was ' or "
-                Ch quote = *text;
-                if (quote != Ch('\'') && quote != Ch('"'))
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
-                ++text;
-
-                // Extract attribute value and expand char refs in it
-                Ch *val = text, *end;
-                const int AttFlags = Flags & ~parse_normalize_whitespace;   // No whitespace normalization in attributes
-                if (quote == Ch('\''))
-                    end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>, attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);
-                else
-                    end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>, attribute_value_pure_pred<Ch('"')>, AttFlags>(text);
-                
-                // Set attribute value
-                attribute->value(val, end - val);
-                
-                // Make sure that end quote is present
-                if (*text != quote)
-                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
-                ++text;     // Skip quote
-
-                // Add terminating zero after value
-                if (!(Flags & parse_no_string_terminators))
-                    attribute->value()[attribute->value_size()] = 0;
-
-                // Skip whitespace after attribute value
-                skip<whitespace_pred, Flags>(text);
-            }
-        }
-
-    };
-
-    //! \cond internal
-    namespace internal
-    {
-
-        // Whitespace (space \n \r \t)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  0,  1,  0,  0,  // 0
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 1
-             1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 2
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 3
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 4
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 5
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 6
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 7
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 8
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 9
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // A
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // B
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // C
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // D
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // E
-             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   // F
-        };
-
-        // Node name (anything but space \n \r \t / > ? \0)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_node_name[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Text (i.e. PCDATA) (anything but < \0)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_text[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Text (i.e. PCDATA) that does not require processing when ws normalization is disabled 
-        // (anything but < \0 &)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled
-        // (anything but < \0 & space \n \r \t)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             0,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Attribute name (anything but space \n \r \t / < > = ? ! \0)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Attribute data with single quote (anything but ' \0)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Attribute data with single quote that does not require processing (anything but ' \0 &)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Attribute data with double quote (anything but " \0)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Attribute data with double quote that does not require processing (anything but " \0 &)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
-             1,  1,  0,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
-             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
-        };
-
-        // Digits (dec and hex, 255 denotes end of numeric character reference)
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_digits[256] = 
-        {
-          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 0
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 1
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 2
-             0,  1,  2,  3,  4,  5,  6,  7,  8,  9,255,255,255,255,255,255,  // 3
-           255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255,  // 4
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 5
-           255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255,  // 6
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 7
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 8
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 9
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // A
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // B
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // C
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // D
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // E
-           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255   // F
-        };
-    
-        // Upper case conversion
-        template<int Dummy>
-        const unsigned char lookup_tables<Dummy>::lookup_upcase[256] = 
-        {
-          // 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  A   B   C   D   E   F
-           0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,   // 0
-           16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,   // 1
-           32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,   // 2
-           48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,   // 3
-           64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   // 4
-           80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,   // 5
-           96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   // 6
-           80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127,  // 7
-           128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,  // 8
-           144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,  // 9
-           160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,  // A
-           176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,  // B
-           192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,  // C
-           208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,  // D
-           224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,  // E
-           240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255   // F
-        };
-    }
-    //! \endcond
-
-}}}}
-
-// Undefine internal macros
-#undef BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
-
-// On MSVC, restore warnings state
-#ifdef _MSC_VER
-    #pragma warning(pop)
-#endif
-
-#endif
+// ----------------------------------------------------------------------------
+// Copyright (C) 2006, 2009 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0. 
+// (See accompanying file LICENSE_1_0.txt or copy at 
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#ifndef LIBLAS_BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
+#define LIBLAS_BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
+
+//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
+
+#include <cstdlib>      // For std::size_t
+#include <cassert>      // For assert
+#include <new>          // For placement new
+
+// On MSVC, disable "conditional expression is constant" warning (level 4). 
+// This warning is almost impossible to avoid with certain types of templated code
+#ifdef _MSC_VER
+    #pragma warning(push)
+    #pragma warning(disable:4127)   // Conditional expression is constant
+#endif
+
+///////////////////////////////////////////////////////////////////////////
+// BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
+    
+#include <exception>    // For std::exception
+
+#define BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
+
+namespace liblas { namespace property_tree { namespace detail {namespace rapidxml
+{
+
+    //! Parse error exception. 
+    //! This exception is thrown by the parser when an error occurs. 
+    //! Use what() function to get human-readable error message. 
+    //! Use where() function to get a pointer to position within source text where error was detected.
+    //! <br><br>
+    //! If throwing exceptions by the parser is undesirable, 
+    //! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.
+    //! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.
+    //! This function must be defined by the user.
+    //! <br><br>
+    //! This class derives from <code>std::exception</code> class.
+    class parse_error: public std::exception
+    {
+    
+    public:
+    
+        //! Constructs parse error
+        parse_error(const char *wa, void *we)
+            : m_what(wa)
+            , m_where(we)
+        {
+        }
+
+        //! Gets human readable description of error.
+        //! \return Pointer to null terminated description of the error.
+        virtual const char *what() const throw()
+        {
+            return m_what;
+        }
+
+        //! Gets pointer to character data where error happened.
+        //! Ch should be the same as char type of xml_document that produced the error.
+        //! \return Pointer to location within the parsed string where error occured.
+        template<class Ch>
+        Ch *where() const
+        {
+            return reinterpret_cast<Ch *>(m_where);
+        }
+
+    private:  
+
+        const char *m_what;
+        void *m_where;
+
+    };
+}}}}
+
+///////////////////////////////////////////////////////////////////////////
+// Pool sizes
+
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE
+    // Size of static memory block of memory_pool.
+    // Define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
+    // No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
+    #define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
+#endif
+
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE
+    // Size of dynamic memory block of memory_pool.
+    // Define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
+    // After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
+    #define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
+#endif
+
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT
+    // Memory allocation alignment.
+    // Define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
+    // All memory allocations for nodes, attributes and strings will be aligned to this value.
+    // This must be a power of 2 and at least 1, otherwise memory_pool will not work.
+    #define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT sizeof(void *)
+#endif
+
+namespace liblas { namespace property_tree { namespace detail {namespace rapidxml
+{
+    // Forward declarations
+    template<class Ch> class xml_node;
+    template<class Ch> class xml_attribute;
+    template<class Ch> class xml_document;
+    
+    //! Enumeration listing all node types produced by the parser.
+    //! Use xml_node::type() function to query node type.
+    enum node_type
+    {
+        node_document,      //!< A document node. Name and value are empty.
+        node_element,       //!< An element node. Name contains element name. Value contains text of first data node.
+        node_data,          //!< A data node. Name is empty. Value contains data text.
+        node_cdata,         //!< A CDATA node. Name is empty. Value contains data text.
+        node_comment,       //!< A comment node. Name is empty. Value contains comment text.
+        node_declaration,   //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
+        node_doctype,       //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
+        node_pi             //!< A PI node. Name contains target. Value contains instructions.
+    };
+
+    ///////////////////////////////////////////////////////////////////////
+    // Parsing flags
+
+    //! Parse flag instructing the parser to not create data nodes. 
+    //! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_no_data_nodes = 0x1;            
+
+    //! Parse flag instructing the parser to not use text of first data node as a value of parent element.
+    //! Can be combined with other flags by use of | operator.
+    //! Note that child data nodes of element node take precendence over its value when printing. 
+    //! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.
+    //! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_no_element_values = 0x2;
+    
+    //! Parse flag instructing the parser to not place zero terminators after strings in the source text.
+    //! By default zero terminators are placed, modifying source text.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_no_string_terminators = 0x4;
+    
+    //! Parse flag instructing the parser to not translate entities in the source text.
+    //! By default entities are translated, modifying source text.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_no_entity_translation = 0x8;
+    
+    //! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.
+    //! By default, UTF-8 handling is enabled.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_no_utf8 = 0x10;
+    
+    //! Parse flag instructing the parser to create XML declaration node.
+    //! By default, declaration node is not created.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_declaration_node = 0x20;
+    
+    //! Parse flag instructing the parser to create comments nodes.
+    //! By default, comment nodes are not created.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_comment_nodes = 0x40;
+    
+    //! Parse flag instructing the parser to create DOCTYPE node.
+    //! By default, doctype node is not created.
+    //! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_doctype_node = 0x80;
+    
+    //! Parse flag instructing the parser to create PI nodes.
+    //! By default, PI nodes are not created.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_pi_nodes = 0x100;
+    
+    //! Parse flag instructing the parser to validate closing tag names. 
+    //! If not set, name inside closing tag is irrelevant to the parser.
+    //! By default, closing tags are not validated.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_validate_closing_tags = 0x200;
+    
+    //! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.
+    //! By default, whitespace is not trimmed. 
+    //! This flag does not cause the parser to modify source text.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_trim_whitespace = 0x400;
+
+    //! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.
+    //! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.
+    //! By default, whitespace is not normalized. 
+    //! If this flag is specified, source text will be modified.
+    //! Can be combined with other flags by use of | operator.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_normalize_whitespace = 0x800;
+
+    // Compound flags
+    
+    //! Parse flags which represent default behaviour of the parser. 
+    //! This is always equal to 0, so that all other flags can be simply ored together.
+    //! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.
+    //! This also means that meaning of each flag is a <i>negation</i> of the default setting. 
+    //! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,
+    //! and using the flag will disable it.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_default = 0;
+    
+    //! A combination of parse flags that forbids any modifications of the source text. 
+    //! This also results in faster parsing. However, note that the following will occur:
+    //! <ul>
+    //! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>
+    //! <li>entities will not be translated</li>
+    //! <li>whitespace will not be normalized</li>
+    //! </ul>
+    //! See xml_document::parse() function.
+    const int parse_non_destructive = parse_no_string_terminators | parse_no_entity_translation;
+    
+    //! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_fastest = parse_non_destructive | parse_no_data_nodes;
+    
+    //! A combination of parse flags resulting in largest amount of data being extracted. 
+    //! This usually results in slowest parsing.
+    //! <br><br>
+    //! See xml_document::parse() function.
+    const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;
+
+    ///////////////////////////////////////////////////////////////////////
+    // Internals
+
+    //! \cond internal
+    namespace internal
+    {
+
+        // Struct that contains lookup tables for the parser
+        // It must be a template to allow correct linking (because it has static data members, which are defined in a header file).
+        template<int Dummy>
+        struct lookup_tables
+        {
+            static const unsigned char lookup_whitespace[256];              // Whitespace table
+            static const unsigned char lookup_node_name[256];               // Node name table
+            static const unsigned char lookup_text[256];                    // Text table
+            static const unsigned char lookup_text_pure_no_ws[256];         // Text table
+            static const unsigned char lookup_text_pure_with_ws[256];       // Text table
+            static const unsigned char lookup_attribute_name[256];          // Attribute name table
+            static const unsigned char lookup_attribute_data_1[256];        // Attribute data table with single quote
+            static const unsigned char lookup_attribute_data_1_pure[256];   // Attribute data table with single quote
+            static const unsigned char lookup_attribute_data_2[256];        // Attribute data table with double quotes
+            static const unsigned char lookup_attribute_data_2_pure[256];   // Attribute data table with double quotes
+            static const unsigned char lookup_digits[256];                  // Digits
+            static const unsigned char lookup_upcase[256];                  // To uppercase conversion table for ASCII characters
+        };
+
+        // Find length of the string
+        template<class Ch>
+        inline std::size_t measure(const Ch *p)
+        {
+            const Ch *tmp = p;
+            while (*tmp) 
+                ++tmp;
+            return tmp - p;
+        }
+
+        // Compare strings for equality
+        template<class Ch>
+        inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2, std::size_t size2, bool case_sensitive)
+        {
+            if (size1 != size2)
+                return false;
+            if (case_sensitive)
+            {
+                for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
+                    if (*p1 != *p2)
+                        return false;
+            }
+            else
+            {
+                for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
+                    if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)] != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])
+                        return false;
+            }
+            return true;
+        }
+    }
+    //! \endcond
+
+    ///////////////////////////////////////////////////////////////////////
+    // Memory pool
+    
+    //! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.
+    //! In most cases, you will not need to use this class directly. 
+    //! However, if you need to create nodes manually or modify names/values of nodes, 
+    //! you are encouraged to use memory_pool of relevant xml_document to allocate the memory. 
+    //! Not only is this faster than allocating them by using <code>new</code> operator, 
+    //! but also their lifetime will be tied to the lifetime of document, 
+    //! possibly simplyfing memory management. 
+    //! <br><br>
+    //! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool. 
+    //! You can also call allocate_string() function to allocate strings.
+    //! Such strings can then be used as names or values of nodes without worrying about their lifetime.
+    //! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called, 
+    //! or when the pool is destroyed.
+    //! <br><br>
+    //! It is also possible to create a standalone memory_pool, and use it 
+    //! to allocate nodes, whose lifetime will not be tied to any document.
+    //! <br><br>
+    //! Pool maintains <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory. 
+    //! Until static memory is exhausted, no dynamic memory allocations are done.
+    //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
+    //! by using global <code>new[]</code> and <code>delete[]</code> operators. 
+    //! This behaviour can be changed by setting custom allocation routines. 
+    //! Use set_allocator() function to set them.
+    //! <br><br>
+    //! Allocations for nodes, attributes and strings are aligned at <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> bytes.
+    //! This value defaults to the size of pointer on target architecture.
+    //! <br><br>
+    //! To obtain absolutely top performance from the parser,
+    //! it is important that all nodes are allocated from a single, contiguous block of memory.
+    //! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
+    //! If required, you can tweak <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code>, <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> 
+    //! to obtain best wasted memory to performance compromise.
+    //! To do it, define their values before rapidxml.hpp file is included.
+    //! \param Ch Character type of created nodes. 
+    template<class Ch = char>
+    class memory_pool
+    {
+        
+    public:
+
+        //! \cond internal
+        typedef void *(alloc_func)(std::size_t);       // Type of user-defined function used to allocate memory
+        typedef void (free_func)(void *);              // Type of user-defined function used to free memory
+        //! \endcond
+        
+        //! Constructs empty pool with default allocator functions.
+        memory_pool()
+            : m_alloc_func(0)
+            , m_free_func(0)
+        {
+            init();
+        }
+
+        //! Destroys pool and frees all the memory. 
+        //! This causes memory occupied by nodes allocated by the pool to be freed.
+        //! Nodes allocated from the pool are no longer valid.
+        ~memory_pool()
+        {
+            clear();
+        }
+
+        //! Allocates a new node from the pool, and optionally assigns name and value to it. 
+        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
+        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
+        //! will call rapidxml::parse_error_handler() function.
+        //! \param type Type of node to create.
+        //! \param name Name to assign to the node, or 0 to assign no name.
+        //! \param value Value to assign to the node, or 0 to assign no value.
+        //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
+        //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
+        //! \return Pointer to allocated node. This pointer will never be NULL.
+        xml_node<Ch> *allocate_node(node_type type, 
+                                    const Ch *name = 0, const Ch *value = 0, 
+                                    std::size_t name_size = 0, std::size_t value_size = 0)
+        {
+            void *memory = allocate_aligned(sizeof(xml_node<Ch>));
+            xml_node<Ch> *node = new(memory) xml_node<Ch>(type);
+            if (name)
+            {
+                if (name_size > 0)
+                    node->name(name, name_size);
+                else
+                    node->name(name);
+            }
+            if (value)
+            {
+                if (value_size > 0)
+                    node->value(value, value_size);
+                else
+                    node->value(value);
+            }
+            return node;
+        }
+
+        //! Allocates a new attribute from the pool, and optionally assigns name and value to it.
+        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
+        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
+        //! will call rapidxml::parse_error_handler() function.
+        //! \param name Name to assign to the attribute, or 0 to assign no name.
+        //! \param value Value to assign to the attribute, or 0 to assign no value.
+        //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
+        //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
+        //! \return Pointer to allocated attribute. This pointer will never be NULL.
+        xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0, 
+                                              std::size_t name_size = 0, std::size_t value_size = 0)
+        {
+            void *memory = allocate_aligned(sizeof(xml_attribute<Ch>));
+            xml_attribute<Ch> *attribute = new(memory) xml_attribute<Ch>;
+            if (name)
+            {
+                if (name_size > 0)
+                    attribute->name(name, name_size);
+                else
+                    attribute->name(name);
+            }
+            if (value)
+            {
+                if (value_size > 0)
+                    attribute->value(value, value_size);
+                else
+                    attribute->value(value);
+            }
+            return attribute;
+        }
+
+        //! Allocates a char array of given size from the pool, and optionally copies a given string to it.
+        //! If the allocation request cannot be accommodated, this function will throw <code>std::bad_alloc</code>.
+        //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
+        //! will call rapidxml::parse_error_handler() function.
+        //! \param source String to initialize the allocated memory with, or 0 to not initialize it.
+        //! \param size Number of characters to allocate, or zero to calculate it automatically from source string length; if size is 0, source string must be specified and null terminated.
+        //! \return Pointer to allocated char array. This pointer will never be NULL.
+        Ch *allocate_string(const Ch *source = 0, std::size_t size = 0)
+        {
+            assert(source || size);     // Either source or size (or both) must be specified
+            if (size == 0)
+                size = internal::measure(source) + 1;
+            Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));
+            if (source)
+                for (std::size_t i = 0; i < size; ++i)
+                    result[i] = source[i];
+            return result;
+        }
+
+        //! Clones an xml_node and its hierarchy of child nodes and attributes.
+        //! Nodes and attributes are allocated from this memory pool.
+        //! Names and values are not cloned, they are shared between the clone and the source.
+        //! Result node can be optionally specified as a second parameter, 
+        //! in which case its contents will be replaced with cloned source node.
+        //! This is useful when you want to clone entire document.
+        //! \param source Node to clone.
+        //! \param result Node to put results in, or 0 to automatically allocate result node
+        //! \return Pointer to cloned node. This pointer will never be NULL.
+        xml_node<Ch> *clone_node(const xml_node<Ch> *source, xml_node<Ch> *result = 0)
+        {
+            // Prepare result node
+            if (result)
+            {
+                result->remove_all_attributes();
+                result->remove_all_nodes();
+                result->type(source->type());
+            }
+            else
+                result = allocate_node(source->type());
+
+            // Clone name and value
+            result->name(source->name(), source->name_size());
+            result->value(source->value(), source->value_size());
+
+            // Clone child nodes and attributes
+            for (xml_node<Ch> *child = source->first_node(); child; child = child->next_sibling())
+                result->append_node(clone_node(child));
+            for (xml_attribute<Ch> *attr = source->first_attribute(); attr; attr = attr->next_attribute())
+                result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size()));
+
+            return result;
+        }
+
+        //! Clears the pool. 
+        //! This causes memory occupied by nodes allocated by the pool to be freed.
+        //! Any nodes or strings allocated from the pool will no longer be valid.
+        void clear()
+        {
+            while (m_begin != m_static_memory)
+            {
+                char *previous_begin = reinterpret_cast<header *>(align(m_begin))->previous_begin;
+                if (m_free_func)
+                    m_free_func(m_begin);
+                else
+                    delete[] m_begin;
+                m_begin = previous_begin;
+            }
+            init();
+        }
+
+        //! Sets or resets the user-defined memory allocation functions for the pool.
+        //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.
+        //! Allocation function must not return invalid pointer on failure. It should either throw,
+        //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program. 
+        //! If it returns invalid pointer, results are undefined.
+        //! <br><br>
+        //! User defined allocation functions must have the following forms:
+        //! <br><code>
+        //! <br>void *allocate(std::size_t size);
+        //! <br>void free(void *pointer);
+        //! </code><br>
+        //! \param af Allocation function, or 0 to restore default function
+        //! \param ff Free function, or 0 to restore default function
+        void set_allocator(alloc_func *af, free_func *ff)
+        {
+            assert(m_begin == m_static_memory && m_ptr == align(m_begin));    // Verify that no memory is allocated yet
+            m_alloc_func = af;
+            m_free_func = ff;
+        }
+
+    private:
+
+        struct header
+        {
+            char *previous_begin;
+        };
+
+        void init()
+        {
+            m_begin = m_static_memory;
+            m_ptr = align(m_begin);
+            m_end = m_static_memory + sizeof(m_static_memory);
+        }
+        
+        char *align(char *ptr)
+        {
+            std::size_t alignment = ((BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1))) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1));
+            return ptr + alignment;
+        }
+        
+        char *allocate_raw(std::size_t size)
+        {
+            // Allocate
+            void *memory;   
+            if (m_alloc_func)   // Allocate memory using either user-specified allocation function or global operator new[]
+            {
+                memory = m_alloc_func(size);
+                assert(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp
+            }
+            else
+            {
+                memory = new char[size];
+            }
+            return static_cast<char *>(memory);
+        }
+        
+        void *allocate_aligned(std::size_t size)
+        {
+            // Calculate aligned pointer
+            char *result = align(m_ptr);
+
+            // If not enough memory left in current pool, allocate a new pool
+            if (result + size > m_end)
+            {
+                // Calculate required pool size (may be bigger than BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE)
+                std::size_t pool_size = BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE;
+                if (pool_size < size)
+                    pool_size = size;
+                
+                // Allocate
+                std::size_t alloc_size = sizeof(header) + (2 * BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 2) + pool_size;     // 2 alignments required in worst case: one for header, one for actual allocation
+                char *raw_memory = allocate_raw(alloc_size);
+                    
+                // Setup new pool in allocated memory
+                char *pool = align(raw_memory);
+                header *new_header = reinterpret_cast<header *>(pool);
+                new_header->previous_begin = m_begin;
+                m_begin = raw_memory;
+                m_ptr = pool + sizeof(header);
+                m_end = raw_memory + alloc_size;
+
+                // Calculate aligned pointer again using new pool
+                result = align(m_ptr);
+            }
+
+            // Update pool and return aligned pointer
+            m_ptr = result + size;
+            return result;
+        }
+
+        char *m_begin;                                      // Start of raw memory making up current pool
+        char *m_ptr;                                        // First free byte in current pool
+        char *m_end;                                        // One past last available byte in current pool
+        char m_static_memory[BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE];    // Static raw memory
+        alloc_func *m_alloc_func;                           // Allocator function, or 0 if default is to be used
+        free_func *m_free_func;                             // Free function, or 0 if default is to be used
+    };
+
+    ///////////////////////////////////////////////////////////////////////////
+    // XML base
+
+    //! Base class for xml_node and xml_attribute implementing common functions: 
+    //! name(), name_size(), value(), value_size() and parent().
+    //! \param Ch Character type to use
+    template<class Ch = char>
+    class xml_base
+    {
+
+    public:
+        
+        ///////////////////////////////////////////////////////////////////////////
+        // Construction & destruction
+    
+        // Construct a base with empty name, value and parent
+        xml_base()
+            : m_name(0)
+            , m_value(0)
+            , m_parent(0)
+        {
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Node data access
+    
+        //! Gets name of the node. 
+        //! Interpretation of name depends on type of node.
+        //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
+        //! <br><br>
+        //! Use name_size() function to determine length of the name.
+        //! \return Name of node, or empty string if node has no name.
+        Ch *name() const
+        {
+            return m_name ? m_name : nullstr();
+        }
+
+        //! Gets size of node name, not including terminator character.
+        //! This function works correctly irrespective of whether name is or is not zero terminated.
+        //! \return Size of node name, in characters.
+        std::size_t name_size() const
+        {
+            return m_name ? m_name_size : 0;
+        }
+
+        //! Gets value of node. 
+        //! Interpretation of value depends on type of node.
+        //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
+        //! <br><br>
+        //! Use value_size() function to determine length of the value.
+        //! \return Value of node, or empty string if node has no value.
+        Ch *value() const
+        {
+            return m_value ? m_value : nullstr();
+        }
+
+        //! Gets size of node value, not including terminator character.
+        //! This function works correctly irrespective of whether value is or is not zero terminated.
+        //! \return Size of node value, in characters.
+        std::size_t value_size() const
+        {
+            return m_value ? m_value_size : 0;
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Node modification
+    
+        //! Sets name of node to a non zero-terminated string.
+        //! See \ref ownership_of_strings.
+        //! <br><br>
+        //! Note that node does not own its name or value, it only stores a pointer to it. 
+        //! It will not delete or otherwise free the pointer on destruction.
+        //! It is reponsibility of the user to properly manage lifetime of the string.
+        //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
+        //! on destruction of the document the string will be automatically freed.
+        //! <br><br>
+        //! Size of name must be specified separately, because name does not have to be zero terminated.
+        //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).
+        //! \param n Name of node to set. Does not have to be zero terminated.
+        //! \param size Size of name, in characters. This does not include zero terminator, if one is present.
+        void name(const Ch *n, std::size_t size)
+        {
+            m_name = const_cast<Ch *>(n);
+            m_name_size = size;
+        }
+
+        //! Sets name of node to a zero-terminated string.
+        //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).
+        //! \param n Name of node to set. Must be zero terminated.
+        void name(const Ch *n)
+        {
+            name(n, internal::measure(n));
+        }
+
+        //! Sets value of node to a non zero-terminated string.
+        //! See \ref ownership_of_strings.
+        //! <br><br>
+        //! Note that node does not own its name or value, it only stores a pointer to it. 
+        //! It will not delete or otherwise free the pointer on destruction.
+        //! It is reponsibility of the user to properly manage lifetime of the string.
+        //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
+        //! on destruction of the document the string will be automatically freed.
+        //! <br><br>
+        //! Size of value must be specified separately, because it does not have to be zero terminated.
+        //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).
+        //! <br><br>
+        //! If an element has a child node of type node_data, it will take precedence over element value when printing.
+        //! If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser.
+        //! \param val value of node to set. Does not have to be zero terminated.
+        //! \param size Size of value, in characters. This does not include zero terminator, if one is present.
+        void value(const Ch *val, std::size_t size)
+        {
+            m_value = const_cast<Ch *>(val);
+            m_value_size = size;
+        }
+
+        //! Sets value of node to a zero-terminated string.
+        //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).
+        //! \param val Vame of node to set. Must be zero terminated.
+        void value(const Ch *val)
+        {
+            this->value(val, internal::measure(val));
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Related nodes access
+    
+        //! Gets node parent.
+        //! \return Pointer to parent node, or 0 if there is no parent.
+        xml_node<Ch> *parent() const
+        {
+            return m_parent;
+        }
+
+    protected:
+
+        // Return empty string
+        static Ch *nullstr()
+        {
+            static Ch zero = Ch('\0');
+            return &zero;
+        }
+
+        Ch *m_name;                         // Name of node, or 0 if no name
+        Ch *m_value;                        // Value of node, or 0 if no value
+        std::size_t m_name_size;            // Length of node name, or undefined of no name
+        std::size_t m_value_size;           // Length of node value, or undefined if no value
+        xml_node<Ch> *m_parent;             // Pointer to parent node, or 0 if none
+
+    };
+
+    //! Class representing attribute node of XML document. 
+    //! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).
+    //! Note that after parse, both name and value of attribute will point to interior of source text used for parsing. 
+    //! Thus, this text must persist in memory for the lifetime of attribute.
+    //! \param Ch Character type to use.
+    template<class Ch = char>
+    class xml_attribute: public xml_base<Ch>
+    {
+
+        friend class xml_node<Ch>;
+    
+    public:
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Construction & destruction
+    
+        //! Constructs an empty attribute with the specified type. 
+        //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.
+        xml_attribute()
+        {
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Related nodes access
+    
+        //! Gets document of which attribute is a child.
+        //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.
+        xml_document<Ch> *document() const
+        {
+            if (xml_node<Ch> *node = this->parent())
+            {
+                while (node->parent())
+                    node = node->parent();
+                return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
+            }
+            else
+                return 0;
+        }
+
+        //! Gets previous attribute, optionally matching attribute name. 
+        //! \param n Name of attribute to find, or 0 to return previous attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found attribute, or 0 if not found.
+        xml_attribute<Ch> *previous_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute; attribute = attribute->m_prev_attribute)
+                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
+                        return attribute;
+                return 0;
+            }
+            else
+                return this->m_parent ? m_prev_attribute : 0;
+        }
+
+        //! Gets next attribute, optionally matching attribute name. 
+        //! \param n Name of attribute to find, or 0 to return next attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found attribute, or 0 if not found.
+        xml_attribute<Ch> *next_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_attribute<Ch> *attribute = m_next_attribute; attribute; attribute = attribute->m_next_attribute)
+                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
+                        return attribute;
+                return 0;
+            }
+            else
+                return this->m_parent ? m_next_attribute : 0;
+        }
+
+    private:
+
+        xml_attribute<Ch> *m_prev_attribute;        // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero
+        xml_attribute<Ch> *m_next_attribute;        // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero
+    
+    };
+
+    ///////////////////////////////////////////////////////////////////////////
+    // XML node
+
+    //! Class representing a node of XML document. 
+    //! Each node may have associated name and value strings, which are available through name() and value() functions. 
+    //! Interpretation of name and value depends on type of the node.
+    //! Type of node can be determined by using type() function.
+    //! <br><br>
+    //! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing. 
+    //! Thus, this text must persist in the memory for the lifetime of node.
+    //! \param Ch Character type to use.
+    template<class Ch = char>
+    class xml_node: public xml_base<Ch>
+    {
+
+    public:
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Construction & destruction
+    
+        //! Constructs an empty node with the specified type. 
+        //! Consider using memory_pool of appropriate document to allocate nodes manually.
+        //! \param t Type of node to construct.
+        xml_node(node_type t)
+            : m_type(t)
+            , m_first_node(0)
+            , m_first_attribute(0)
+        {
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Node data access
+    
+        //! Gets type of node.
+        //! \return Type of node.
+        node_type type() const
+        {
+            return m_type;
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Related nodes access
+    
+        //! Gets document of which node is a child.
+        //! \return Pointer to document that contains this node, or 0 if there is no parent document.
+        xml_document<Ch> *document() const
+        {
+            xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);
+            while (node->parent())
+                node = node->parent();
+            return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
+        }
+
+        //! Gets first child node, optionally matching node name.
+        //! \param n Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found child, or 0 if not found.
+        xml_node<Ch> *first_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_node<Ch> *child = m_first_node; child; child = child->next_sibling())
+                    if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
+                        return child;
+                return 0;
+            }
+            else
+                return m_first_node;
+        }
+
+        //! Gets last child node, optionally matching node name. 
+        //! Behaviour is undefined if node has no children.
+        //! Use first_node() to test if node has children.
+        //! \param n Name of child to find, or 0 to return last child regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found child, or 0 if not found.
+        xml_node<Ch> *last_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            assert(m_first_node);  // Cannot query for last child if node has no children
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_node<Ch> *child = m_last_node; child; child = child->previous_sibling())
+                    if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
+                        return child;
+                return 0;
+            }
+            else
+                return m_last_node;
+        }
+
+        //! Gets previous sibling node, optionally matching node name. 
+        //! Behaviour is undefined if node has no parent.
+        //! Use parent() to test if node has a parent.
+        //! \param n Name of sibling to find, or 0 to return previous sibling regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found sibling, or 0 if not found.
+        xml_node<Ch> *previous_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            assert(this->m_parent);     // Cannot query for siblings if node has no parent
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_node<Ch> *sibling = m_prev_sibling; sibling; sibling = sibling->m_prev_sibling)
+                    if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
+                        return sibling;
+                return 0;
+            }
+            else
+                return m_prev_sibling;
+        }
+
+        //! Gets next sibling node, optionally matching node name. 
+        //! Behaviour is undefined if node has no parent.
+        //! Use parent() to test if node has a parent.
+        //! \param n Name of sibling to find, or 0 to return next sibling regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found sibling, or 0 if not found.
+        xml_node<Ch> *next_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            assert(this->m_parent);     // Cannot query for siblings if node has no parent
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_node<Ch> *sibling = m_next_sibling; sibling; sibling = sibling->m_next_sibling)
+                    if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
+                        return sibling;
+                return 0;
+            }
+            else
+                return m_next_sibling;
+        }
+
+        //! Gets first attribute of node, optionally matching attribute name.
+        //! \param n Name of attribute to find, or 0 to return first attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found attribute, or 0 if not found.
+        xml_attribute<Ch> *first_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_attribute<Ch> *attribute = m_first_attribute; attribute; attribute = attribute->m_next_attribute)
+                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
+                        return attribute;
+                return 0;
+            }
+            else
+                return m_first_attribute;
+        }
+
+        //! Gets last attribute of node, optionally matching attribute name.
+        //! \param n Name of attribute to find, or 0 to return last attribute regardless of its name; this string doesn't have to be zero-terminated if nsize is non-zero
+        //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
+        //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
+        //! \return Pointer to found attribute, or 0 if not found.
+        xml_attribute<Ch> *last_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
+        {
+            if (n)
+            {
+                if (nsize == 0)
+                    nsize = internal::measure(n);
+                for (xml_attribute<Ch> *attribute = m_last_attribute; attribute; attribute = attribute->m_prev_attribute)
+                    if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
+                        return attribute;
+                return 0;
+            }
+            else
+                return m_first_attribute ? m_last_attribute : 0;
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Node modification
+    
+        //! Sets type of node.
+        //! \param t Type of node to set.
+        void type(node_type t)
+        {
+            m_type = t;
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Node manipulation
+
+        //! Prepends a new child node.
+        //! The prepended child becomes the first child, and all existing children are moved one position back.
+        //! \param child Node to prepend.
+        void prepend_node(xml_node<Ch> *child)
+        {
+            assert(child && !child->parent() && child->type() != node_document);
+            if (first_node())
+            {
+                child->m_next_sibling = m_first_node;
+                m_first_node->m_prev_sibling = child;
+            }
+            else
+            {
+                child->m_next_sibling = 0;
+                m_last_node = child;
+            }
+            m_first_node = child;
+            child->m_parent = this;
+            child->m_prev_sibling = 0;
+        }
+
+        //! Appends a new child node. 
+        //! The appended child becomes the last child.
+        //! \param child Node to append.
+        void append_node(xml_node<Ch> *child)
+        {
+            assert(child && !child->parent() && child->type() != node_document);
+            if (first_node())
+            {
+                child->m_prev_sibling = m_last_node;
+                m_last_node->m_next_sibling = child;
+            }
+            else
+            {
+                child->m_prev_sibling = 0;
+                m_first_node = child;
+            }
+            m_last_node = child;
+            child->m_parent = this;
+            child->m_next_sibling = 0;
+        }
+
+        //! Inserts a new child node at specified place inside the node. 
+        //! All children after and including the specified node are moved one position back.
+        //! \param where Place where to insert the child, or 0 to insert at the back.
+        //! \param child Node to insert.
+        void insert_node(xml_node<Ch> *where, xml_node<Ch> *child)
+        {
+            assert(!where || where->parent() == this);
+            assert(child && !child->parent() && child->type() != node_document);
+            if (where == m_first_node)
+                prepend_node(child);
+            else if (where == 0)
+                append_node(child);
+            else
+            {
+                child->m_prev_sibling = where->m_prev_sibling;
+                child->m_next_sibling = where;
+                where->m_prev_sibling->m_next_sibling = child;
+                where->m_prev_sibling = child;
+                child->m_parent = this;
+            }
+        }
+
+        //! Removes first child node. 
+        //! If node has no children, behaviour is undefined.
+        //! Use first_node() to test if node has children.
+        void remove_first_node()
+        {
+            assert(first_node());
+            xml_node<Ch> *child = m_first_node;
+            m_first_node = child->m_next_sibling;
+            if (child->m_next_sibling)
+                child->m_next_sibling->m_prev_sibling = 0;
+            else
+                m_last_node = 0;
+            child->m_parent = 0;
+        }
+
+        //! Removes last child of the node. 
+        //! If node has no children, behaviour is undefined.
+        //! Use first_node() to test if node has children.
+        void remove_last_node()
+        {
+            assert(first_node());
+            xml_node<Ch> *child = m_last_node;
+            if (child->m_prev_sibling)
+            {
+                m_last_node = child->m_prev_sibling;
+                child->m_prev_sibling->m_next_sibling = 0;
+            }
+            else
+                m_first_node = 0;
+            child->m_parent = 0;
+        }
+
+        //! Removes specified child from the node
+        // \param where Pointer to child to be removed.
+        void remove_node(xml_node<Ch> *where)
+        {
+            assert(where && where->parent() == this);
+            assert(first_node());
+            if (where == m_first_node)
+                remove_first_node();
+            else if (where == m_last_node)
+                remove_last_node();
+            else
+            {
+                where->m_prev_sibling->m_next_sibling = where->m_next_sibling;
+                where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;
+                where->m_parent = 0;
+            }
+        }
+
+        //! Removes all child nodes (but not attributes).
+        void remove_all_nodes()
+        {
+            for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)
+                node->m_parent = 0;
+            m_first_node = 0;
+        }
+
+        //! Prepends a new attribute to the node.
+        //! \param attribute Attribute to prepend.
+        void prepend_attribute(xml_attribute<Ch> *attribute)
+        {
+            assert(attribute && !attribute->parent());
+            if (first_attribute())
+            {
+                attribute->m_next_attribute = m_first_attribute;
+                m_first_attribute->m_prev_attribute = attribute;
+            }
+            else
+            {
+                attribute->m_next_attribute = 0;
+                m_last_attribute = attribute;
+            }
+            m_first_attribute = attribute;
+            attribute->m_parent = this;
+            attribute->m_prev_attribute = 0;
+        }
+
+        //! Appends a new attribute to the node.
+        //! \param attribute Attribute to append.
+        void append_attribute(xml_attribute<Ch> *attribute)
+        {
+            assert(attribute && !attribute->parent());
+            if (first_attribute())
+            {
+                attribute->m_prev_attribute = m_last_attribute;
+                m_last_attribute->m_next_attribute = attribute;
+            }
+            else
+            {
+                attribute->m_prev_attribute = 0;
+                m_first_attribute = attribute;
+            }
+            m_last_attribute = attribute;
+            attribute->m_parent = this;
+            attribute->m_next_attribute = 0;
+        }
+
+        //! Inserts a new attribute at specified place inside the node. 
+        //! All attributes after and including the specified attribute are moved one position back.
+        //! \param where Place where to insert the attribute, or 0 to insert at the back.
+        //! \param attribute Attribute to insert.
+        void insert_attribute(xml_attribute<Ch> *where, xml_attribute<Ch> *attribute)
+        {
+            assert(!where || where->parent() == this);
+            assert(attribute && !attribute->parent());
+            if (where == m_first_attribute)
+                prepend_attribute(attribute);
+            else if (where == 0)
+                append_attribute(attribute);
+            else
+            {
+                attribute->m_prev_attribute = where->m_prev_attribute;
+                attribute->m_next_attribute = where;
+                where->m_prev_attribute->m_next_attribute = attribute;
+                where->m_prev_attribute = attribute;
+                attribute->m_parent = this;
+            }
+        }
+
+        //! Removes first attribute of the node. 
+        //! If node has no attributes, behaviour is undefined.
+        //! Use first_attribute() to test if node has attributes.
+        void remove_first_attribute()
+        {
+            assert(first_attribute());
+            xml_attribute<Ch> *attribute = m_first_attribute;
+            if (attribute->m_next_attribute)
+            {
+                attribute->m_next_attribute->m_prev_attribute = 0;
+            }
+            else
+                m_last_attribute = 0;
+            attribute->m_parent = 0;
+            m_first_attribute = attribute->m_next_attribute;
+        }
+
+        //! Removes last attribute of the node. 
+        //! If node has no attributes, behaviour is undefined.
+        //! Use first_attribute() to test if node has attributes.
+        void remove_last_attribute()
+        {
+            assert(first_attribute());
+            xml_attribute<Ch> *attribute = m_last_attribute;
+            if (attribute->m_prev_attribute)
+            {
+                attribute->m_prev_attribute->m_next_attribute = 0;
+                m_last_attribute = attribute->m_prev_attribute;
+            }
+            else
+                m_first_attribute = 0;
+            attribute->m_parent = 0;
+        }
+
+        //! Removes specified attribute from node.
+        //! \param where Pointer to attribute to be removed.
+        void remove_attribute(xml_attribute<Ch> *where)
+        {
+            assert(first_attribute() && where->parent() == this);
+            if (where == m_first_attribute)
+                remove_first_attribute();
+            else if (where == m_last_attribute)
+                remove_last_attribute();
+            else
+            {
+                where->m_prev_attribute->m_next_attribute = where->m_next_attribute;
+                where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;
+                where->m_parent = 0;
+            }
+        }
+
+        //! Removes all attributes of node.
+        void remove_all_attributes()
+        {
+            for (xml_attribute<Ch> *attribute = first_attribute(); attribute; attribute = attribute->m_next_attribute)
+                attribute->m_parent = 0;
+            m_first_attribute = 0;
+        }
+        
+    private:
+
+        ///////////////////////////////////////////////////////////////////////////
+        // Restrictions
+
+        // No copying
+        xml_node(const xml_node &);
+        void operator =(const xml_node &);
+    
+        ///////////////////////////////////////////////////////////////////////////
+        // Data members
+    
+        // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.
+        // This is required for maximum performance, as it allows the parser to omit initialization of 
+        // unneded/redundant values.
+        //
+        // The rules are as follows:
+        // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively
+        // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage
+        // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage
+
+        node_type m_type;                       // Type of node; always valid
+        xml_node<Ch> *m_first_node;             // Pointer to first child node, or 0 if none; always valid
+        xml_node<Ch> *m_last_node;              // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero
+        xml_attribute<Ch> *m_first_attribute;   // Pointer to first attribute of node, or 0 if none; always valid
+        xml_attribute<Ch> *m_last_attribute;    // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero
+        xml_node<Ch> *m_prev_sibling;           // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
+        xml_node<Ch> *m_next_sibling;           // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
+
+    };
+
+    ///////////////////////////////////////////////////////////////////////////
+    // XML document
+    
+    //! This class represents root of the DOM hierarchy. 
+    //! It is also an xml_node and a memory_pool through public inheritance.
+    //! Use parse() function to build a DOM tree from a zero-terminated XML text string.
+    //! parse() function allocates memory for nodes and attributes by using functions of xml_document, 
+    //! which are inherited from memory_pool.
+    //! To access root node of the document, use the document itself, as if it was an xml_node.
+    //! \param Ch Character type to use.
+    template<class Ch = char>
+    class xml_document: public xml_node<Ch>, public memory_pool<Ch>
+    {
+    
+    public:
+
+        //! Constructs empty XML document
+        xml_document()
+            : xml_node<Ch>(node_document)
+        {
+        }
+
+        //! Parses zero-terminated XML string according to given flags.
+        //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.
+        //! The string must persist for the lifetime of the document.
+        //! In case of error, rapidxml::parse_error exception will be thrown.
+        //! <br><br>
+        //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.
+        //! Make sure that data is zero-terminated.
+        //! <br><br>
+        //! Document can be parsed into multiple times. 
+        //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.
+        //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.
+        template<int Flags>
+        void parse(Ch *text)
+        {
+            assert(text);
+            
+            // Remove current contents
+            this->remove_all_nodes();
+            this->remove_all_attributes();
+            
+            // Parse BOM, if any
+            parse_bom<Flags>(text);
+            
+            // Parse children
+            while (1)
+            {
+                // Skip whitespace before node
+                skip<whitespace_pred, Flags>(text);
+                if (*text == 0)
+                    break;
+
+                // Parse and append new child
+                if (*text == Ch('<'))
+                {
+                    ++text;     // Skip '<'
+                    if (xml_node<Ch> *node = parse_node<Flags>(text))
+                        this->append_node(node);
+                }
+                else
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected <", text);
+            }
+
+        }
+
+        //! Clears the document by deleting all nodes and clearing the memory pool.
+        //! All nodes owned by document pool are destroyed.
+        void clear()
+        {
+            this->remove_all_nodes();
+            this->remove_all_attributes();
+            memory_pool<Ch>::clear();
+        }
+        
+    private:
+
+        ///////////////////////////////////////////////////////////////////////
+        // Internal character utility functions
+        
+        // Detect whitespace character
+        struct whitespace_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_whitespace[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect node name character
+        struct node_name_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_node_name[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect attribute name character
+        struct attribute_name_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_attribute_name[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect text character (PCDATA)
+        struct text_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_text[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect text character (PCDATA) that does not require processing
+        struct text_pure_no_ws_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect text character (PCDATA) that does not require processing
+        struct text_pure_with_ws_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                return internal::lookup_tables<0>::lookup_text_pure_with_ws[static_cast<unsigned char>(ch)];
+            }
+        };
+
+        // Detect attribute value character
+        template<Ch Quote>
+        struct attribute_value_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                if (Quote == Ch('\''))
+                    return internal::lookup_tables<0>::lookup_attribute_data_1[static_cast<unsigned char>(ch)];
+                if (Quote == Ch('\"'))
+                    return internal::lookup_tables<0>::lookup_attribute_data_2[static_cast<unsigned char>(ch)];
+                return 0;       // Should never be executed, to avoid warnings on Comeau
+            }
+        };
+
+        // Detect attribute value character
+        template<Ch Quote>
+        struct attribute_value_pure_pred
+        {
+            static unsigned char test(Ch ch)
+            {
+                if (Quote == Ch('\''))
+                    return internal::lookup_tables<0>::lookup_attribute_data_1_pure[static_cast<unsigned char>(ch)];
+                if (Quote == Ch('\"'))
+                    return internal::lookup_tables<0>::lookup_attribute_data_2_pure[static_cast<unsigned char>(ch)];
+                return 0;       // Should never be executed, to avoid warnings on Comeau
+            }
+        };
+
+        // Insert coded character, using UTF8 or 8-bit ASCII
+        template<int Flags>
+        static void insert_coded_character(Ch *&text, unsigned long code)
+        {
+            if (Flags & parse_no_utf8)
+            {
+                // Insert 8-bit ASCII character
+                // Todo: possibly verify that code is less than 256 and use replacement char otherwise?
+                text[0] = static_cast<unsigned char>(code);
+                text += 1;
+            }
+            else
+            {
+                // Insert UTF8 sequence
+                if (code < 0x80)    // 1 byte sequence
+                {
+                    text[0] = static_cast<unsigned char>(code);
+                    text += 1;
+                }
+                else if (code < 0x800)  // 2 byte sequence
+                {
+                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[0] = static_cast<unsigned char>(code | 0xC0);
+                    text += 2;
+                }
+                else if (code < 0x10000)    // 3 byte sequence
+                {
+                    text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[0] = static_cast<unsigned char>(code | 0xE0);
+                    text += 3;
+                }
+                else if (code < 0x110000)   // 4 byte sequence
+                {
+                    text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
+                    text[0] = static_cast<unsigned char>(code | 0xF0);
+                    text += 4;
+                }
+                else    // Invalid, only codes up to 0x10FFFF are allowed in Unicode
+                {
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
+                }
+            }
+        }
+
+        // Skip characters until predicate evaluates to true
+        template<class StopPred, int Flags>
+        static void skip(Ch *&text)
+        {
+            Ch *tmp = text;
+            while (StopPred::test(*tmp))
+                ++tmp;
+            text = tmp;
+        }
+
+        // Skip characters until predicate evaluates to true while doing the following:
+        // - replacing XML character entity references with proper characters (' & " < > &#...;)
+        // - condensing whitespace sequences to single space character
+        template<class StopPred, class StopPredPure, int Flags>
+        static Ch *skip_and_expand_character_refs(Ch *&text)
+        {
+            // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip
+            if (Flags & parse_no_entity_translation && 
+                !(Flags & parse_normalize_whitespace) &&
+                !(Flags & parse_trim_whitespace))
+            {
+                skip<StopPred, Flags>(text);
+                return text;
+            }
+            
+            // Use simple skip until first modification is detected
+            skip<StopPredPure, Flags>(text);
+
+            // Use translation skip
+            Ch *src = text;
+            Ch *dest = src;
+            while (StopPred::test(*src))
+            {
+                // If entity translation is enabled    
+                if (!(Flags & parse_no_entity_translation))
+                {
+                    // Test if replacement is needed
+                    if (src[0] == Ch('&'))
+                    {
+                        switch (src[1])
+                        {
+
+                        // & '
+                        case Ch('a'): 
+                            if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';'))
+                            {
+                                *dest = Ch('&');
+                                ++dest;
+                                src += 5;
+                                continue;
+                            }
+                            if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s') && src[5] == Ch(';'))
+                            {
+                                *dest = Ch('\'');
+                                ++dest;
+                                src += 6;
+                                continue;
+                            }
+                            break;
+
+                        // "
+                        case Ch('q'): 
+                            if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t') && src[5] == Ch(';'))
+                            {
+                                *dest = Ch('"');
+                                ++dest;
+                                src += 6;
+                                continue;
+                            }
+                            break;
+
+                        // >
+                        case Ch('g'): 
+                            if (src[2] == Ch('t') && src[3] == Ch(';'))
+                            {
+                                *dest = Ch('>');
+                                ++dest;
+                                src += 4;
+                                continue;
+                            }
+                            break;
+
+                        // <
+                        case Ch('l'): 
+                            if (src[2] == Ch('t') && src[3] == Ch(';'))
+                            {
+                                *dest = Ch('<');
+                                ++dest;
+                                src += 4;
+                                continue;
+                            }
+                            break;
+
+                        // &#...; - assumes ASCII
+                        case Ch('#'): 
+                            if (src[2] == Ch('x'))
+                            {
+                                unsigned long code = 0;
+                                src += 3;   // Skip &#x
+                                while (1)
+                                {
+                                    unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
+                                    if (digit == 0xFF)
+                                        break;
+                                    code = code * 16 + digit;
+                                    ++src;
+                                }
+                                insert_coded_character<Flags>(dest, code);    // Put character in output
+                            }
+                            else
+                            {
+                                unsigned long code = 0;
+                                src += 2;   // Skip &#
+                                while (1)
+                                {
+                                    unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
+                                    if (digit == 0xFF)
+                                        break;
+                                    code = code * 10 + digit;
+                                    ++src;
+                                }
+                                insert_coded_character<Flags>(dest, code);    // Put character in output
+                            }
+                            if (*src == Ch(';'))
+                                ++src;
+                            else
+                                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ;", src);
+                            continue;
+
+                        // Something else
+                        default:
+                            // Ignore, just copy '&' verbatim
+                            break;
+
+                        }
+                    }
+                }
+                
+                // If whitespace condensing is enabled
+                if (Flags & parse_normalize_whitespace)
+                {
+                    // Test if condensing is needed                 
+                    if (whitespace_pred::test(*src))
+                    {
+                        *dest = Ch(' '); ++dest;    // Put single space in dest
+                        ++src;                      // Skip first whitespace char
+                        // Skip remaining whitespace chars
+                        while (whitespace_pred::test(*src))
+                            ++src;
+                        continue;
+                    }
+                }
+
+                // No replacement, only copy character
+                *dest++ = *src++;
+
+            }
+
+            // Return new end
+            text = src;
+            return dest;
+
+        }
+
+        ///////////////////////////////////////////////////////////////////////
+        // Internal parsing functions
+        
+        // Parse BOM, if any
+        template<int Flags>
+        void parse_bom(Ch *&text)
+        {
+            // UTF-8?
+            if (static_cast<unsigned char>(text[0]) == 0xEF && 
+                static_cast<unsigned char>(text[1]) == 0xBB && 
+                static_cast<unsigned char>(text[2]) == 0xBF)
+            {
+                text += 3;      // Skip utf-8 bom
+            }
+        }
+
+        // Parse XML declaration (<?xml...)
+        template<int Flags>
+        xml_node<Ch> *parse_xml_declaration(Ch *&text)
+        {
+            // If parsing of declaration is disabled
+            if (!(Flags & parse_declaration_node))
+            {
+                // Skip until end of declaration
+                while (text[0] != Ch('?') || text[1] != Ch('>'))
+                {
+                    if (!text[0])
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+                text += 2;    // Skip '?>'
+                return 0;
+            }
+
+            // Create declaration
+            xml_node<Ch> *declaration = this->allocate_node(node_declaration);
+
+            // Skip whitespace before attributes or ?>
+            skip<whitespace_pred, Flags>(text);
+
+            // Parse declaration attributes
+            parse_node_attributes<Flags>(text, declaration);
+            
+            // Skip ?>
+            if (text[0] != Ch('?') || text[1] != Ch('>'))
+                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ?>", text);
+            text += 2;
+            
+            return declaration;
+        }
+
+        // Parse XML comment (<!--...)
+        template<int Flags>
+        xml_node<Ch> *parse_comment(Ch *&text)
+        {
+            // If parsing of comments is disabled
+            if (!(Flags & parse_comment_nodes))
+            {
+                // Skip until end of comment
+                while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
+                {
+                    if (!text[0])
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+                text += 3;     // Skip '-->'
+                return 0;      // Do not produce comment node
+            }
+
+            // Remember value start
+            Ch *val = text;
+
+            // Skip until end of comment
+            while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
+            {
+                if (!text[0])
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                ++text;
+            }
+
+            // Create comment node
+            xml_node<Ch> *comment = this->allocate_node(node_comment);
+            comment->value(val, text - val);
+            
+            // Place zero terminator after comment value
+            if (!(Flags & parse_no_string_terminators))
+                *text = Ch('\0');
+            
+            text += 3;     // Skip '-->'
+            return comment;
+        }
+
+        // Parse DOCTYPE
+        template<int Flags>
+        xml_node<Ch> *parse_doctype(Ch *&text)
+        {
+            // Remember value start
+            Ch *val = text;
+
+            // Skip to >
+            while (*text != Ch('>'))
+            {
+                // Determine character type
+                switch (*text)
+                {
+                
+                // If '[' encountered, scan for matching ending ']' using naive algorithm with depth
+                // This works for all W3C test files except for 2 most wicked
+                case Ch('['):
+                {
+                    ++text;     // Skip '['
+                    int depth = 1;
+                    while (depth > 0)
+                    {
+                        switch (*text)
+                        {
+                            case Ch('['): ++depth; break;
+                            case Ch(']'): --depth; break;
+                            case 0: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                            default: break;
+                        }
+                        ++text;
+                    }
+                    break;
+                }
+                
+                // Error on end of text
+                case Ch('\0'):
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                
+                // Other character, skip it
+                default:
+                    ++text;
+
+                }
+            }
+            
+            // If DOCTYPE nodes enabled
+            if (Flags & parse_doctype_node)
+            {
+                // Create a new doctype node
+                xml_node<Ch> *doctype = this->allocate_node(node_doctype);
+                doctype->value(val, text - val);
+                
+                // Place zero terminator after value
+                if (!(Flags & parse_no_string_terminators))
+                    *text = Ch('\0');
+
+                text += 1;      // skip '>'
+                return doctype;
+            }
+            else
+            {
+                text += 1;      // skip '>'
+                return 0;
+            }
+
+        }
+
+        // Parse PI
+        template<int Flags>
+        xml_node<Ch> *parse_pi(Ch *&text)
+        {
+            // If creation of PI nodes is enabled
+            if (Flags & parse_pi_nodes)
+            {
+                // Create pi node
+                xml_node<Ch> *pi = this->allocate_node(node_pi);
+
+                // Extract PI target name
+                Ch *n = text;
+                skip<node_name_pred, Flags>(text);
+                if (text == n)
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected PI target", text);
+                pi->name(n, text - n);
+                
+                // Skip whitespace between pi target and pi
+                skip<whitespace_pred, Flags>(text);
+
+                // Remember start of pi
+                Ch *val = text;
+                
+                // Skip to '?>'
+                while (text[0] != Ch('?') || text[1] != Ch('>'))
+                {
+                    if (*text == Ch('\0'))
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+
+                // Set pi value (verbatim, no entity expansion or whitespace normalization)
+                pi->value(val, text - val);
+
+                // Place zero terminator after name and value
+                if (!(Flags & parse_no_string_terminators))
+                {
+                    pi->name()[pi->name_size()] = Ch('\0');
+                    pi->value()[pi->value_size()] = Ch('\0');
+                }
+                
+                text += 2;                          // Skip '?>'
+                return pi;
+            }
+            else
+            {
+                // Skip to '?>'
+                while (text[0] != Ch('?') || text[1] != Ch('>'))
+                {
+                    if (*text == Ch('\0'))
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+                text += 2;    // Skip '?>'
+                return 0;
+            }
+        }
+
+        // Parse and append data
+        // Return character that ends data.
+        // This is necessary because this character might have been overwritten by a terminating 0
+        template<int Flags>
+        Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start)
+        {
+            // Backup to contents start if whitespace trimming is disabled
+            if (!(Flags & parse_trim_whitespace))
+                text = contents_start;     
+            
+            // Skip until end of data
+            Ch *val = text, *end;
+            if (Flags & parse_normalize_whitespace)
+                end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred, Flags>(text);   
+            else
+                end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred, Flags>(text);
+
+            // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >
+            if (Flags & parse_trim_whitespace)
+            {
+                if (Flags & parse_normalize_whitespace)
+                {
+                    // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end
+                    if (*(end - 1) == Ch(' '))
+                        --end;
+                }
+                else
+                {
+                    // Backup until non-whitespace character is found
+                    while (whitespace_pred::test(*(end - 1)))
+                        --end;
+                }
+            }
+            
+            // If characters are still left between end and value (this test is only necessary if normalization is enabled)
+            // Create new data node
+            if (!(Flags & parse_no_data_nodes))
+            {
+                xml_node<Ch> *data = this->allocate_node(node_data);
+                data->value(val, end - val);
+                node->append_node(data);
+            }
+
+            // Add data to parent node if no data exists yet
+            if (!(Flags & parse_no_element_values)) 
+                if (*node->value() == Ch('\0'))
+                    node->value(val, end - val);
+
+            // Place zero terminator after value
+            if (!(Flags & parse_no_string_terminators))
+            {
+                Ch ch = *text;
+                *end = Ch('\0');
+                return ch;      // Return character that ends data; this is required because zero terminator overwritten it
+            }
+
+            // Return character that ends data
+            return *text;
+        }
+
+        // Parse CDATA
+        template<int Flags>
+        xml_node<Ch> *parse_cdata(Ch *&text)
+        {
+            // If CDATA is disabled
+            if (Flags & parse_no_data_nodes)
+            {
+                // Skip until end of cdata
+                while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
+                {
+                    if (!text[0])
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+                text += 3;      // Skip ]]>
+                return 0;       // Do not produce CDATA node
+            }
+
+            // Skip until end of cdata
+            Ch *val = text;
+            while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
+            {
+                if (!text[0])
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                ++text;
+            }
+
+            // Create new cdata node
+            xml_node<Ch> *cdata = this->allocate_node(node_cdata);
+            cdata->value(val, text - val);
+
+            // Place zero terminator after value
+            if (!(Flags & parse_no_string_terminators))
+                *text = Ch('\0');
+
+            text += 3;      // Skip ]]>
+            return cdata;
+        }
+        
+        // Parse element node
+        template<int Flags>
+        xml_node<Ch> *parse_element(Ch *&text)
+        {
+            // Create element node
+            xml_node<Ch> *element = this->allocate_node(node_element);
+
+            // Extract element name
+            Ch *n = text;
+            skip<node_name_pred, Flags>(text);
+            if (text == n)
+                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected element name", text);
+            element->name(n, text - n);
+            
+            // Skip whitespace between element name and attributes or >
+            skip<whitespace_pred, Flags>(text);
+
+            // Parse attributes, if any
+            parse_node_attributes<Flags>(text, element);
+
+            // Determine ending type
+            if (*text == Ch('>'))
+            {
+                ++text;
+                parse_node_contents<Flags>(text, element);
+            }
+            else if (*text == Ch('/'))
+            {
+                ++text;
+                if (*text != Ch('>'))
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
+                ++text;
+            }
+            else
+                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
+
+            // Place zero terminator after name
+            if (!(Flags & parse_no_string_terminators))
+                element->name()[element->name_size()] = Ch('\0');
+
+            // Return parsed element
+            return element;
+        }
+
+        // Determine node type, and parse it
+        template<int Flags>
+        xml_node<Ch> *parse_node(Ch *&text)
+        {
+            // Parse proper node type
+            switch (text[0])
+            {
+
+            // <...
+            default: 
+                // Parse and append element node
+                return parse_element<Flags>(text);
+
+            // <?...
+            case Ch('?'): 
+                ++text;     // Skip ?
+                if ((text[0] == Ch('x') || text[0] == Ch('X')) &&
+                    (text[1] == Ch('m') || text[1] == Ch('M')) && 
+                    (text[2] == Ch('l') || text[2] == Ch('L')) &&
+                    whitespace_pred::test(text[3]))
+                {
+                    // '<?xml ' - xml declaration
+                    text += 4;      // Skip 'xml '
+                    return parse_xml_declaration<Flags>(text);
+                }
+                else
+                {
+                    // Parse PI
+                    return parse_pi<Flags>(text);
+                }
+            
+            // <!...
+            case Ch('!'): 
+
+                // Parse proper subset of <! node
+                switch (text[1])    
+                {
+                
+                // <!-
+                case Ch('-'):
+                    if (text[2] == Ch('-'))
+                    {
+                        // '<!--' - xml comment
+                        text += 3;     // Skip '!--'
+                        return parse_comment<Flags>(text);
+                    }
+                    break;
+
+                // <![
+                case Ch('['):
+                    if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A') && 
+                        text[5] == Ch('T') && text[6] == Ch('A') && text[7] == Ch('['))
+                    {
+                        // '<![CDATA[' - cdata
+                        text += 8;     // Skip '![CDATA['
+                        return parse_cdata<Flags>(text);
+                    }
+                    break;
+
+                // <!D
+                case Ch('D'):
+                    if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T') && 
+                        text[5] == Ch('Y') && text[6] == Ch('P') && text[7] == Ch('E') && 
+                        whitespace_pred::test(text[8]))
+                    {
+                        // '<!DOCTYPE ' - doctype
+                        text += 9;      // skip '!DOCTYPE '
+                        return parse_doctype<Flags>(text);
+                    }
+                    break;
+
+                default: break;
+
+                }   // switch
+
+                // Attempt to skip other, unrecognized node types starting with <!
+                ++text;     // Skip !
+                while (*text != Ch('>'))
+                {
+                    if (*text == 0)
+                        BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+                    ++text;
+                }
+                ++text;     // Skip '>'
+                return 0;   // No node recognized
+
+            }
+        }
+
+        // Parse contents of the node - children, data etc.
+        template<int Flags>
+        void parse_node_contents(Ch *&text, xml_node<Ch> *node)
+        {
+            // For all children and text
+            while (1)
+            {
+                // Skip whitespace between > and node contents
+                Ch *contents_start = text;      // Store start of node contents before whitespace is skipped
+                if (Flags & parse_trim_whitespace)
+                    skip<whitespace_pred, Flags>(text);
+                Ch next_char = *text;
+
+            // After data nodes, instead of continuing the loop, control jumps here.
+            // This is because zero termination inside parse_and_append_data() function
+            // would wreak havoc with the above code.
+            // Also, skipping whitespace after data nodes is unnecessary.
+            after_data_node:    
+                
+                // Determine what comes next: node closing, child node, data node, or 0?
+                switch (next_char)
+                {
+                
+                // Node closing or child node
+                case Ch('<'):
+                    if (text[1] == Ch('/'))
+                    {
+                        // Node closing
+                        text += 2;      // Skip '</'
+                        if (Flags & parse_validate_closing_tags)
+                        {
+                            // Skip and validate closing tag name
+                            Ch *closing_name = text;
+                            skip<node_name_pred, Flags>(text);
+                            if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true))
+                                BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
+                        }
+                        else
+                        {
+                            // No validation, just skip name
+                            skip<node_name_pred, Flags>(text);
+                        }
+                        // Skip remaining whitespace after node name
+                        skip<whitespace_pred, Flags>(text);
+                        if (*text != Ch('>'))
+                            BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
+                        ++text;     // Skip '>'
+                        return;     // Node closed, finished parsing contents
+                    }
+                    else
+                    {
+                        // Child node
+                        ++text;     // Skip '<'
+                        if (xml_node<Ch> *child = parse_node<Flags>(text))
+                            node->append_node(child);
+                    }
+                    break;
+
+                // End of data - error
+                case Ch('\0'):
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+
+                // Data node
+                default:
+                    next_char = parse_and_append_data<Flags>(node, text, contents_start);
+                    goto after_data_node;   // Bypass regular processing after data nodes
+
+                }
+            }
+        }
+        
+        // Parse XML attributes of the node
+        template<int Flags>
+        void parse_node_attributes(Ch *&text, xml_node<Ch> *node)
+        {
+            // For all attributes 
+            while (attribute_name_pred::test(*text))
+            {
+                // Extract attribute name
+                Ch *n = text;
+                ++text;     // Skip first character of attribute name
+                skip<attribute_name_pred, Flags>(text);
+                if (text == n)
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected attribute name", n);
+
+                // Create new attribute
+                xml_attribute<Ch> *attribute = this->allocate_attribute();
+                attribute->name(n, text - n);
+                node->append_attribute(attribute);
+
+                // Skip whitespace after attribute name
+                skip<whitespace_pred, Flags>(text);
+
+                // Skip =
+                if (*text != Ch('='))
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected =", text);
+                ++text;
+
+                // Add terminating zero after name
+                if (!(Flags & parse_no_string_terminators))
+                    attribute->name()[attribute->name_size()] = 0;
+
+                // Skip whitespace after =
+                skip<whitespace_pred, Flags>(text);
+
+                // Skip quote and remember if it was ' or "
+                Ch quote = *text;
+                if (quote != Ch('\'') && quote != Ch('"'))
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
+                ++text;
+
+                // Extract attribute value and expand char refs in it
+                Ch *val = text, *end;
+                const int AttFlags = Flags & ~parse_normalize_whitespace;   // No whitespace normalization in attributes
+                if (quote == Ch('\''))
+                    end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>, attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);
+                else
+                    end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>, attribute_value_pure_pred<Ch('"')>, AttFlags>(text);
+                
+                // Set attribute value
+                attribute->value(val, end - val);
+                
+                // Make sure that end quote is present
+                if (*text != quote)
+                    BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
+                ++text;     // Skip quote
+
+                // Add terminating zero after value
+                if (!(Flags & parse_no_string_terminators))
+                    attribute->value()[attribute->value_size()] = 0;
+
+                // Skip whitespace after attribute value
+                skip<whitespace_pred, Flags>(text);
+            }
+        }
+
+    };
+
+    //! \cond internal
+    namespace internal
+    {
+
+        // Whitespace (space \n \r \t)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  0,  1,  0,  0,  // 0
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 1
+             1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 2
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 3
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 4
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 5
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 6
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 7
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 8
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // 9
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // A
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // B
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // C
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // D
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  // E
+             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0   // F
+        };
+
+        // Node name (anything but space \n \r \t / > ? \0)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_node_name[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Text (i.e. PCDATA) (anything but < \0)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_text[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Text (i.e. PCDATA) that does not require processing when ws normalization is disabled 
+        // (anything but < \0 &)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled
+        // (anything but < \0 & space \n \r \t)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             0,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Attribute name (anything but space \n \r \t / < > = ? ! \0)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Attribute data with single quote (anything but ' \0)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Attribute data with single quote that does not require processing (anything but ' \0 &)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Attribute data with double quote (anything but " \0)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Attribute data with double quote that does not require processing (anything but " \0 &)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+             0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
+             1,  1,  0,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 3
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
+             1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
+        };
+
+        // Digits (dec and hex, 255 denotes end of numeric character reference)
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_digits[256] = 
+        {
+          // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 0
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 1
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 2
+             0,  1,  2,  3,  4,  5,  6,  7,  8,  9,255,255,255,255,255,255,  // 3
+           255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255,  // 4
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 5
+           255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255,  // 6
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 7
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 8
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // 9
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // A
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // B
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // C
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // D
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,  // E
+           255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255   // F
+        };
+    
+        // Upper case conversion
+        template<int Dummy>
+        const unsigned char lookup_tables<Dummy>::lookup_upcase[256] = 
+        {
+          // 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  A   B   C   D   E   F
+           0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,   // 0
+           16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,   // 1
+           32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,   // 2
+           48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,   // 3
+           64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   // 4
+           80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,   // 5
+           96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   // 6
+           80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127,  // 7
+           128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,  // 8
+           144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,  // 9
+           160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,  // A
+           176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,  // B
+           192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,  // C
+           208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,  // D
+           224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,  // E
+           240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255   // F
+        };
+    }
+    //! \endcond
+
+}}}}
+
+// Undefine internal macros
+#undef BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
+
+// On MSVC, restore warnings state
+#ifdef _MSC_VER
+    #pragma warning(pop)
+#endif
+
+#endif
diff --git a/include/liblas/external/property_tree/xml_parser.hpp b/include/liblas/external/property_tree/xml_parser.hpp
index fc199a6..f524219 100644
--- a/include/liblas/external/property_tree/xml_parser.hpp
+++ b/include/liblas/external/property_tree/xml_parser.hpp
@@ -1,153 +1,153 @@
-// ----------------------------------------------------------------------------
-// Copyright (C) 2002-2006 Marcin Kalicinski
-// Copyright (C) 2009 Sebastian Redl
-//
-// Distributed under the Boost Software License, Version 1.0. 
-// (See accompanying file LICENSE_1_0.txt or copy at 
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// For more information, see www.boost.org
-// ----------------------------------------------------------------------------
-#ifndef LIBLAS_BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED
-#define LIBLAS_BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED
-
-#include <liblas/external/property_tree/ptree.hpp>
-#include <liblas/external/property_tree/detail/xml_parser_write.hpp>
-#include <liblas/external/property_tree/detail/xml_parser_error.hpp>
-#include <liblas/external/property_tree/detail/xml_parser_writer_settings.hpp>
-#include <liblas/external/property_tree/detail/xml_parser_flags.hpp>
-#include <liblas/external/property_tree/detail/xml_parser_read_rapidxml.hpp>
-
-#include <fstream>
-#include <string>
-#include <locale>
-
-namespace liblas { namespace property_tree { namespace xml_parser
-{
-
-    /**
-     * Reads XML from an input stream and translates it to property tree.
-     * @note Clears existing contents of property tree.  In case of error the
-     *       property tree unmodified.
-     * @note XML attributes are placed under keys named @c \<xmlattr\>.
-     * @throw xml_parser_error In case of error deserializing the property tree.
-     * @param stream Stream from which to read in the property tree.
-     * @param[out] pt The property tree to populate.
-     * @param flags Flags controlling the behaviour of the parser.
-     *              The following flags are supported:
-     * @li @c no_concat_text -- Prevents concatenation of text nodes into
-     *                          datastring of property tree.  Puts them in
-     *                          separate @c \<xmltext\> strings instead.
-     * @li @c no_comments -- Skip XML comments.
-     * @li @c trim_whitespace -- Trim leading and trailing whitespace from text,
-     *                           and collapse sequences of whitespace.
-     */
-    template<class Ptree>
-    void read_xml(std::basic_istream<
-                      typename Ptree::key_type::value_type
-                  > &stream,
-                  Ptree &pt,
-                  int flags = 0)
-    {
-        read_xml_internal(stream, pt, flags, std::string());
-    }
-
-    /**
-     * Reads XML from a file using the given locale and translates it to
-     * property tree.
-     * @note Clears existing contents of property tree.  In case of error the
-     *       property tree unmodified.
-     * @note XML attributes are placed under keys named @c \<xmlattr\>.
-     * @throw xml_parser_error In case of error deserializing the property tree.
-     * @param filename The file from which to read in the property tree.
-     * @param[out] pt The property tree to populate.
-     * @param flags Flags controlling the bahviour of the parser.
-     *              The following flags are supported:
-     * @li @c no_concat_text -- Prevents concatenation of text nodes into
-     *                          datastring of property tree.  Puts them in
-     *                          separate @c \<xmltext\> strings instead.
-     * @li @c no_comments -- Skip XML comments.
-     * @param loc The locale to use when reading in the file contents.
-     */
-    template<class Ptree>
-    void read_xml(const std::string &filename,
-                  Ptree &pt,
-                  int flags = 0,
-                  const std::locale &loc = std::locale())
-    {
-        BOOST_ASSERT(validate_flags(flags));
-        std::basic_ifstream<typename Ptree::key_type::value_type>
-            stream(filename.c_str());
-        if (!stream)
-            BOOST_PROPERTY_TREE_THROW(xml_parser_error(
-                "cannot open file", filename, 0));
-        stream.imbue(loc);
-        read_xml_internal(stream, pt, flags, filename);
-    }
-
-    /**
-     * Translates the property tree to XML and writes it the given output
-     * stream.
-     * @throw xml_parser_error In case of error translating the property tree to
-     *                         XML or writing to the output stream.
-     * @param stream The stream to which to write the XML representation of the 
-     *               property tree.
-     * @param pt The property tree to tranlsate to XML and output.
-     * @param settings The settings to use when writing out the property tree as
-     *                 XML.
-     */
-    template<class Ptree>
-    void write_xml(std::basic_ostream<
-                       typename Ptree::key_type::value_type
-                   > &stream,
-                   const Ptree &pt,
-                   const xml_writer_settings<
-                       typename Ptree::key_type::value_type
-                   > & settings = xml_writer_settings<
-                                    typename Ptree::key_type::value_type>() )
-    {
-        write_xml_internal(stream, pt, std::string(), settings);
-    }
-
-    /**
-     * Translates the property tree to XML and writes it the given file.
-     * @throw xml_parser_error In case of error translating the property tree to
-     *                         XML or writing to the output stream.
-     * @param filename The file to which to write the XML representation of the 
-     *                 property tree.
-     * @param pt The property tree to tranlsate to XML and output.
-     * @param loc The locale to use when writing the output to file.
-     * @param settings The settings to use when writing out the property tree as
-     *                 XML.
-     */
-    template<class Ptree>
-    void write_xml(const std::string &filename,
-                   const Ptree &pt,
-                   const std::locale &loc = std::locale(),
-                   const xml_writer_settings<
-                       typename Ptree::key_type::value_type
-                   > & settings = xml_writer_settings<
-                                    typename Ptree::key_type::value_type>())
-    {
-        std::basic_ofstream<typename Ptree::key_type::value_type>
-            stream(filename.c_str());
-        if (!stream)
-            BOOST_PROPERTY_TREE_THROW(xml_parser_error(
-                "cannot open file", filename, 0));
-        stream.imbue(loc);
-        write_xml_internal(stream, pt, filename, settings);
-    }
-
-} } }
-
-namespace liblas { namespace property_tree
-{
-    using xml_parser::read_xml;
-    using xml_parser::write_xml;
-    using xml_parser::xml_parser_error;
-
-    using xml_parser::xml_writer_settings;
-    using xml_parser::xml_writer_make_settings;
-} }
-
-#endif
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+// Copyright (C) 2009 Sebastian Redl
+//
+// Distributed under the Boost Software License, Version 1.0. 
+// (See accompanying file LICENSE_1_0.txt or copy at 
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#ifndef LIBLAS_BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED
+#define LIBLAS_BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED
+
+#include <liblas/external/property_tree/ptree.hpp>
+#include <liblas/external/property_tree/detail/xml_parser_write.hpp>
+#include <liblas/external/property_tree/detail/xml_parser_error.hpp>
+#include <liblas/external/property_tree/detail/xml_parser_writer_settings.hpp>
+#include <liblas/external/property_tree/detail/xml_parser_flags.hpp>
+#include <liblas/external/property_tree/detail/xml_parser_read_rapidxml.hpp>
+
+#include <fstream>
+#include <string>
+#include <locale>
+
+namespace liblas { namespace property_tree { namespace xml_parser
+{
+
+    /**
+     * Reads XML from an input stream and translates it to property tree.
+     * @note Clears existing contents of property tree.  In case of error the
+     *       property tree unmodified.
+     * @note XML attributes are placed under keys named @c \<xmlattr\>.
+     * @throw xml_parser_error In case of error deserializing the property tree.
+     * @param stream Stream from which to read in the property tree.
+     * @param[out] pt The property tree to populate.
+     * @param flags Flags controlling the behaviour of the parser.
+     *              The following flags are supported:
+     * @li @c no_concat_text -- Prevents concatenation of text nodes into
+     *                          datastring of property tree.  Puts them in
+     *                          separate @c \<xmltext\> strings instead.
+     * @li @c no_comments -- Skip XML comments.
+     * @li @c trim_whitespace -- Trim leading and trailing whitespace from text,
+     *                           and collapse sequences of whitespace.
+     */
+    template<class Ptree>
+    void read_xml(std::basic_istream<
+                      typename Ptree::key_type::value_type
+                  > &stream,
+                  Ptree &pt,
+                  int flags = 0)
+    {
+        read_xml_internal(stream, pt, flags, std::string());
+    }
+
+    /**
+     * Reads XML from a file using the given locale and translates it to
+     * property tree.
+     * @note Clears existing contents of property tree.  In case of error the
+     *       property tree unmodified.
+     * @note XML attributes are placed under keys named @c \<xmlattr\>.
+     * @throw xml_parser_error In case of error deserializing the property tree.
+     * @param filename The file from which to read in the property tree.
+     * @param[out] pt The property tree to populate.
+     * @param flags Flags controlling the bahviour of the parser.
+     *              The following flags are supported:
+     * @li @c no_concat_text -- Prevents concatenation of text nodes into
+     *                          datastring of property tree.  Puts them in
+     *                          separate @c \<xmltext\> strings instead.
+     * @li @c no_comments -- Skip XML comments.
+     * @param loc The locale to use when reading in the file contents.
+     */
+    template<class Ptree>
+    void read_xml(const std::string &filename,
+                  Ptree &pt,
+                  int flags = 0,
+                  const std::locale &loc = std::locale())
+    {
+        BOOST_ASSERT(validate_flags(flags));
+        std::basic_ifstream<typename Ptree::key_type::value_type>
+            stream(filename.c_str());
+        if (!stream)
+            BOOST_PROPERTY_TREE_THROW(xml_parser_error(
+                "cannot open file", filename, 0));
+        stream.imbue(loc);
+        read_xml_internal(stream, pt, flags, filename);
+    }
+
+    /**
+     * Translates the property tree to XML and writes it the given output
+     * stream.
+     * @throw xml_parser_error In case of error translating the property tree to
+     *                         XML or writing to the output stream.
+     * @param stream The stream to which to write the XML representation of the 
+     *               property tree.
+     * @param pt The property tree to tranlsate to XML and output.
+     * @param settings The settings to use when writing out the property tree as
+     *                 XML.
+     */
+    template<class Ptree>
+    void write_xml(std::basic_ostream<
+                       typename Ptree::key_type::value_type
+                   > &stream,
+                   const Ptree &pt,
+                   const xml_writer_settings<
+                       typename Ptree::key_type::value_type
+                   > & settings = xml_writer_settings<
+                                    typename Ptree::key_type::value_type>() )
+    {
+        write_xml_internal(stream, pt, std::string(), settings);
+    }
+
+    /**
+     * Translates the property tree to XML and writes it the given file.
+     * @throw xml_parser_error In case of error translating the property tree to
+     *                         XML or writing to the output stream.
+     * @param filename The file to which to write the XML representation of the 
+     *                 property tree.
+     * @param pt The property tree to tranlsate to XML and output.
+     * @param loc The locale to use when writing the output to file.
+     * @param settings The settings to use when writing out the property tree as
+     *                 XML.
+     */
+    template<class Ptree>
+    void write_xml(const std::string &filename,
+                   const Ptree &pt,
+                   const std::locale &loc = std::locale(),
+                   const xml_writer_settings<
+                       typename Ptree::key_type::value_type
+                   > & settings = xml_writer_settings<
+                                    typename Ptree::key_type::value_type>())
+    {
+        std::basic_ofstream<typename Ptree::key_type::value_type>
+            stream(filename.c_str());
+        if (!stream)
+            BOOST_PROPERTY_TREE_THROW(xml_parser_error(
+                "cannot open file", filename, 0));
+        stream.imbue(loc);
+        write_xml_internal(stream, pt, filename, settings);
+    }
+
+} } }
+
+namespace liblas { namespace property_tree
+{
+    using xml_parser::read_xml;
+    using xml_parser::write_xml;
+    using xml_parser::xml_parser_error;
+
+    using xml_parser::xml_writer_settings;
+    using xml_parser::xml_writer_make_settings;
+} }
+
+#endif
diff --git a/python/liblas/header.py b/python/liblas/header.py
index b26bc7f..149d3cd 100644
--- a/python/liblas/header.py
+++ b/python/liblas/header.py
@@ -142,14 +142,14 @@ class Header(object):
             2, "Waveform Data Packets External", "If this bit is set, the
             waveform data packets are located external to this file in an
             auxiliary file with the same base name as this file and the
-            extension \".wdp\". (note that this bit is mutually exclusive with
+            extension .wdp. (note that this bit is mutually exclusive with
             bit 1)"
             3, "Return numbers have been synthetically generated", "If set,
             the point return numbers in the Point Data Records have been
             synthetically generated. This could be the case, for example, when
             a composite file is created by combining a First Return File and a
             Last Return File. In this case, first return data will be labeled
-            \"1 of 2\" and second return data will be labeled \"2 of 2\""
+            '1 of 2' and second return data will be labeled '2 of 2'"
             4:15, "Reserved", "Must be set to zero"
 
     """
@@ -256,14 +256,13 @@ class Header(object):
                 :header: "Generating Agent", "System ID"
                 :widths: 40, 60
 
-                "Hardware system", "String identifying hardware (e.g. \"ALTM
-                1210\" or \"ALS50\""
+                "Hardware system","String identifying hardware (e.g. ALTM 1210 or ALS50"
                 "Merge of one or more files","MERGE"
                 "Modification of a single file","MODIFICATION"
                 "Extraction from one or more files", "EXTRACTION"
                 "Reprojection, rescaling, warping, etc.","TRANSFORMATION"
-                "Some other operation","\"OTHER\" or a string up to 32
-                characters identifying the operation"
+                "Some other operation","OTHER or a string up to 32 characters identifying the operation"
+
 
         >>> h.system_id
         ''
diff --git a/python/tests/Header.txt b/python/tests/Header.txt
index 9b98645..a5d6af9 100644
--- a/python/tests/Header.txt
+++ b/python/tests/Header.txt
@@ -48,7 +48,7 @@
   datetime.datetime(2008, 3, 19, 0, 0)
 
   >>> h.software_id
-  'libLAS 1.8.0'
+  'libLAS 1.8.1'
   >>> h.software_id = 'hobu'
   >>> h.software_id
   'hobu'
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8f9b2a6..e35de06 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,267 +1,267 @@
-###############################################################################
-#
-# src/CMakeLists.txt controls building of libLAS library
-#
-# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
-#
-###############################################################################
-
-# Collect dependencies configuration
-if(GDAL_FOUND)
-  set(LIBLAS_GDAL_CPP
-    gt_citation.cpp
-    gt_wkt_srs.cpp
-    tifvsi.cpp)
-endif()
-
-###############################################################################
-# Source files specification
-
-set(LIBLAS_HEADERS_DIR ../include/liblas)
-
-set(LIBLAS_HPP
-  ${LIBLAS_HEADERS_DIR}/chipper.hpp
-  ${LIBLAS_HEADERS_DIR}/exception.hpp
-  ${LIBLAS_HEADERS_DIR}/export.hpp
-  ${LIBLAS_HEADERS_DIR}/factory.hpp 
-  ${LIBLAS_HEADERS_DIR}/iterator.hpp
-  ${LIBLAS_HEADERS_DIR}/bounds.hpp
-  ${LIBLAS_HEADERS_DIR}/classification.hpp
-  ${LIBLAS_HEADERS_DIR}/color.hpp
-  ${LIBLAS_HEADERS_DIR}/dimension.hpp  
-  ${LIBLAS_HEADERS_DIR}/error.hpp
-  ${LIBLAS_HEADERS_DIR}/filter.hpp
-  ${LIBLAS_HEADERS_DIR}/header.hpp
-  ${LIBLAS_HEADERS_DIR}/index.hpp
-  ${LIBLAS_HEADERS_DIR}/point.hpp
-  ${LIBLAS_HEADERS_DIR}/reader.hpp
-  ${LIBLAS_HEADERS_DIR}/schema.hpp
-  ${LIBLAS_HEADERS_DIR}/spatialreference.hpp
-  ${LIBLAS_HEADERS_DIR}/transform.hpp  
-  ${LIBLAS_HEADERS_DIR}/variablerecord.hpp
-  ${LIBLAS_HEADERS_DIR}/writer.hpp
-  ${LIBLAS_HEADERS_DIR}/liblas.hpp
-  ${LIBLAS_HEADERS_DIR}/utility.hpp
-  ${LIBLAS_HEADERS_DIR}/version.hpp)
-
-set(LIBLAS_EXTERNAL_HPP)
-
-set(LIBLAS_EXTERNAL_PROPERTY_TREE_HPP
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/exceptions.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/id_translator.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/info_parser.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/ini_parser.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/json_parser.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree_fwd.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree_serialization.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/stream_translator.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/string_path.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/xml_parser.hpp)
-
-set(LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/exception_implementation.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/file_parser_error.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_error.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_read.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_utils.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_write.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_writer_settings.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_error.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_read.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_write.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/ptree_implementation.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/ptree_utils.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/rapidxml.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_error.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_flags.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_read_rapidxml.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_utils.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_write.hpp
-  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_writer_settings.hpp)
-
-set(LIBLAS_DETAIL_HPP
-  ${LIBLAS_HEADERS_DIR}/detail/binary.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/endian.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/fwd.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/pointrecord.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/timer.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/private_utility.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/singleton.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/zippoint.hpp)
-
-set(LIBLAS_DETAIL_INDEX_HPP
-  ${LIBLAS_HEADERS_DIR}/detail/index/indexoutput.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/index/indexcell.hpp)
-  
-set(LIBLAS_DETAIL_READER_HPP
-  ${LIBLAS_HEADERS_DIR}/detail/reader/cachedreader.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/reader/reader.hpp  
-  ${LIBLAS_HEADERS_DIR}/detail/reader/zipreader.hpp  
-  ${LIBLAS_HEADERS_DIR}/detail/reader/header.hpp
-  )
-
-set(LIBLAS_DETAIL_WRITER_HPP
-  ${LIBLAS_HEADERS_DIR}/detail/writer/writer.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/writer/zipwriter.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/writer/point.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/writer/header.hpp)
-
-set(LIBLAS_CPP
-  chipper.cpp
-  factory.cpp
-  classification.cpp
-  color.cpp
-  dimension.cpp
-  error.cpp
-  filter.cpp
-  header.cpp
-  index.cpp
-  point.cpp
-  reader.cpp
-  spatialreference.cpp
-  schema.cpp
-  transform.cpp
-  utility.cpp
-  variablerecord.cpp
-  writer.cpp
-  version.cpp)
-
-set(LIBLAS_DETAIL_CPP
-  detail/utility.cpp
-  detail/sha1.cpp
-  detail/zippoint.cpp
-)
-  
-set(LIBLAS_DETAIL_INDEX_CPP
-  detail/index/indexcell.cpp
-  detail/index/indexoutput.cpp)
-
-set(LIBLAS_DETAIL_READER_CPP
-  detail/reader/header.cpp
-  detail/reader/reader.cpp
-  detail/reader/zipreader.cpp
-  detail/reader/cachedreader.cpp)
-
-set(LIBLAS_DETAIL_WRITER_CPP
-  detail/writer/header.cpp
-  detail/writer/point.cpp
-  detail/writer/zipwriter.cpp
-  detail/writer/writer.cpp)
-
-# Group source files for IDE source explorers (e.g. Visual Studio)
-source_group("CMake Files" FILES CMakeLists.txt)
-source_group("Header Files" FILES ${LIBLAS_HPP})
-source_group("Header Files\\external" FILES ${LIBLAS_EXTERNAL_HPP})
-source_group("Header Files\\external\\property_tree" FILES ${LIBLAS_EXTERNAL_PROPERTY_TREE_HPP})
-source_group("Header Files\\external\\property_tree\\detail" FILES ${LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP})
-source_group("Header Files\\detail" FILES ${LIBLAS_DETAIL_HPP})
-source_group("Header Files\\detail\\index" FILES ${LIBLAS_DETAIL_INDEX_HPP})
-source_group("Header Files\\detail\\reader" FILES ${LIBLAS_DETAIL_READER_HPP})
-source_group("Header Files\\detail\\writer" FILES ${LIBLAS_DETAIL_WRITER_HPP})
-source_group("Source Files" FILES ${LIBLAS_CPP})
-source_group("Source Files\\detail" FILES ${LIBLAS_DETAIL_CPP})
-source_group("Source Files\\detail\\index" FILES ${LIBLAS_DETAIL_INDEX_CPP})
-source_group("Source Files\\detail\\reader" FILES ${LIBLAS_DETAIL_READER_CPP})
-source_group("Source Files\\detail\\writer" FILES ${LIBLAS_DETAIL_WRITER_CPP})
-if(GDAL_FOUND)
-    source_group("Source Files\\gdal" FILES ${LIBLAS_GDAL_CPP})
-endif()
-
-# Diable Visual C++ language extensions when building libLAS library
-# Need this enabled for boost to work -- hobu
-#if (WIN32)
-#  if (MSVC)
-#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
-#  endif()
-#endif()
-
-# Standard include directory of libLAS library
-include_directories(../include)
-
-###############################################################################
-# Targets settings
-
-set(LIBLAS_SOURCES
-  ${LIBLAS_HPP}
-  ${LIBLAS_EXTERNAL_HPP}
-  ${LIBLAS_EXTERNAL_PROPERTY_TREE_HPP}
-  ${LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP}
-  ${LIBLAS_DETAIL_HPP}
-  ${LIBLAS_DETAIL_READER_HPP}
-  ${LIBLAS_DETAIL_WRITER_HPP}
-  ${LIBLAS_DETAIL_INDEX_CPP}
-  ${LIBLAS_CPP}
-  ${LIBLAS_DETAIL_CPP}
-  ${LIBLAS_DETAIL_READER_CPP}
-  ${LIBLAS_DETAIL_WRITER_CPP}
-  ${LIBLAS_GDAL_CPP})
-
-set(LIBLAS_C_SOURCES
-  ${LIBLAS_HEADERS_DIR}/capi/las_config.h
-  ${LIBLAS_HEADERS_DIR}/capi/las_version.h
-  ${LIBLAS_HEADERS_DIR}/capi/liblas.h
-  c_api.cpp)
-
-# NOTE:
-# This hack is required to correctly link static into shared library.
-# Such practice is not recommended as not portable, instead each library,
-# static and shared should be built from sources separately.
-#if(UNIX)
-#  add_definitions("-fPIC")
-#endif()
-
-if(WIN32)
-    add_definitions("-DLAS_DLL_EXPORT=1")
-if (NOT WITH_STATIC_LASZIP)
-    add_definitions("-DLASZIP_DLL_IMPORT=1")
-endif()
-endif()
-
-add_library(${LIBLAS_LIB_NAME} SHARED ${LIBLAS_SOURCES})
-add_library(${LIBLAS_C_LIB_NAME} SHARED ${LIBLAS_C_SOURCES})
-
-target_link_libraries(${LIBLAS_LIB_NAME}
-  ${TIFF_LIBRARY}
-  ${GEOTIFF_LIBRARY}
-  ${GDAL_LIBRARY}
-  ${LASZIP_LIBRARY}
-  ${Boost_LIBRARIES})
-
-target_link_libraries(${LIBLAS_C_LIB_NAME}
-  ${LIBLAS_LIB_NAME} )
-
-set_target_properties(${LIBLAS_LIB_NAME}
-  PROPERTIES
-  VERSION "${LIBLAS_LIB_VERSION}"
-  SOVERSION "${LIBLAS_LIB_SOVERSION}")
-set_target_properties(${LIBLAS_C_LIB_NAME}
-  PROPERTIES
-  VERSION "${LIBLAS_C_LIB_VERSION}"
-  SOVERSION "${LIBLAS_C_LIB_SOVERSION}")
-
-if (APPLE)
-  set_target_properties(
-    ${LIBLAS_C_LIB_NAME}
-    PROPERTIES
-    INSTALL_NAME_DIR "@rpath" BUILD_WITH_INSTALL_RPATH ON)
-  set_target_properties(
-    ${LIBLAS_LIB_NAME}
-    PROPERTIES
-    INSTALL_NAME_DIR "@rpath" BUILD_WITH_INSTALL_RPATH ON)
-endif()
-
-###############################################################################
-# Targets installation.  The EXPORT clause specifies a depends target
-# which packages up information about the libraries for
-# liblas-config.cmake.
-
-install(TARGETS ${LIBLAS_LIB_NAME} ${LIBLAS_C_LIB_NAME}
-  EXPORT depends
-  RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
-  LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
-  ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
-
-install(DIRECTORY ${LIBLAS_HEADERS_DIR}
-  DESTINATION ${LIBLAS_INCLUDE_DIR}
-  FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
+###############################################################################
+#
+# src/CMakeLists.txt controls building of libLAS library
+#
+# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
+#
+###############################################################################
+
+# Collect dependencies configuration
+if(GDAL_FOUND)
+  set(LIBLAS_GDAL_CPP
+    gt_citation.cpp
+    gt_wkt_srs.cpp
+    tifvsi.cpp)
+endif()
+
+###############################################################################
+# Source files specification
+
+set(LIBLAS_HEADERS_DIR ../include/liblas)
+
+set(LIBLAS_HPP
+  ${LIBLAS_HEADERS_DIR}/chipper.hpp
+  ${LIBLAS_HEADERS_DIR}/exception.hpp
+  ${LIBLAS_HEADERS_DIR}/export.hpp
+  ${LIBLAS_HEADERS_DIR}/factory.hpp 
+  ${LIBLAS_HEADERS_DIR}/iterator.hpp
+  ${LIBLAS_HEADERS_DIR}/bounds.hpp
+  ${LIBLAS_HEADERS_DIR}/classification.hpp
+  ${LIBLAS_HEADERS_DIR}/color.hpp
+  ${LIBLAS_HEADERS_DIR}/dimension.hpp  
+  ${LIBLAS_HEADERS_DIR}/error.hpp
+  ${LIBLAS_HEADERS_DIR}/filter.hpp
+  ${LIBLAS_HEADERS_DIR}/header.hpp
+  ${LIBLAS_HEADERS_DIR}/index.hpp
+  ${LIBLAS_HEADERS_DIR}/point.hpp
+  ${LIBLAS_HEADERS_DIR}/reader.hpp
+  ${LIBLAS_HEADERS_DIR}/schema.hpp
+  ${LIBLAS_HEADERS_DIR}/spatialreference.hpp
+  ${LIBLAS_HEADERS_DIR}/transform.hpp  
+  ${LIBLAS_HEADERS_DIR}/variablerecord.hpp
+  ${LIBLAS_HEADERS_DIR}/writer.hpp
+  ${LIBLAS_HEADERS_DIR}/liblas.hpp
+  ${LIBLAS_HEADERS_DIR}/utility.hpp
+  ${LIBLAS_HEADERS_DIR}/version.hpp)
+
+set(LIBLAS_EXTERNAL_HPP)
+
+set(LIBLAS_EXTERNAL_PROPERTY_TREE_HPP
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/exceptions.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/id_translator.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/info_parser.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/ini_parser.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/json_parser.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree_fwd.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/ptree_serialization.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/stream_translator.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/string_path.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/xml_parser.hpp)
+
+set(LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/exception_implementation.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/file_parser_error.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_error.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_read.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_utils.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_write.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/info_parser_writer_settings.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_error.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_read.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/json_parser_write.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/ptree_implementation.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/ptree_utils.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/rapidxml.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_error.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_flags.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_read_rapidxml.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_utils.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_write.hpp
+  ${LIBLAS_HEADERS_DIR}/external/property_tree/detail/xml_parser_writer_settings.hpp)
+
+set(LIBLAS_DETAIL_HPP
+  ${LIBLAS_HEADERS_DIR}/detail/binary.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/endian.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/fwd.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/pointrecord.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/timer.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/private_utility.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/singleton.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/zippoint.hpp)
+
+set(LIBLAS_DETAIL_INDEX_HPP
+  ${LIBLAS_HEADERS_DIR}/detail/index/indexoutput.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/index/indexcell.hpp)
+  
+set(LIBLAS_DETAIL_READER_HPP
+  ${LIBLAS_HEADERS_DIR}/detail/reader/cachedreader.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/reader/reader.hpp  
+  ${LIBLAS_HEADERS_DIR}/detail/reader/zipreader.hpp  
+  ${LIBLAS_HEADERS_DIR}/detail/reader/header.hpp
+  )
+
+set(LIBLAS_DETAIL_WRITER_HPP
+  ${LIBLAS_HEADERS_DIR}/detail/writer/writer.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/writer/zipwriter.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/writer/point.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/writer/header.hpp)
+
+set(LIBLAS_CPP
+  chipper.cpp
+  factory.cpp
+  classification.cpp
+  color.cpp
+  dimension.cpp
+  error.cpp
+  filter.cpp
+  header.cpp
+  index.cpp
+  point.cpp
+  reader.cpp
+  spatialreference.cpp
+  schema.cpp
+  transform.cpp
+  utility.cpp
+  variablerecord.cpp
+  writer.cpp
+  version.cpp)
+
+set(LIBLAS_DETAIL_CPP
+  detail/utility.cpp
+  detail/sha1.cpp
+  detail/zippoint.cpp
+)
+  
+set(LIBLAS_DETAIL_INDEX_CPP
+  detail/index/indexcell.cpp
+  detail/index/indexoutput.cpp)
+
+set(LIBLAS_DETAIL_READER_CPP
+  detail/reader/header.cpp
+  detail/reader/reader.cpp
+  detail/reader/zipreader.cpp
+  detail/reader/cachedreader.cpp)
+
+set(LIBLAS_DETAIL_WRITER_CPP
+  detail/writer/header.cpp
+  detail/writer/point.cpp
+  detail/writer/zipwriter.cpp
+  detail/writer/writer.cpp)
+
+# Group source files for IDE source explorers (e.g. Visual Studio)
+source_group("CMake Files" FILES CMakeLists.txt)
+source_group("Header Files" FILES ${LIBLAS_HPP})
+source_group("Header Files\\external" FILES ${LIBLAS_EXTERNAL_HPP})
+source_group("Header Files\\external\\property_tree" FILES ${LIBLAS_EXTERNAL_PROPERTY_TREE_HPP})
+source_group("Header Files\\external\\property_tree\\detail" FILES ${LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP})
+source_group("Header Files\\detail" FILES ${LIBLAS_DETAIL_HPP})
+source_group("Header Files\\detail\\index" FILES ${LIBLAS_DETAIL_INDEX_HPP})
+source_group("Header Files\\detail\\reader" FILES ${LIBLAS_DETAIL_READER_HPP})
+source_group("Header Files\\detail\\writer" FILES ${LIBLAS_DETAIL_WRITER_HPP})
+source_group("Source Files" FILES ${LIBLAS_CPP})
+source_group("Source Files\\detail" FILES ${LIBLAS_DETAIL_CPP})
+source_group("Source Files\\detail\\index" FILES ${LIBLAS_DETAIL_INDEX_CPP})
+source_group("Source Files\\detail\\reader" FILES ${LIBLAS_DETAIL_READER_CPP})
+source_group("Source Files\\detail\\writer" FILES ${LIBLAS_DETAIL_WRITER_CPP})
+if(GDAL_FOUND)
+    source_group("Source Files\\gdal" FILES ${LIBLAS_GDAL_CPP})
+endif()
+
+# Diable Visual C++ language extensions when building libLAS library
+# Need this enabled for boost to work -- hobu
+#if (WIN32)
+#  if (MSVC)
+#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
+#  endif()
+#endif()
+
+# Standard include directory of libLAS library
+include_directories(../include)
+
+###############################################################################
+# Targets settings
+
+set(LIBLAS_SOURCES
+  ${LIBLAS_HPP}
+  ${LIBLAS_EXTERNAL_HPP}
+  ${LIBLAS_EXTERNAL_PROPERTY_TREE_HPP}
+  ${LIBLAS_EXTERNAL_PROPERTY_TREE_DETAIL_HPP}
+  ${LIBLAS_DETAIL_HPP}
+  ${LIBLAS_DETAIL_READER_HPP}
+  ${LIBLAS_DETAIL_WRITER_HPP}
+  ${LIBLAS_DETAIL_INDEX_CPP}
+  ${LIBLAS_CPP}
+  ${LIBLAS_DETAIL_CPP}
+  ${LIBLAS_DETAIL_READER_CPP}
+  ${LIBLAS_DETAIL_WRITER_CPP}
+  ${LIBLAS_GDAL_CPP})
+
+set(LIBLAS_C_SOURCES
+  ${LIBLAS_HEADERS_DIR}/capi/las_config.h
+  ${LIBLAS_HEADERS_DIR}/capi/las_version.h
+  ${LIBLAS_HEADERS_DIR}/capi/liblas.h
+  c_api.cpp)
+
+# NOTE:
+# This hack is required to correctly link static into shared library.
+# Such practice is not recommended as not portable, instead each library,
+# static and shared should be built from sources separately.
+#if(UNIX)
+#  add_definitions("-fPIC")
+#endif()
+
+if(WIN32)
+    add_definitions("-DLAS_DLL_EXPORT=1")
+if (NOT WITH_STATIC_LASZIP)
+    add_definitions("-DLASZIP_DLL_IMPORT=1")
+endif()
+endif()
+
+add_library(${LIBLAS_LIB_NAME} SHARED ${LIBLAS_SOURCES})
+add_library(${LIBLAS_C_LIB_NAME} SHARED ${LIBLAS_C_SOURCES})
+
+target_link_libraries(${LIBLAS_LIB_NAME}
+  ${TIFF_LIBRARY}
+  ${GEOTIFF_LIBRARY}
+  ${GDAL_LIBRARY}
+  ${LASZIP_LIBRARY}
+  ${Boost_LIBRARIES})
+
+target_link_libraries(${LIBLAS_C_LIB_NAME}
+  ${LIBLAS_LIB_NAME} )
+
+set_target_properties(${LIBLAS_LIB_NAME}
+  PROPERTIES
+  VERSION "${LIBLAS_LIB_VERSION}"
+  SOVERSION "${LIBLAS_LIB_SOVERSION}")
+set_target_properties(${LIBLAS_C_LIB_NAME}
+  PROPERTIES
+  VERSION "${LIBLAS_C_LIB_VERSION}"
+  SOVERSION "${LIBLAS_C_LIB_SOVERSION}")
+
+if (APPLE)
+  set_target_properties(
+    ${LIBLAS_C_LIB_NAME}
+    PROPERTIES
+    INSTALL_NAME_DIR "@rpath" BUILD_WITH_INSTALL_RPATH ON)
+  set_target_properties(
+    ${LIBLAS_LIB_NAME}
+    PROPERTIES
+    INSTALL_NAME_DIR "@rpath" BUILD_WITH_INSTALL_RPATH ON)
+endif()
+
+###############################################################################
+# Targets installation.  The EXPORT clause specifies a depends target
+# which packages up information about the libraries for
+# liblas-config.cmake.
+
+install(TARGETS ${LIBLAS_LIB_NAME} ${LIBLAS_C_LIB_NAME}
+  EXPORT depends
+  RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
+  LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
+  ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
+
+install(DIRECTORY ${LIBLAS_HEADERS_DIR}
+  DESTINATION ${LIBLAS_INCLUDE_DIR}
+  FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
diff --git a/src/detail/reader/header.cpp b/src/detail/reader/header.cpp
index 4773bd2..a7eaa48 100644
--- a/src/detail/reader/header.cpp
+++ b/src/detail/reader/header.cpp
@@ -2,43 +2,43 @@
  * $Id$
  *
  * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose:  Header Reader implementation for C++ libLAS 
+ * Purpose:  Header Reader implementation for C++ libLAS
  * Author:   Howard Butler, hobu.inc at gmail.com
  *
  ******************************************************************************
  * Copyright (c) 2010, Howard Butler
  *
  * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
  * conditions are met:
- * 
- *     * Redistributions of source code must retain the above copyright 
+ *
+ *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
- *     * 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 
+ *     * 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.
- *     * Neither the name of the Martin Isenburg or Iowa Department 
- *       of Natural Resources nor the names of its contributors may be 
- *       used to endorse or promote products derived from this software 
+ *     * Neither the name of the Martin Isenburg or Iowa Department
+ *       of Natural Resources nor the names of its contributors may be
+ *       used to endorse or promote products derived from this software
  *       without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * "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 
- * COPYRIGHT OWNER OR CONTRIBUTORS 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 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT OWNER OR CONTRIBUTORS 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 <liblas/header.hpp>
 #include <liblas/variablerecord.hpp>
 #include <liblas/detail/reader/header.hpp>
@@ -110,7 +110,7 @@ void Header::ReadHeader()
     boost::uuids::uuid u;
     for (int i=0; i<16; i++)
         u.data[i] = d[i];
-    
+
     m_header->SetProjectId(u);
 
     // 8. Version major
@@ -144,10 +144,10 @@ void Header::ReadHeader()
 
     // 15. Offset to data
     read_n(n4, m_ifs, sizeof(n4));
-    
+
     if (n4 < m_header->GetHeaderSize())
     {
-        std::ostringstream msg; 
+        std::ostringstream msg;
         msg <<  "The offset to the start of point data, "
             << n4 << ", is smaller than the header size, "
             << m_header->GetHeaderSize() << ".  This is "
@@ -194,7 +194,7 @@ void Header::ReadHeader()
     if (n1 == liblas::ePointFormat0)
     {
         m_header->SetDataFormatId(liblas::ePointFormat0);
-    } 
+    }
     else if (n1 == liblas::ePointFormat1)
     {
         m_header->SetDataFormatId(liblas::ePointFormat1);
@@ -219,7 +219,7 @@ void Header::ReadHeader()
     {
         throw std::domain_error("invalid point data format");
     }
-    
+
     // 18. Point Data Record Length
     read_n(n2, m_ifs, sizeof(n2));
     uint16_t record_length(n2);
@@ -229,16 +229,16 @@ void Header::ReadHeader()
     m_header->SetPointRecordsCount(n4);
 
     // 20. Number of points by return
-    // A few versions of the spec had this as 7, but 
-    // https://lidarbb.cr.usgs.gov/index.php?showtopic=11388 says 
+    // A few versions of the spec had this as 7, but
+    // https://lidarbb.cr.usgs.gov/index.php?showtopic=11388 says
     // it is supposed to always be 5
-    std::size_t const return_count_length = 5; 
+    std::size_t const return_count_length = 5;
     for (std::size_t i = 0; i < return_count_length; ++i)
     {
         uint32_t count = 0;
         read_n(count, m_ifs, sizeof(uint32_t));
         m_header->SetPointRecordsByReturnCount(i, count);
-    }  
+    }
 
     // 21-23. Scale factors
     read_n(x1, m_ifs, sizeof(x1));
@@ -283,39 +283,39 @@ void Header::ReadHeader()
 
     if (m_header->GetDataRecordLength() != record_length) // we have extra_bytes
     {
-        // FIXME: We only dump the bytes into an "extra" dimension for 
-        // now and there's now way to get to them. For LAS 1.4 files these 
+        // FIXME: We only dump the bytes into an "extra" dimension for
+        // now and there's now way to get to them. For LAS 1.4 files these
         // could be interpreted using the VLR, but it isn't done at this time.
-        
+
         Dimension extra("extra", (record_length - m_header->GetDataRecordLength())*8);
         extra.SetDescription("Extra bytes");
         extra.IsRequired(false); extra.IsActive(true); extra.IsInteger(false); extra.IsNumeric(true);
-        
+
         Schema schema = m_header->GetSchema();
         schema.AddDimension(extra);
         m_header->SetSchema(schema);
-    } 
+    }
 
 }
 
-bool Header::HasLAS10PadSignature() 
+bool Header::HasLAS10PadSignature()
 {
     uint8_t const sgn1 = 0xCC;
     uint8_t const sgn2 = 0xDD;
-    uint8_t pad1 = 0x0; 
+    uint8_t pad1 = 0x0;
     uint8_t pad2 = 0x0;
 
     std::streamsize const current_pos = m_ifs.tellg();
-    
-    // If our little test reads off the end of the file (in the case 
-    // of a file with just a header and no points), we'll try to put the 
+
+    // If our little test reads off the end of the file (in the case
+    // of a file with just a header and no points), we'll try to put the
     // borken dishes back up in the cabinet
     try
     {
         detail::read_n(pad1, m_ifs, sizeof(uint8_t));
         detail::read_n(pad2, m_ifs, sizeof(uint8_t));
     }
-    catch (std::out_of_range& e) 
+    catch (std::out_of_range& e)
     {
         boost::ignore_unused_variable_warning(e);
         m_ifs.seekg(current_pos, std::ios::beg);
@@ -325,21 +325,21 @@ bool Header::HasLAS10PadSignature()
     {
         boost::ignore_unused_variable_warning(e);
         m_ifs.seekg(current_pos, std::ios::beg);
-        return false;        
+        return false;
     }
     LIBLAS_SWAP_BYTES(pad1);
     LIBLAS_SWAP_BYTES(pad2);
-    
+
     // Put the stream back where we found it
     m_ifs.seekg(current_pos, std::ios::beg);
-    
-    // Let's check both ways in case people were 
-    // careless with their swapping.  This will do no good 
+
+    // Let's check both ways in case people were
+    // careless with their swapping.  This will do no good
     // when we go to read point data though.
     bool found = false;
     if (sgn1 == pad2 && sgn2 == pad1) found = true;
     if (sgn1 == pad1 && sgn2 == pad2) found = true;
-    
+
     return found;
 }
 
@@ -348,19 +348,19 @@ void Header::ReadVLRs()
     VLRHeader vlrh;
 
     if (m_ifs.eof()) {
-        // if we hit the end of the file already, it's because 
-        // we don't have any points.  We still want to read the VLRs 
+        // if we hit the end of the file already, it's because
+        // we don't have any points.  We still want to read the VLRs
         // in that case.
-        m_ifs.clear();  
+        m_ifs.clear();
     }
 
     // seek to the start of the VLRs
     m_ifs.seekg(m_header->GetHeaderSize(), std::ios::beg);
 
     uint32_t count = m_header->GetRecordsCount();
-    
-    // We set the VLR records count to 0 because AddVLR 
-    // will ++ it each time we add a VLR instance to the 
+
+    // We set the VLR records count to 0 because AddVLR
+    // will ++ it each time we add a VLR instance to the
     // header.
     m_header->SetRecordsCount(0);
     for (uint32_t i = 0; i < count; ++i)
@@ -374,7 +374,7 @@ void Header::ReadVLRs()
         {
             read_n(data.front(), m_ifs, length);
         }
-        
+
         VariableRecord vlr;
         vlr.SetReserved(vlrh.reserved);
         vlr.SetUserId(std::string(vlrh.userId, VariableRecord::eUserIdSize));
@@ -386,22 +386,22 @@ void Header::ReadVLRs()
         m_header->AddVLR(vlr);
     }
 
-    liblas::SpatialReference srs(m_header->GetVLRs());    
+    liblas::SpatialReference srs(m_header->GetVLRs());
     m_header->SetSRS(srs);
-    
+
     // Go fetch the schema from the VLRs if we've got one.
     try {
         liblas::Schema schema(m_header->GetVLRs());
         m_header->SetSchema(schema);
 
-    } catch (std::runtime_error const& e) 
+    } catch (std::runtime_error const& e)
     {
         // Create one from the PointFormat if we don't have
-        // one in the VLRs.  Create a custom dimension on the schema 
-        // That comprises the rest of the bytes after the end of the 
+        // one in the VLRs.  Create a custom dimension on the schema
+        // That comprises the rest of the bytes after the end of the
         // required dimensions.
         liblas::Schema schema(m_header->GetDataFormatId());
-        
+
         // FIXME: handle custom bytes here.
         m_header->SetSchema(schema);
         boost::ignore_unused_variable_warning(e);
@@ -425,25 +425,25 @@ void Header::ReadVLRs()
 
 void Header::Validate()
 {
-    // Check that the point count actually describes the number of points 
-    // in the file.  If it doesn't, we're going to throw an error telling 
-    // the user why.  It may also be a problem that the dataoffset is 
-    // really what is wrong, but there's no real way to know that unless 
+    // Check that the point count actually describes the number of points
+    // in the file.  If it doesn't, we're going to throw an error telling
+    // the user why.  It may also be a problem that the dataoffset is
+    // really what is wrong, but there's no real way to know that unless
     // you go start mucking around in the bytes with hexdump or od
-        
+
     // LAS 1.3 specification no longer mandates that the end of the file is the
     // end of the points. See http://trac.liblas.org/ticket/147 for more details
-    // on this issue and why the seek can be trouble in the windows case.  
-    // If you are having trouble properly seeking to the end of the stream on 
-    // windows, use boost's iostreams or similar, which do not have an overflow 
+    // on this issue and why the seek can be trouble in the windows case.
+    // If you are having trouble properly seeking to the end of the stream on
+    // windows, use boost's iostreams or similar, which do not have an overflow
     // problem.
-    
-    if (m_header->GetVersionMinor() < 3 && !m_header->Compressed() ) 
+
+    if (m_header->GetVersionMinor() < 3 && !m_header->Compressed() )
     {
-        // Seek to the beginning 
+        // Seek to the beginning
         m_ifs.seekg(0, std::ios::beg);
         std::ios::pos_type beginning = m_ifs.tellg();
-    
+
         // Seek to the end
         m_ifs.seekg(0, std::ios::end);
         std::ios::pos_type end = m_ifs.tellg();
@@ -452,29 +452,29 @@ void Header::Validate()
         std::ios::off_type length = static_cast<std::ios::off_type>(m_header->GetDataRecordLength());
         std::ios::off_type point_bytes = end - offset;
 
-        // Figure out how many points we have and whether or not we have 
+        // Figure out how many points we have and whether or not we have
         // extra slop in there.
         std::ios::off_type count = point_bytes / length;
         std::ios::off_type remainder = point_bytes % length;
-        
+
 
         if ( m_header->GetPointRecordsCount() != static_cast<uint32_t>(count)) {
-  
-                std::ostringstream msg; 
+
+                std::ostringstream msg;
                 msg <<  "The number of points in the header that was set "
                         "by the software '" << m_header->GetSoftwareId() <<
                         "' does not match the actual number of points in the file "
-                        "as determined by subtracting the data offset (" 
-                        <<m_header->GetDataOffset() << ") from the file length (" 
-                        << size <<  ") and dividing by the point record length (" 
+                        "as determined by subtracting the data offset ("
+                        <<m_header->GetDataOffset() << ") from the file length ("
+                        << size <<  ") and dividing by the point record length ("
                         << m_header->GetDataRecordLength() << ")."
                         " It also does not perfectly contain an exact number of"
                         " point data and we cannot infer a point count."
-                        " Calculated number of points: " << count << 
-                        " Header-specified number of points: " 
+                        " Calculated number of points: " << count <<
+                        " Header-specified number of points: "
                         << m_header->GetPointRecordsCount() <<
                         " Point data remainder: " << remainder;
-                throw std::runtime_error(msg.str());                
+                throw std::runtime_error(msg.str());
 
         }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/liblas.git



More information about the Pkg-grass-devel mailing list