Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/exiv2/xmpsdk/src/UnicodeInlines.incl_cpp
Line
Count
Source
1
#ifndef __UnicodeInlines_incl_cpp__
2
#define __UnicodeInlines_incl_cpp__
3
4
// =================================================================================================
5
// Copyright 2002-2007 Adobe Systems Incorporated
6
// All Rights Reserved.
7
//
8
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
9
// of the Adobe license agreement accompanying it.
10
// =================================================================================================
11
12
#include "UnicodeConversions.hpp"
13
14
// =================================================================================================
15
// Inner loop utilities that need to be inlined.
16
// =================================================================================================
17
18
static inline XMP_Uns32 GetCodePoint ( const XMP_Uns8 ** utf8Str_io )
19
0
{
20
0
  const XMP_Uns8 * u8Ptr = *utf8Str_io;
21
0
  XMP_Uns32 cp;
22
0
  size_t u8Len;
23
0
  CodePoint_from_UTF8 ( u8Ptr, 4, &cp, &u8Len );  // Throws an exception for errors.
24
0
  *utf8Str_io = u8Ptr + u8Len;
25
0
  return cp;
26
0
}
Unexecuted instantiation: XMPCore_Impl.cpp:GetCodePoint(unsigned char const**)
Unexecuted instantiation: XMPMeta-GetSet.cpp:GetCodePoint(unsigned char const**)
Unexecuted instantiation: XMPMeta-Parse.cpp:GetCodePoint(unsigned char const**)
Unexecuted instantiation: XMPMeta-Serialize.cpp:GetCodePoint(unsigned char const**)
Unexecuted instantiation: XMPMeta.cpp:GetCodePoint(unsigned char const**)
27
28
// =================================================================================================
29
30
static inline bool IsStartChar_ASCII ( XMP_Uns32 cp )
31
1.11M
{
32
  // ASCII starting characters for an XML name.
33
1.11M
  if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true;
34
38.2k
  return false;
35
1.11M
}
XMPCore_Impl.cpp:IsStartChar_ASCII(unsigned int)
Line
Count
Source
31
1.09M
{
32
  // ASCII starting characters for an XML name.
33
1.09M
  if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true;
34
37.8k
  return false;
35
1.09M
}
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsStartChar_ASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Parse.cpp:IsStartChar_ASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Serialize.cpp:IsStartChar_ASCII(unsigned int)
XMPMeta.cpp:IsStartChar_ASCII(unsigned int)
Line
Count
Source
31
24.6k
{
32
  // ASCII starting characters for an XML name.
33
24.6k
  if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true;
34
396
  return false;
35
24.6k
}
36
37
// -------------------------------------------------------------------------------------------------
38
39
static inline bool IsStartChar_NonASCII ( XMP_Uns32 cp )
40
0
{
41
  // Non-ASCII starting characters for an XML name.
42
  
43
0
  if ( ((0xC0 <= cp) && (cp <= 0xD6))  || ((0xD8 <= cp) && (cp <= 0xF6)) ) return true;
44
0
  if ( ((0xF8 <= cp) && (cp <= 0x2FF)) || ((0x370 <= cp) && (cp <= 0x37D)) ) return true;
45
46
0
  if ( ((0x37F <= cp) && (cp <= 0x1FFF))  || ((0x200C <= cp) && (cp <= 0x200D)) ) return true;
47
0
  if ( ((0x2070 <= cp) && (cp <= 0x218F)) || ((0x2C00 <= cp) && (cp <= 0x2FEF)) ) return true;
48
0
  if ( ((0x3001 <= cp) && (cp <= 0xD7FF)) || ((0xF900 <= cp) && (cp <= 0xFDCF)) ) return true;
49
0
  if ( ((0xFDF0 <= cp) && (cp <= 0xFFFD)) || ((0x10000 <= cp) && (cp <= 0xEFFFF)) ) return true;
50
51
0
  return false;
52
53
0
}
Unexecuted instantiation: XMPCore_Impl.cpp:IsStartChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsStartChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Parse.cpp:IsStartChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Serialize.cpp:IsStartChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta.cpp:IsStartChar_NonASCII(unsigned int)
54
55
// -------------------------------------------------------------------------------------------------
56
57
static inline bool IsOtherChar_ASCII ( XMP_Uns32 cp )
58
38.2k
{
59
  // ASCII following characters for an XML name.
60
38.2k
  if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true;
61
0
  return false;
62
38.2k
}
XMPCore_Impl.cpp:IsOtherChar_ASCII(unsigned int)
Line
Count
Source
58
37.8k
{
59
  // ASCII following characters for an XML name.
60
37.8k
  if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true;
61
0
  return false;
62
37.8k
}
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsOtherChar_ASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Parse.cpp:IsOtherChar_ASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Serialize.cpp:IsOtherChar_ASCII(unsigned int)
XMPMeta.cpp:IsOtherChar_ASCII(unsigned int)
Line
Count
Source
58
396
{
59
  // ASCII following characters for an XML name.
60
396
  if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true;
61
0
  return false;
62
396
}
63
64
// -------------------------------------------------------------------------------------------------
65
66
static inline bool IsOtherChar_NonASCII ( XMP_Uns32 cp )
67
0
{
68
  // Non-ASCII following characters for an XML name.
69
0
  if ( (cp == 0xB7) || ((0x300 <= cp) && (cp <= 0x36F))  || ((0x203F <= cp) && (cp <= 0x2040)) ) return true;
70
0
  return false;
71
0
}
Unexecuted instantiation: XMPCore_Impl.cpp:IsOtherChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsOtherChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Parse.cpp:IsOtherChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta-Serialize.cpp:IsOtherChar_NonASCII(unsigned int)
Unexecuted instantiation: XMPMeta.cpp:IsOtherChar_NonASCII(unsigned int)
72
73
// -------------------------------------------------------------------------------------------------
74
75
static inline void VerifyUTF8 ( XMP_StringPtr str )
76
0
{
77
0
  const XMP_Uns8 * utf8Str = (XMP_Uns8*)str;
78
0
  while ( *utf8Str != 0 ) {
79
0
    while ( (*utf8Str != 0) && (*utf8Str < 0x80) ) ++utf8Str;
80
0
    if ( *utf8Str >= 0x80 ) (void) GetCodePoint ( &utf8Str ); // Throws for bad UTF-8.
81
0
  }
82
0
}
Unexecuted instantiation: XMPCore_Impl.cpp:VerifyUTF8(char const*)
Unexecuted instantiation: XMPMeta-GetSet.cpp:VerifyUTF8(char const*)
Unexecuted instantiation: XMPMeta-Parse.cpp:VerifyUTF8(char const*)
Unexecuted instantiation: XMPMeta-Serialize.cpp:VerifyUTF8(char const*)
Unexecuted instantiation: XMPMeta.cpp:VerifyUTF8(char const*)
83
84
// -------------------------------------------------------------------------------------------------
85
86
static inline void VerifySimpleXMLName ( XMP_StringPtr _nameStart, XMP_StringPtr _nameEnd )
87
137k
{
88
89
137k
  const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart;
90
137k
  const XMP_Uns8 * nameEnd   = (const XMP_Uns8 *) _nameEnd;
91
137k
  const XMP_Uns8 * namePos   = nameStart;
92
137k
  XMP_Uns32 cp;
93
  
94
  // The first character is more restricted.
95
  
96
137k
  if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath );
