Skip to content

Commit a914365

Browse files
committed
Make ICU no longer a required dependency
1 parent 9edbe7e commit a914365

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ FIND_LIBRARY(icu "icuuc" /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
4141
IF(icu)
4242
MESSAGE(STATUS "ICU libraries found")
4343
ELSE()
44-
MESSAGE(FATAL_ERROR "Unable to find ICU library files, aborting")
44+
MESSAGE(STATUS "Unable to find ICU library files, aborting")
45+
ADD_DEFINITIONS(-DHAVE_ICU)
4546
ENDIF()
4647

4748
INCLUDE(CheckIncludeFileCXX)

src/ifcparse/IfcCharacterDecoder.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
using namespace IfcParse;
7070

7171
void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
72+
#ifdef HAVE_ICU
7273
if ( destination ) {
7374
char* extraction_buffer = new char[4];
7475
UnicodeString(ch).extract(extraction_buffer,4,destination,status);
@@ -79,18 +80,25 @@ void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
7980
s2 << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (int) ch;
8081
s << s2.str();
8182
}
83+
#else
84+
s.put(substitution_character);
85+
#endif
8286
}
8387
IfcCharacterDecoder::IfcCharacterDecoder(IfcParse::File* f) {
8488
file = f;
89+
#ifdef HAVE_ICU
8590
if ( ! destination && mode == UTF8 ) {
8691
destination = ucnv_open("utf-8", &status);
8792
} else if ( ! destination && mode == LATIN ) {
8893
destination = ucnv_open("iso-8859-1", &status);
8994
}
95+
#endif
9096
}
9197
IfcCharacterDecoder::~IfcCharacterDecoder() {
98+
#ifdef HAVE_ICU
9299
if ( destination ) ucnv_close(destination);
93100
if ( converter ) ucnv_close(converter);
101+
#endif
94102
}
95103
IfcCharacterDecoder::operator std::string() {
96104
unsigned int parse_state = 0;
@@ -102,6 +110,7 @@ IfcCharacterDecoder::operator std::string() {
102110
unsigned int hex_count = 0;
103111
while ( current_char = file->Peek() ) {
104112
if ( EXPECTS_CHARACTER(parse_state) ) {
113+
#ifdef HAVE_ICU
105114
if ( previous_codepage != codepage ) {
106115
if ( converter ) ucnv_close(converter);
107116
char encoder[11] = {'i','s','o','-','8','8','5','9','-',codepage + 0x30};
@@ -111,6 +120,10 @@ IfcCharacterDecoder::operator std::string() {
111120
const char* char_array = &characters[0];
112121
UChar32 ch = ucnv_getNextUChar(converter,&char_array,char_array+1,&status);
113122
addChar(s,ch);
123+
#else
124+
UChar32 ch = 0;
125+
addChar(s,ch);
126+
#endif
114127
parse_state = 0;
115128
} else if ( current_char == '\'' && ! parse_state ) {
116129
parse_state = APOSTROPHE;
@@ -225,10 +238,12 @@ void IfcCharacterDecoder::dryRun() {
225238
file->Inc();
226239
}
227240
}
228-
241+
#ifdef HAVE_ICU
229242
UConverter* IfcCharacterDecoder::destination = 0;
230243
UConverter* IfcCharacterDecoder::converter = 0;
231244
int IfcCharacterDecoder::previous_codepage = -1;
232245
UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
233246
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
234-
247+
#else
248+
char IfcCharacterDecoder::substitution_character = '_';
249+
#endif

src/ifcparse/IfcCharacterDecoder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
#include <string>
3131
#include <sstream>
3232

33+
#ifdef HAVE_ICU
3334
#include "unicode/ucnv.h"
35+
#else
36+
typedef unsigned int UChar32;
37+
#endif
3438

3539
#include "../ifcparse/IfcFile.h"
3640

@@ -39,14 +43,20 @@ namespace IfcParse {
3943
class IfcCharacterDecoder {
4044
private:
4145
IfcParse::File* file;
46+
#ifdef HAVE_ICU
4247
static UConverter* destination;
4348
static UConverter* converter;
4449
static int previous_codepage;
4550
static UErrorCode status;
51+
#endif
4652
void addChar(std::stringstream& s,const UChar32& ch);
4753
public:
54+
#ifdef HAVE_ICU
4855
enum ConversionMode {UTF8,LATIN,JSON,PYTHON};
4956
static ConversionMode mode;
57+
#else
58+
static char substitution_character;
59+
#endif
5060
IfcCharacterDecoder(IfcParse::File* file);
5161
~IfcCharacterDecoder();
5262
void dryRun();

0 commit comments

Comments
 (0)