2026-03-31 15:32:36 +02:00
|
|
|
/********************************************************************************
|
2023-09-18 16:13:44 +02:00
|
|
|
* *
|
|
|
|
|
* 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 <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
2012-07-18 18:45:34 +00:00
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
/********************************************************************************
|
2023-09-18 16:13:44 +02:00
|
|
|
* *
|
|
|
|
|
* Implementation of character decoding as described in ISO 10303-21 table 2 and *
|
|
|
|
|
* table 4 *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
2012-07-18 18:45:34 +00:00
|
|
|
|
2011-09-25 09:53:22 +00:00
|
|
|
#ifndef IFCCHARACTERDECODER_H
|
|
|
|
|
#define IFCCHARACTERDECODER_H
|
|
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
#include "file_reader.h"
|
2026-07-09 13:21:39 +02:00
|
|
|
#include "logger.h"
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
#include <string>
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
namespace ifcopenshell {
|
2025-09-26 14:24:49 +02:00
|
|
|
IFC_PARSE_API std::u32string::value_type convert_codepage(int codepage, int index);
|
|
|
|
|
IFC_PARSE_API std::string convert_utf8(const std::u32string& string);
|
|
|
|
|
IFC_PARSE_API std::u32string convert_utf8(const std::string& string);
|
2026-03-31 15:32:36 +02:00
|
|
|
} // namespace ifcopenshell
|
2019-05-10 11:59:00 +02:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
namespace ifcopenshell {
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2026-03-27 20:45:13 +01:00
|
|
|
template <typename Reader>
|
2026-03-31 15:32:36 +02:00
|
|
|
class IFC_PARSE_API character_decoder {
|
2023-09-17 12:30:17 +02:00
|
|
|
private:
|
2026-03-27 20:45:13 +01:00
|
|
|
Reader* stream_;
|
2026-06-11 21:04:44 +02:00
|
|
|
Logger& logger_;
|
2023-09-17 12:30:17 +02:00
|
|
|
int codepage_;
|
2026-03-27 20:45:13 +01:00
|
|
|
std::u32string builder_;
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum ConversionMode {
|
|
|
|
|
SUBSTITUTE,
|
|
|
|
|
UTF8,
|
|
|
|
|
ESCAPE
|
|
|
|
|
};
|
2026-03-27 20:45:13 +01:00
|
|
|
inline static ConversionMode mode = UTF8;
|
|
|
|
|
inline static char substitution_character = '_';
|
|
|
|
|
|
2026-07-09 13:21:39 +02:00
|
|
|
character_decoder(Reader* stream, Logger& logger = Logger::Root());
|
2026-03-31 15:32:36 +02:00
|
|
|
~character_decoder();
|
2023-09-17 12:30:17 +02:00
|
|
|
// Gets a decoded string representation at the token stream
|
|
|
|
|
// read pointer and advances the underlying token stream.
|
|
|
|
|
operator std::string();
|
|
|
|
|
// Gets a decoded string representation at the offset provided,
|
|
|
|
|
// does not mutate the underlying token stream read pointer.
|
2026-03-31 18:23:13 +02:00
|
|
|
std::string get(size_t& offset);
|
2023-09-17 12:30:17 +02:00
|
|
|
};
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
} // namespace ifcopenshell
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
namespace ifcopenshell {
|
2012-09-09 11:55:53 +00:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
class IFC_PARSE_API character_encoder {
|
2023-09-17 12:30:17 +02:00
|
|
|
private:
|
2023-11-06 20:38:19 +01:00
|
|
|
std::u32string str_;
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
public:
|
2026-03-31 15:32:36 +02:00
|
|
|
character_encoder(const std::string& input);
|
2023-09-17 12:30:17 +02:00
|
|
|
operator std::string();
|
|
|
|
|
};
|
2012-09-09 11:55:53 +00:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
} // namespace IfcWrite
|
2012-09-09 11:55:53 +00:00
|
|
|
|
2011-09-25 09:53:22 +00:00
|
|
|
#endif
|