mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-02 04:59:52 +00:00
Make ICU no longer a required dependency
This commit is contained in:
@@ -41,7 +41,8 @@ FIND_LIBRARY(icu "icuuc" /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
|
|||||||
IF(icu)
|
IF(icu)
|
||||||
MESSAGE(STATUS "ICU libraries found")
|
MESSAGE(STATUS "ICU libraries found")
|
||||||
ELSE()
|
ELSE()
|
||||||
MESSAGE(FATAL_ERROR "Unable to find ICU library files, aborting")
|
MESSAGE(STATUS "Unable to find ICU library files, aborting")
|
||||||
|
ADD_DEFINITIONS(-DHAVE_ICU)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
INCLUDE(CheckIncludeFileCXX)
|
INCLUDE(CheckIncludeFileCXX)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
using namespace IfcParse;
|
using namespace IfcParse;
|
||||||
|
|
||||||
void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
|
void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
|
||||||
|
#ifdef HAVE_ICU
|
||||||
if ( destination ) {
|
if ( destination ) {
|
||||||
char* extraction_buffer = new char[4];
|
char* extraction_buffer = new char[4];
|
||||||
UnicodeString(ch).extract(extraction_buffer,4,destination,status);
|
UnicodeString(ch).extract(extraction_buffer,4,destination,status);
|
||||||
@@ -79,18 +80,25 @@ void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
|
|||||||
s2 << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (int) ch;
|
s2 << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (int) ch;
|
||||||
s << s2.str();
|
s << s2.str();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
s.put(substitution_character);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
IfcCharacterDecoder::IfcCharacterDecoder(IfcParse::File* f) {
|
IfcCharacterDecoder::IfcCharacterDecoder(IfcParse::File* f) {
|
||||||
file = f;
|
file = f;
|
||||||
|
#ifdef HAVE_ICU
|
||||||
if ( ! destination && mode == UTF8 ) {
|
if ( ! destination && mode == UTF8 ) {
|
||||||
destination = ucnv_open("utf-8", &status);
|
destination = ucnv_open("utf-8", &status);
|
||||||
} else if ( ! destination && mode == LATIN ) {
|
} else if ( ! destination && mode == LATIN ) {
|
||||||
destination = ucnv_open("iso-8859-1", &status);
|
destination = ucnv_open("iso-8859-1", &status);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
IfcCharacterDecoder::~IfcCharacterDecoder() {
|
IfcCharacterDecoder::~IfcCharacterDecoder() {
|
||||||
|
#ifdef HAVE_ICU
|
||||||
if ( destination ) ucnv_close(destination);
|
if ( destination ) ucnv_close(destination);
|
||||||
if ( converter ) ucnv_close(converter);
|
if ( converter ) ucnv_close(converter);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
IfcCharacterDecoder::operator std::string() {
|
IfcCharacterDecoder::operator std::string() {
|
||||||
unsigned int parse_state = 0;
|
unsigned int parse_state = 0;
|
||||||
@@ -102,6 +110,7 @@ IfcCharacterDecoder::operator std::string() {
|
|||||||
unsigned int hex_count = 0;
|
unsigned int hex_count = 0;
|
||||||
while ( current_char = file->Peek() ) {
|
while ( current_char = file->Peek() ) {
|
||||||
if ( EXPECTS_CHARACTER(parse_state) ) {
|
if ( EXPECTS_CHARACTER(parse_state) ) {
|
||||||
|
#ifdef HAVE_ICU
|
||||||
if ( previous_codepage != codepage ) {
|
if ( previous_codepage != codepage ) {
|
||||||
if ( converter ) ucnv_close(converter);
|
if ( converter ) ucnv_close(converter);
|
||||||
char encoder[11] = {'i','s','o','-','8','8','5','9','-',codepage + 0x30};
|
char encoder[11] = {'i','s','o','-','8','8','5','9','-',codepage + 0x30};
|
||||||
@@ -111,6 +120,10 @@ IfcCharacterDecoder::operator std::string() {
|
|||||||
const char* char_array = &characters[0];
|
const char* char_array = &characters[0];
|
||||||
UChar32 ch = ucnv_getNextUChar(converter,&char_array,char_array+1,&status);
|
UChar32 ch = ucnv_getNextUChar(converter,&char_array,char_array+1,&status);
|
||||||
addChar(s,ch);
|
addChar(s,ch);
|
||||||
|
#else
|
||||||
|
UChar32 ch = 0;
|
||||||
|
addChar(s,ch);
|
||||||
|
#endif
|
||||||
parse_state = 0;
|
parse_state = 0;
|
||||||
} else if ( current_char == '\'' && ! parse_state ) {
|
} else if ( current_char == '\'' && ! parse_state ) {
|
||||||
parse_state = APOSTROPHE;
|
parse_state = APOSTROPHE;
|
||||||
@@ -225,10 +238,12 @@ void IfcCharacterDecoder::dryRun() {
|
|||||||
file->Inc();
|
file->Inc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_ICU
|
||||||
UConverter* IfcCharacterDecoder::destination = 0;
|
UConverter* IfcCharacterDecoder::destination = 0;
|
||||||
UConverter* IfcCharacterDecoder::converter = 0;
|
UConverter* IfcCharacterDecoder::converter = 0;
|
||||||
int IfcCharacterDecoder::previous_codepage = -1;
|
int IfcCharacterDecoder::previous_codepage = -1;
|
||||||
UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
|
UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
|
||||||
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
|
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
|
||||||
|
#else
|
||||||
|
char IfcCharacterDecoder::substitution_character = '_';
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -30,7 +30,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#ifdef HAVE_ICU
|
||||||
#include "unicode/ucnv.h"
|
#include "unicode/ucnv.h"
|
||||||
|
#else
|
||||||
|
typedef unsigned int UChar32;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../ifcparse/IfcFile.h"
|
#include "../ifcparse/IfcFile.h"
|
||||||
|
|
||||||
@@ -39,14 +43,20 @@ namespace IfcParse {
|
|||||||
class IfcCharacterDecoder {
|
class IfcCharacterDecoder {
|
||||||
private:
|
private:
|
||||||
IfcParse::File* file;
|
IfcParse::File* file;
|
||||||
|
#ifdef HAVE_ICU
|
||||||
static UConverter* destination;
|
static UConverter* destination;
|
||||||
static UConverter* converter;
|
static UConverter* converter;
|
||||||
static int previous_codepage;
|
static int previous_codepage;
|
||||||
static UErrorCode status;
|
static UErrorCode status;
|
||||||
|
#endif
|
||||||
void addChar(std::stringstream& s,const UChar32& ch);
|
void addChar(std::stringstream& s,const UChar32& ch);
|
||||||
public:
|
public:
|
||||||
|
#ifdef HAVE_ICU
|
||||||
enum ConversionMode {UTF8,LATIN,JSON,PYTHON};
|
enum ConversionMode {UTF8,LATIN,JSON,PYTHON};
|
||||||
static ConversionMode mode;
|
static ConversionMode mode;
|
||||||
|
#else
|
||||||
|
static char substitution_character;
|
||||||
|
#endif
|
||||||
IfcCharacterDecoder(IfcParse::File* file);
|
IfcCharacterDecoder(IfcParse::File* file);
|
||||||
~IfcCharacterDecoder();
|
~IfcCharacterDecoder();
|
||||||
void dryRun();
|
void dryRun();
|
||||||
|
|||||||
Reference in New Issue
Block a user