1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/************************************************************************
*
* Copyright (C) 2017-2022 IRCAD France
* Copyright (C) 2017-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight 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
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#pragma once
#include "io/dicom/config.hpp"
#include <core/Exception.hpp>
#include <core/macros.hpp>
#include <boost/locale/encoding_errors.hpp>
#include <map>
#include <string>
#include <vector>
namespace sight::core::log
{
class Logger;
}
namespace sight::io::dicom
{
namespace helper
{
/**
* @brief Helper class for encoding management.
*/
class IO_DICOM_CLASS_API Encoding
{
public:
/**
* @brief Convert a DICOM string from the specified charset to utf-8.
* @param[in] source Source buffer
* @param[in] definedCharsetTerm DICOM source charset
* @param[in] logger Logger used for conversion errors
* @throw core::Exception
* @throw boost::locale::conv::invalid_charset_error
* @return converted string in utf-8 format
*/
IO_DICOM_API static std::string convertString(
const std::string& source,
const std::string& definedCharsetTerm,
const SPTR(core::log::Logger)& logger = nullptr
);
private:
/**
* @brief Convert string charset without code extension from DICOM format to boost format.
* @param[in] source Source buffer
* @param[in] definedTerm DICOM charset
* @param[in] logger Logger used for conversion errors
* @return converted charset
*/
static std::string convertStringWithoutCodeExtensions(
const std::string& source,
const std::string& definedTerm,
const SPTR(core::log::Logger)& logger
);
/**
* @brief Convert string sequence with a code extension.
* @param[in] sequence Sequence buffer
* @param[in] definedTermList DICOM charset list
* @param[in] logger Logger used for conversion errors
* @throw core::Exception
* @throw boost::locale::conv::invalid_charset_error
* @return converted sequence in utf-8 format
*/
static std::string convertSequenceWithCodeExtensions(
const std::string& sequence,
const std::vector<std::string>& definedTermList,
const SPTR(core::log::Logger)& logger
);
/**
* @brief Map used to convert defined term to charset
* @{ */
typedef std::map<std::string, std::string> DefinedTermToCharsetMapType;
static const DefinedTermToCharsetMapType s_DEFINED_TERM_TO_CHARSET;
/** @} */
/// Escape sequence representation
typedef std::pair<char, char> EscapeSequenceType;
/// Pair containing a defined term and the associated charset
typedef std::pair<std::string, std::string> DefinedTermAndCharsetPairType;
/**
* @brief Map used to convert escape sequence to charset
* @{ */
typedef std::map<EscapeSequenceType, DefinedTermAndCharsetPairType> EscapeSequenceToCharsetMapType;
static const EscapeSequenceToCharsetMapType s_ESCAPE_SEQUENCE_TO_CHARSET;
/** @} */
};
} // namespace helper
} // namespace sight::io::dicom
|