97
98
137k
  cp = *namePos;
99
137k
  if ( cp < 0x80 ) {
100
137k
    ++namePos;
101
137k
    if ( ! IsStartChar_ASCII(cp) ) goto NameError;
102
137k
  } else {
103
0
    cp = GetCodePoint ( &namePos );
104
0
    if ( ! IsStartChar_NonASCII(cp) ) goto NameError;
105
0
  }
106
107
  // Check the rest of the name.
108
  
109
1.11M
  while ( namePos < nameEnd ) {
110
981k
    cp = *namePos;
111
981k
    if ( cp < 0x80 ) {
112
981k
      ++namePos;
113
981k
      if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError;
114
981k
    } else {
115
0
      cp = GetCodePoint ( &namePos );
116
0
      if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError;
117
0
    }
118
981k
  }
119
120
137k
  return;
121
122
137k
NameError:
123
0
  XMP_Throw ( "Bad XML name", kXMPErr_BadXPath );
124
  
125
0
}  // VerifySimpleXMLName
XMPCore_Impl.cpp:VerifySimpleXMLName(char const*, char const*)
Line
Count
Source
87
132k
{
88
89
132k
  const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart;
90
132k
  const XMP_Uns8 * nameEnd   = (const XMP_Uns8 *) _nameEnd;
91
132k
  const XMP_Uns8 * namePos   = nameStart;
92
132k
  XMP_Uns32 cp;
93
  
94
  // The first character is more restricted.
95
  
96
132k
  if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath );
