6969using namespace IfcParse;
7070
7171void 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}
8387IfcCharacterDecoder::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}
9197IfcCharacterDecoder::~IfcCharacterDecoder () {
98+ #ifdef HAVE_ICU
9299 if ( destination ) ucnv_close (destination);
93100 if ( converter ) ucnv_close (converter);
101+ #endif
94102}
95103IfcCharacterDecoder::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
229242UConverter* IfcCharacterDecoder::destination = 0 ;
230243UConverter* IfcCharacterDecoder::converter = 0 ;
231244int IfcCharacterDecoder::previous_codepage = -1 ;
232245UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
233246IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
234-
247+ #else
248+ char IfcCharacterDecoder::substitution_character = ' _' ;
249+ #endif
0 commit comments