PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
dataset_charset.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11
13
14namespace kcenon::pacs::encoding {
15
17 const core::dicom_dataset& ds,
19 std::string_view default_value) {
20
21 const auto* elem = ds.get(tag);
22 if (elem == nullptr) {
23 return std::string{default_value};
24 }
25
26 auto raw = elem->as_string();
27 if (!raw.is_ok()) {
28 return std::string{default_value};
29 }
30
31 // Look up Specific Character Set (0008,0005)
33 auto scs = parse_specific_character_set(scs_value);
34
35 return decode_to_utf8(raw.value(), scs);
36}
37
41 vr_type vr,
42 std::string_view utf8_value) {
43
44 // Look up Specific Character Set (0008,0005)
46 auto scs = parse_specific_character_set(scs_value);
47
48 auto encoded = encode_from_utf8(utf8_value, scs);
50}
51
52} // namespace kcenon::pacs::encoding
auto get(dicom_tag tag) noexcept -> dicom_element *
Get a pointer to the element with the given tag.
void insert(dicom_element element)
Insert or replace an element in the dataset.
auto get_string(dicom_tag tag, std::string_view default_value="") const -> std::string
Get the string value of an element.
static auto from_string(dicom_tag tag, encoding::vr_type vr, std::string_view value) -> dicom_element
Create an element from a string value.
Character set-aware string access for DICOM datasets.
Compile-time constants for commonly used DICOM tags.
constexpr dicom_tag specific_character_set
Specific Character Set.
vr_type
DICOM Value Representation (VR) types.
Definition vr_type.h:29
std::string encode_from_utf8(std::string_view utf8_text, const specific_character_set &scs)
Encode a UTF-8 string to the target character set encoding.
specific_character_set parse_specific_character_set(std::string_view value)
Parse a Specific Character Set (0008,0005) value.
std::string get_decoded_string(const core::dicom_dataset &ds, core::dicom_tag tag, std::string_view default_value="")
Get a string value from dataset, decoded to UTF-8.
void set_encoded_string(core::dicom_dataset &ds, core::dicom_tag tag, vr_type vr, std::string_view utf8_value)
Set a string value in dataset, encoding from UTF-8.
std::string decode_to_utf8(std::string_view text, const specific_character_set &scs)
Decode a DICOM string to UTF-8 using the given character set.
vr_encoding vr