/src/dcmtk/dcmdata/libsrc/dcvrlo.cc
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1994-2022, OFFIS e.V. |
4 | | * All rights reserved. See COPYRIGHT file for details. |
5 | | * |
6 | | * This software and supporting documentation were developed by |
7 | | * |
8 | | * OFFIS e.V. |
9 | | * R&D Division Health |
10 | | * Escherweg 2 |
11 | | * D-26121 Oldenburg, Germany |
12 | | * |
13 | | * |
14 | | * Module: dcmdata |
15 | | * |
16 | | * Author: Gerd Ehlers, Andreas Barth |
17 | | * |
18 | | * Purpose: Implementation class DcmLongString |
19 | | * |
20 | | */ |
21 | | |
22 | | |
23 | | #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ |
24 | | |
25 | | #include "dcmtk/dcmdata/dcjson.h" |
26 | | #include "dcmtk/dcmdata/dcvrlo.h" |
27 | | |
28 | | |
29 | | // ******************************** |
30 | | |
31 | | |
32 | | DcmLongString::DcmLongString(const DcmTag &tag, |
33 | | const Uint32 len) |
34 | 0 | : DcmCharString(tag, len) |
35 | 0 | { |
36 | 0 | setMaxLength(64); |
37 | 0 | setNonSignificantChars(" \\"); |
38 | 0 | } |
39 | | |
40 | | |
41 | | DcmLongString::DcmLongString(const DcmLongString &old) |
42 | 0 | : DcmCharString(old) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | |
47 | | DcmLongString::~DcmLongString() |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | |
52 | | DcmLongString &DcmLongString::operator=(const DcmLongString &obj) |
53 | 0 | { |
54 | 0 | DcmCharString::operator=(obj); |
55 | 0 | return *this; |
56 | 0 | } |
57 | | |
58 | | |
59 | | OFCondition DcmLongString::copyFrom(const DcmObject& rhs) |
60 | 0 | { |
61 | 0 | if (this != &rhs) |
62 | 0 | { |
63 | 0 | if (rhs.ident() != ident()) return EC_IllegalCall; |
64 | 0 | *this = OFstatic_cast(const DcmLongString &, rhs); |
65 | 0 | } |
66 | 0 | return EC_Normal; |
67 | 0 | } |
68 | | |
69 | | |
70 | | // ******************************** |
71 | | |
72 | | |
73 | | DcmEVR DcmLongString::ident() const |
74 | 0 | { |
75 | 0 | return EVR_LO; |
76 | 0 | } |
77 | | |
78 | | |
79 | | OFCondition DcmLongString::checkValue(const OFString &vm, |
80 | | const OFBool /*oldFormat*/) |
81 | 0 | { |
82 | 0 | OFString strVal; |
83 | | /* get "raw value" without any modifications (if possible) */ |
84 | 0 | OFCondition l_error = getStringValue(strVal); |
85 | 0 | if (l_error.good()) |
86 | 0 | { |
87 | 0 | OFString charset; |
88 | | /* try to determine the value of the SpecificCharacterSet element */ |
89 | 0 | if (getSpecificCharacterSet(charset) == EC_CorruptedData) |
90 | 0 | charset = "UNKNOWN"; |
91 | 0 | l_error = DcmLongString::checkStringValue(strVal, vm, charset); |
92 | 0 | } |
93 | 0 | return l_error; |
94 | 0 | } |
95 | | |
96 | | |
97 | | // ******************************** |
98 | | |
99 | | |
100 | | OFCondition DcmLongString::getOFString(OFString &stringVal, |
101 | | const unsigned long pos, |
102 | | OFBool normalize) |
103 | 0 | { |
104 | 0 | OFCondition l_error = DcmCharString::getOFString(stringVal, pos, normalize); |
105 | 0 | if (l_error.good() && normalize) |
106 | 0 | normalizeString(stringVal, !MULTIPART, DELETE_LEADING, DELETE_TRAILING); |
107 | 0 | return l_error; |
108 | 0 | } |
109 | | |
110 | | |
111 | | // ******************************** |
112 | | |
113 | | |
114 | | OFCondition DcmLongString::checkStringValue(const OFString &value, |
115 | | const OFString &vm, |
116 | | const OFString &charset) |
117 | 0 | { |
118 | 0 | return DcmByteString::checkStringValue(value, vm, "lo", 12, 0 /* maxLen: no check */, charset); |
119 | 0 | } |
120 | | |
121 | | |
122 | | // ******************************** |
123 | | |
124 | | |
125 | | OFCondition DcmLongString::writeJson(STD_NAMESPACE ostream &out, |
126 | | DcmJsonFormat &format) |
127 | 0 | { |
128 | | /* always write JSON Opener */ |
129 | 0 | DcmElement::writeJsonOpener(out, format); |
130 | | /* write element value (if non-empty) */ |
131 | 0 | if (!isEmpty()) |
132 | 0 | { |
133 | 0 | OFString value; |
134 | 0 | OFCondition status = getOFString(value, 0L); |
135 | 0 | if (status.bad()) |
136 | 0 | return status; |
137 | 0 | format.printValuePrefix(out); |
138 | 0 | DcmJsonFormat::printValueString(out, value); |
139 | 0 | const unsigned long vm = getVM(); |
140 | 0 | for (unsigned long valNo = 1; valNo < vm; ++valNo) |
141 | 0 | { |
142 | 0 | status = getOFString(value, valNo); |
143 | 0 | if (status.bad()) |
144 | 0 | return status; |
145 | 0 | format.printNextArrayElementPrefix(out); |
146 | 0 | DcmJsonFormat::printValueString(out, value); |
147 | 0 | } |
148 | 0 | format.printValueSuffix(out); |
149 | 0 | } |
150 | | /* write JSON Closer */ |
151 | 0 | DcmElement::writeJsonCloser(out, format); |
152 | | /* always report success */ |
153 | 0 | return EC_Normal; |
154 | 0 | } |