Skip to content

Commit 95d2cdc

Browse files
committed
Only allow character decoder compatibility mode if HAVE_ICU is defined since it relies on ICU to be available.
1 parent 217a7c6 commit 95d2cdc

File tree

2 files changed

+68
-63
lines changed

2 files changed

+68
-63
lines changed

src/ifcparse/IfcCharacterDecoder.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ IfcCharacterDecoder::operator std::string() {
126126
int codepage = 1;
127127
unsigned int hex = 0;
128128
unsigned int hex_count = 0;
129-
unsigned int old_hex = 0; // for compatibility_mode
130-
129+
#ifdef HAVE_ICU
130+
unsigned int old_hex = 0; // for compatibility_mode
131+
#endif
131132
while ( current_char = file->Peek() ) {
132133
if ( EXPECTS_CHARACTER(parse_state) ) {
133134
#ifdef HAVE_ICU
@@ -178,27 +179,31 @@ IfcCharacterDecoder::operator std::string() {
178179
hex <<= 4;
179180
parse_state += HEX((++hex_count));
180181
hex += HEX_TO_INT(current_char);
181-
if ( (hex_count == 2 && !(parse_state & EXTENDED2)) ||
182-
(hex_count == 4 && !(parse_state & EXTENDED4)) ||
183-
(hex_count == 8) ) {
184-
if (compatibility_mode) {
185-
if (old_hex == 0) {
186-
old_hex = hex;
187-
} else {
188-
char characters[3] = { old_hex, hex };
189-
const char* char_array = &characters[0];
190-
UChar32 ch = ucnv_getNextUChar(compatibility_converter,&char_array,char_array+2,&status);
191-
addChar(s,ch);
192-
old_hex = 0;
193-
}
194-
}
195-
else {
196-
addChar(s,(UChar32) hex);
197-
}
198-
if ( hex_count == 2 ) parse_state = 0;
199-
else CLEAR_HEX(parse_state);
200-
hex = hex_count = 0;
201-
}
182+
if ( (hex_count == 2 && !(parse_state & EXTENDED2)) ||
183+
(hex_count == 4 && !(parse_state & EXTENDED4)) ||
184+
(hex_count == 8) ) {
185+
#ifdef HAVE_ICU
186+
if (compatibility_mode) {
187+
if (old_hex == 0) {
188+
old_hex = hex;
189+
} else {
190+
char characters[3] = { old_hex, hex };
191+
const char* char_array = &characters[0];
192+
UChar32 ch = ucnv_getNextUChar(compatibility_converter,&char_array,char_array+2,&status);
193+
addChar(s,ch);
194+
old_hex = 0;
195+
}
196+
}
197+
else {
198+
#endif
199+
addChar(s,(UChar32) hex);
200+
#ifdef HAVE_ICU
201+
}
202+
#endif
203+
if ( hex_count == 2 ) parse_state = 0;
204+
else CLEAR_HEX(parse_state);
205+
hex = hex_count = 0;
206+
}
202207
} else if ( parse_state && !(
203208
(current_char == '\\' && parse_state == FIRST_SOLIDUS) ||
204209
(current_char == '\'' && parse_state == APOSTROPHE)
@@ -207,8 +212,8 @@ IfcCharacterDecoder::operator std::string() {
207212
throw IfcException("Invalid character encountered");
208213
} else {
209214
parse_state = hex = hex_count = 0;
210-
// NOTE: this is in fact wrong, this ought to be the representation of the character.
211-
// In UTF-8 this is the same, but we should not rely on that.
215+
// NOTE: this is in fact wrong, this ought to be the representation of the character.
216+
// In UTF-8 this is the same, but we should not rely on that.
212217
s.put(current_char);
213218
}
214219
file->Inc();
@@ -281,13 +286,13 @@ int IfcCharacterDecoder::previous_codepage = -1;
281286
UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
282287
#endif
283288

284-
//#ifdef HAVE_ICU
289+
#ifdef HAVE_ICU
285290
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
286291

287292
// Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior
288293
bool IfcCharacterDecoder::compatibility_mode = false;
289294
std::string IfcCharacterDecoder::compatibility_charset = "";
290295

291-
//#else
296+
#else
292297
char IfcCharacterDecoder::substitution_character = '_';
293-
//#endif
298+
#endif

src/ifcparse/IfcCharacterDecoder.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/********************************************************************************
2-
* *
3-
* This file is part of IfcOpenShell. *
4-
* *
5-
* IfcOpenShell is free software: you can redistribute it and/or modify *
6-
* it under the terms of the Lesser GNU General Public License as published by *
7-
* the Free Software Foundation, either version 3.0 of the License, or *
8-
* (at your option) any later version. *
9-
* *
10-
* IfcOpenShell is distributed in the hope that it will be useful, *
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13-
* Lesser GNU General Public License for more details. *
14-
* *
15-
* You should have received a copy of the Lesser GNU General Public License *
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17-
* *
18-
********************************************************************************/
19-
20-
/********************************************************************************
21-
* *
22-
* Implementation of character decoding as described in ISO 10303-21 table 2 and *
23-
* table 4 *
24-
* *
25-
********************************************************************************/
26-
2+
* *
3+
* This file is part of IfcOpenShell. *
4+
* *
5+
* IfcOpenShell is free software: you can redistribute it and/or modify *
6+
* it under the terms of the Lesser GNU General Public License as published by *
7+
* the Free Software Foundation, either version 3.0 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* IfcOpenShell is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* Lesser GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the Lesser GNU General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
* *
18+
********************************************************************************/
19+
20+
/********************************************************************************
21+
* *
22+
* Implementation of character decoding as described in ISO 10303-21 table 2 and *
23+
* table 4 *
24+
* *
25+
********************************************************************************/
26+
2727
#ifndef IFCCHARACTERDECODER_H
2828
#define IFCCHARACTERDECODER_H
2929

@@ -46,25 +46,25 @@ namespace IfcParse {
4646
#ifdef HAVE_ICU
4747
static UConverter* destination;
4848
static UConverter* converter;
49-
static UConverter* compatibility_converter;
49+
static UConverter* compatibility_converter;
5050
static int previous_codepage;
5151
static UErrorCode status;
5252
#endif
5353
void addChar(std::stringstream& s,const UChar32& ch);
5454
public:
55-
//#ifdef HAVE_ICU
56-
enum ConversionMode {DEFAULT,UTF8,LATIN,JSON,PYTHON};
55+
#ifdef HAVE_ICU
56+
enum ConversionMode {DEFAULT,UTF8,LATIN,JSON,PYTHON};
5757
static ConversionMode mode;
5858

59-
// Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior to encode characters.
60-
// It just translate to extended string in system default code page, not unicode.
61-
// If you want to process these strings, set true.
62-
static bool compatibility_mode;
63-
static std::string compatibility_charset;
59+
// Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior to encode characters.
60+
// It just translate to extended string in system default code page, not unicode.
61+
// If you want to process these strings, set true.
62+
static bool compatibility_mode;
63+
static std::string compatibility_charset;
6464

65-
//#else
65+
#else
6666
static char substitution_character;
67-
//#endif
67+
#endif
6868
IfcCharacterDecoder(IfcParse::File* file);
6969
~IfcCharacterDecoder();
7070
void dryRun();

0 commit comments

Comments
 (0)