Coverage Report

Created: 2026-08-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/dcmdata/libsrc/dcvrst.cc
Line
Count
Source
1
/*
2
 *
3
 *  Copyright (C) 1994-2024, 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
17
 *
18
 *  Purpose: Implementation of class DcmShortText
19
 *
20
 */
21
22
23
#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
24
25
#include "dcmtk/dcmdata/dcvrst.h"
26
27
28
// ********************************
29
30
31
DcmShortText::DcmShortText(const DcmTag &tag,
32
                           const Uint32 len)
33
1.15k
  : DcmCharString(tag, len)
34
1.15k
{
35
1.15k
    setMaxLength(1024);
36
1.15k
}
37
38
39
DcmShortText::DcmShortText(const DcmShortText &old)
40
0
  : DcmCharString(old)
41
0
{
42
0
}
43
44
45
DcmShortText::~DcmShortText()
46
1.15k
{
47
1.15k
}
48
49
50
DcmShortText &DcmShortText::operator=(const DcmShortText &obj)
51
0
{
52
0
    DcmCharString::operator=(obj);
53
0
    return *this;
54
0
}
55
56
57
int DcmShortText::compare(const DcmElement& rhs) const
58
0
{
59
0
    int result = DcmElement::compare(rhs);
60
0
    if (result != 0)
61
0
    {
62
0
        return result;
63
0
    }
64
65
    /* cast away constness (dcmdata is not const correct...) */
66
0
    DcmShortText* myThis = NULL;
67
0
    DcmShortText* myRhs = NULL;
68
0
    myThis = OFconst_cast(DcmShortText*, this);
69
0
    myRhs = OFstatic_cast(DcmShortText*, OFconst_cast(DcmElement*, &rhs));
70
71
    /* compare length */
72
0
    unsigned long thisLength = myThis->getLength();
73
0
    unsigned long rhsLength = myRhs->getLength();
74
0
    if (thisLength < rhsLength)
75
0
    {
76
0
        return -1;
77
0
    }
78
0
    else if (thisLength > rhsLength)
79
0
    {
80
0
        return 1;
81
0
    }
82
83
    /* check whether values are equal */
84
0
    OFString thisValue, rhsValue;
85
0
    myThis->getOFStringArray(thisValue);
86
0
    myRhs->getOFStringArray(rhsValue);
87
0
    return thisValue.compare(rhsValue);
88
0
}
89
90
91
OFCondition DcmShortText::copyFrom(const DcmObject& rhs)
92
0
{
93
0
    if (this != &rhs)
94
0
    {
95
0
        if (rhs.ident() != ident()) return EC_IllegalCall;
96
0
        *this = OFstatic_cast(const DcmShortText &, rhs);
97
0
    }
98
0
    return EC_Normal;
99
0
}
100
101
102
// ********************************
103
104
105
DcmEVR DcmShortText::ident() const
106
170
{
107
170
    return EVR_ST;
108
170
}
109
110
111
OFCondition DcmShortText::checkValue(const OFString & /*vm*/,
112
                                     const OFBool /*oldFormat*/)
113
0
{
114
0
    OFString strVal;
115
    /* get "raw value" without any modifications (if possible) */
116
0
    OFCondition l_error = getStringValue(strVal);
117
0
    if (l_error.good())
118
0
    {
119
0
        OFString charset;
120
        /* try to determine the value of the SpecificCharacterSet element */
121
0
        if (getSpecificCharacterSet(charset) == EC_CorruptedData)
122
0
            charset = "UNKNOWN";
123
0
        l_error = DcmShortText::checkStringValue(strVal, charset);
124
0
    }
125
0
    return l_error;
126
0
}
127
128
129
unsigned long DcmShortText::getVM()
130
0
{
131
    /* value multiplicity is 1 for non-empty string, 0 otherwise */
132
0
    return (getRealLength() > 0) ? 1 : 0;
133
0
}
134
135
136
// ********************************
137
138
139
OFCondition DcmShortText::getOFString(OFString &stringVal,
140
                                      const unsigned long /*pos*/,
141
                                      OFBool normalize)
142
14
{
143
    /* treat backslash as a normal character */
144
14
    return getOFStringArray(stringVal, normalize);
145
14
}
146
147
148
OFCondition DcmShortText::getOFStringArray(OFString &stringVal,
149
                                           OFBool normalize)
150
14
{
151
    /* get string value without handling the "\" as a delimiter */
152
14
    OFCondition l_error = getStringValue(stringVal);
153
14
    if (l_error.good() && normalize)
154
14
        normalizeString(stringVal, !MULTIPART, !DELETE_LEADING, DELETE_TRAILING);
155
14
    return l_error;
156
14
}
157
158
159
// ********************************
160
161
162
OFCondition DcmShortText::checkStringValue(const OFString &value,
163
                                           const OFString &charset)
164
0
{
165
0
    return DcmByteString::checkStringValue(value, "" /* vm */, "lt", 14, 0 /* maxLen: no check */, charset);
166
0
}