/src/dcmtk/dcmdata/libsrc/dcvrcs.cc
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1994-2021, 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: class DcmCodeString |
19 | | * |
20 | | */ |
21 | | |
22 | | |
23 | | #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ |
24 | | |
25 | | #include "dcmtk/dcmdata/dcvrcs.h" |
26 | | #include "dcmtk/dcmdata/dcmatch.h" |
27 | | |
28 | | |
29 | 0 | #define MAX_CS_LENGTH 16 |
30 | | |
31 | | |
32 | | // ******************************** |
33 | | |
34 | | |
35 | | DcmCodeString::DcmCodeString(const DcmTag &tag, |
36 | | const Uint32 len) |
37 | 0 | : DcmByteString(tag, len) |
38 | 0 | { |
39 | 0 | setMaxLength(MAX_CS_LENGTH); |
40 | 0 | setNonSignificantChars(" \\"); |
41 | 0 | } |
42 | | |
43 | | |
44 | | DcmCodeString::DcmCodeString(const DcmCodeString &old) |
45 | 0 | : DcmByteString(old) |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | |
50 | | DcmCodeString::~DcmCodeString() |
51 | 0 | { |
52 | 0 | } |
53 | | |
54 | | |
55 | | DcmCodeString &DcmCodeString::operator=(const DcmCodeString &obj) |
56 | 0 | { |
57 | 0 | DcmByteString::operator=(obj); |
58 | 0 | return *this; |
59 | 0 | } |
60 | | |
61 | | |
62 | | OFCondition DcmCodeString::copyFrom(const DcmObject& rhs) |
63 | 0 | { |
64 | 0 | if (this != &rhs) |
65 | 0 | { |
66 | 0 | if (rhs.ident() != ident()) return EC_IllegalCall; |
67 | 0 | *this = OFstatic_cast(const DcmCodeString &, rhs); |
68 | 0 | } |
69 | 0 | return EC_Normal; |
70 | 0 | } |
71 | | |
72 | | |
73 | | // ******************************** |
74 | | |
75 | | |
76 | | DcmEVR DcmCodeString::ident() const |
77 | 0 | { |
78 | 0 | return EVR_CS; |
79 | 0 | } |
80 | | |
81 | | |
82 | | OFCondition DcmCodeString::checkValue(const OFString &vm, |
83 | | const OFBool /*oldFormat*/) |
84 | 0 | { |
85 | 0 | OFString strVal; |
86 | | /* get "raw value" without any modifications (if possible) */ |
87 | 0 | OFCondition l_error = getStringValue(strVal); |
88 | 0 | if (l_error.good()) |
89 | 0 | l_error = DcmCodeString::checkStringValue(strVal, vm); |
90 | 0 | return l_error; |
91 | 0 | } |
92 | | |
93 | | |
94 | | // ******************************** |
95 | | |
96 | | |
97 | | OFCondition DcmCodeString::getOFString(OFString &stringVal, |
98 | | const unsigned long pos, |
99 | | OFBool normalize) |
100 | 0 | { |
101 | 0 | OFCondition l_error = DcmByteString::getOFString(stringVal, pos, normalize); |
102 | 0 | if (l_error.good() && normalize) |
103 | 0 | normalizeString(stringVal, !MULTIPART, DELETE_LEADING, DELETE_TRAILING); |
104 | 0 | return l_error; |
105 | 0 | } |
106 | | |
107 | | |
108 | | // ******************************** |
109 | | |
110 | | |
111 | | OFBool DcmCodeString::checkVR(const OFString &value, |
112 | | size_t *pos, |
113 | | const OFBool checkLength) |
114 | 0 | { |
115 | 0 | unsigned char c; |
116 | 0 | size_t i; |
117 | 0 | const size_t length = value.length(); |
118 | 0 | const size_t maxlen = (length < MAX_CS_LENGTH) || (!checkLength) ? length : MAX_CS_LENGTH; |
119 | | /* iterate over all characters (up to the maximum) */ |
120 | 0 | for (i = 0; i < maxlen; i++) |
121 | 0 | { |
122 | 0 | c = value.at(i); |
123 | | /* check for valid CS character: A-Z, 0-9, _ and ' ' (space) */ |
124 | 0 | if ((c != ' ') && (c != '_') && !isdigit(c) && !(isalpha(c) && isupper(c))) |
125 | 0 | break; |
126 | 0 | } |
127 | | /* return position of first invalid character (eos if all valid) */ |
128 | 0 | if (pos != NULL) |
129 | 0 | *pos = i; |
130 | | /* OFFalse in case of any invalid character */ |
131 | 0 | return (i == length); |
132 | 0 | } |
133 | | |
134 | | |
135 | | // ******************************** |
136 | | |
137 | | |
138 | | OFCondition DcmCodeString::checkStringValue(const OFString &value, |
139 | | const OFString &vm) |
140 | 0 | { |
141 | 0 | return DcmByteString::checkStringValue(value, vm, "cs", 10, MAX_CS_LENGTH); |
142 | 0 | } |
143 | | |
144 | | |
145 | | OFBool DcmCodeString::matches(const OFString& key, |
146 | | const OFString& candidate, |
147 | | const OFBool enableWildCardMatching) const |
148 | 0 | { |
149 | 0 | if (enableWildCardMatching) |
150 | 0 | return DcmAttributeMatching::wildCardMatching(key.c_str(), key.length(), candidate.c_str(), candidate.length()); |
151 | 0 | else |
152 | 0 | return DcmByteString::matches(key, candidate, OFFalse); |
153 | 0 | } |
154 | | |
155 | | |
156 | | OFBool DcmCodeString::isUniversalMatch(const OFBool normalize, |
157 | | const OFBool enableWildCardMatching) |
158 | 0 | { |
159 | 0 | if(!isEmpty(normalize)) |
160 | 0 | { |
161 | 0 | if(enableWildCardMatching) |
162 | 0 | { |
163 | 0 | OFString value; |
164 | 0 | for(unsigned long valNo = 0; valNo < getVM(); ++valNo) |
165 | 0 | { |
166 | 0 | getOFString(value, valNo, normalize); |
167 | 0 | if(value.find_first_not_of( '*' ) != OFString_npos) |
168 | 0 | return OFFalse; |
169 | 0 | } |
170 | 0 | } |
171 | 0 | else |
172 | 0 | return OFFalse; |
173 | 0 | } |
174 | 0 | return OFTrue; |
175 | 0 | } |