97
98
132k
  cp = *namePos;
99
132k
  if ( cp < 0x80 ) {
100
132k
    ++namePos;
101
132k
    if ( ! IsStartChar_ASCII(cp) ) goto NameError;
102
132k
  } else {
103
0
    cp = GetCodePoint ( &namePos );
104
0
    if ( ! IsStartChar_NonASCII(cp) ) goto NameError;
105
0
  }
106
107
  // Check the rest of the name.
108
  
109
1.09M
  while ( namePos < nameEnd ) {
110
961k
    cp = *namePos;
111
961k
    if ( cp < 0x80 ) {
112
961k
      ++namePos;
113
961k
      if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError;
114
961k
    } else {
115
0
      cp = GetCodePoint ( &namePos );
116
0
      if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError;
117
0
    }
118
961k
  }
119
120
132k
  return;
121
122
132k
NameError:
123
0
  XMP_Throw ( "Bad XML name", kXMPErr_BadXPath );
124
  
125
0
}  // VerifySimpleXMLName
Unexecuted instantiation: XMPMeta-GetSet.cpp:VerifySimpleXMLName(char const*, char const*)
Unexecuted instantiation: XMPMeta-Parse.cpp:VerifySimpleXMLName(char const*, char const*)
Unexecuted instantiation: XMPMeta-Serialize.cpp:VerifySimpleXMLName(char const*, char const*)
XMPMeta.cpp:VerifySimpleXMLName(char const*, char const*)
Line
Count
Source
87
5.16k
{
88
89
5.16k
  const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart;
90
5.16k
  const XMP_Uns8 * nameEnd   = (const XMP_Uns8 *) _nameEnd;
91
5.16k
  const XMP_Uns8 * namePos   = nameStart;
92
5.16k
  XMP_Uns32 cp;
93
  
94
  // The first character is more restricted.
95
  
96
5.16k
  if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath );
97
98
5.16k
  cp = *namePos;
99
5.16k
  if ( cp < 0x80 ) {
100
5.16k
    ++namePos;
101
5.16k
    if ( ! IsStartChar_ASCII(cp) ) goto NameError;
102
5.16k
  } else {
103
0
    cp = GetCodePoint ( &namePos );
104
0
    if ( ! IsStartChar_NonASCII(cp) ) goto NameError;
105
0
  }
106
107
  // Check the rest of the name.
108
  
109
24.6k
  while ( namePos < nameEnd ) {
110
19.5k
    cp = *namePos;
111
19.5k
    if ( cp < 0x80 ) {
112
19.5k
      ++namePos;
113
19.5k
      if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError;
114
19.5k
    } else {
115
0
      cp = GetCodePoint ( &namePos );
116
0
      if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError;
117
0
    }
118
19.5k
  }
119
120
5.16k
  return;
121
122
5.16k
NameError:
123
0
  XMP_Throw ( "Bad XML name", kXMPErr_BadXPath );
124
  
125
0
}  // VerifySimpleXMLName
126
127
// =================================================================================================
128
129
#endif  // __UnicodeInlines_incl_cpp__