diff --git a/src/ifcparse/IfcCharacterDecoder.cpp b/src/ifcparse/IfcCharacterDecoder.cpp index 6afd0cba6a..f15163d788 100644 --- a/src/ifcparse/IfcCharacterDecoder.cpp +++ b/src/ifcparse/IfcCharacterDecoder.cpp @@ -126,8 +126,9 @@ IfcCharacterDecoder::operator std::string() { int codepage = 1; unsigned int hex = 0; unsigned int hex_count = 0; - unsigned int old_hex = 0; // for compatibility_mode - +#ifdef HAVE_ICU + unsigned int old_hex = 0; // for compatibility_mode +#endif while ( current_char = file->Peek() ) { if ( EXPECTS_CHARACTER(parse_state) ) { #ifdef HAVE_ICU @@ -178,27 +179,31 @@ IfcCharacterDecoder::operator std::string() { hex <<= 4; parse_state += HEX((++hex_count)); hex += HEX_TO_INT(current_char); - if ( (hex_count == 2 && !(parse_state & EXTENDED2)) || - (hex_count == 4 && !(parse_state & EXTENDED4)) || - (hex_count == 8) ) { - if (compatibility_mode) { - if (old_hex == 0) { - old_hex = hex; - } else { - char characters[3] = { old_hex, hex }; - const char* char_array = &characters[0]; - UChar32 ch = ucnv_getNextUChar(compatibility_converter,&char_array,char_array+2,&status); - addChar(s,ch); - old_hex = 0; - } - } - else { - addChar(s,(UChar32) hex); - } - if ( hex_count == 2 ) parse_state = 0; - else CLEAR_HEX(parse_state); - hex = hex_count = 0; - } + if ( (hex_count == 2 && !(parse_state & EXTENDED2)) || + (hex_count == 4 && !(parse_state & EXTENDED4)) || + (hex_count == 8) ) { +#ifdef HAVE_ICU + if (compatibility_mode) { + if (old_hex == 0) { + old_hex = hex; + } else { + char characters[3] = { old_hex, hex }; + const char* char_array = &characters[0]; + UChar32 ch = ucnv_getNextUChar(compatibility_converter,&char_array,char_array+2,&status); + addChar(s,ch); + old_hex = 0; + } + } + else { +#endif + addChar(s,(UChar32) hex); +#ifdef HAVE_ICU + } +#endif + if ( hex_count == 2 ) parse_state = 0; + else CLEAR_HEX(parse_state); + hex = hex_count = 0; + } } else if ( parse_state && !( (current_char == '\\' && parse_state == FIRST_SOLIDUS) || (current_char == '\'' && parse_state == APOSTROPHE) @@ -207,8 +212,8 @@ IfcCharacterDecoder::operator std::string() { throw IfcException("Invalid character encountered"); } else { parse_state = hex = hex_count = 0; - // NOTE: this is in fact wrong, this ought to be the representation of the character. - // In UTF-8 this is the same, but we should not rely on that. + // NOTE: this is in fact wrong, this ought to be the representation of the character. + // In UTF-8 this is the same, but we should not rely on that. s.put(current_char); } file->Inc(); @@ -281,13 +286,13 @@ int IfcCharacterDecoder::previous_codepage = -1; UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR; #endif -//#ifdef HAVE_ICU +#ifdef HAVE_ICU IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON; // Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior bool IfcCharacterDecoder::compatibility_mode = false; std::string IfcCharacterDecoder::compatibility_charset = ""; -//#else +#else char IfcCharacterDecoder::substitution_character = '_'; -//#endif +#endif diff --git a/src/ifcparse/IfcCharacterDecoder.h b/src/ifcparse/IfcCharacterDecoder.h index 8d66d4dd77..92c24e11df 100644 --- a/src/ifcparse/IfcCharacterDecoder.h +++ b/src/ifcparse/IfcCharacterDecoder.h @@ -1,29 +1,29 @@ /******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - - /******************************************************************************** - * * - * Implementation of character decoding as described in ISO 10303-21 table 2 and * - * table 4 * - * * - ********************************************************************************/ - +* * +* This file is part of IfcOpenShell. * +* * +* IfcOpenShell is free software: you can redistribute it and/or modify * +* it under the terms of the Lesser GNU General Public License as published by * +* the Free Software Foundation, either version 3.0 of the License, or * +* (at your option) any later version. * +* * +* IfcOpenShell is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* Lesser GNU General Public License for more details. * +* * +* You should have received a copy of the Lesser GNU General Public License * +* along with this program. If not, see . * +* * +********************************************************************************/ + +/******************************************************************************** +* * +* Implementation of character decoding as described in ISO 10303-21 table 2 and * +* table 4 * +* * +********************************************************************************/ + #ifndef IFCCHARACTERDECODER_H #define IFCCHARACTERDECODER_H @@ -46,25 +46,25 @@ namespace IfcParse { #ifdef HAVE_ICU static UConverter* destination; static UConverter* converter; - static UConverter* compatibility_converter; + static UConverter* compatibility_converter; static int previous_codepage; static UErrorCode status; #endif void addChar(std::stringstream& s,const UChar32& ch); public: -//#ifdef HAVE_ICU - enum ConversionMode {DEFAULT,UTF8,LATIN,JSON,PYTHON}; +#ifdef HAVE_ICU + enum ConversionMode {DEFAULT,UTF8,LATIN,JSON,PYTHON}; static ConversionMode mode; - // Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior to encode characters. - // It just translate to extended string in system default code page, not unicode. - // If you want to process these strings, set true. - static bool compatibility_mode; - static std::string compatibility_charset; + // Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior to encode characters. + // It just translate to extended string in system default code page, not unicode. + // If you want to process these strings, set true. + static bool compatibility_mode; + static std::string compatibility_charset; -//#else +#else static char substitution_character; -//#endif +#endif IfcCharacterDecoder(IfcParse::File* file); ~IfcCharacterDecoder(); void dryRun();