Coverage Report

Created: 2026-02-05 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/glTFCommon/glTFCommon.cpp
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2026, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
copyright notice, this list of conditions and the
15
following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
copyright notice, this list of conditions and the
19
following disclaimer in the documentation and/or other
20
materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
contributors may be used to endorse or promote products
24
derived from this software without specific prior
25
written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
#include "AssetLib/glTFCommon/glTFCommon.h"
42
43
using namespace glTFCommon::Util;
44
45
namespace glTFCommon::Util {
46
47
1.40k
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
48
1.40k
    if (nullptr == const_uri) {
49
0
        return false;
50
0
    }
51
52
1.40k
    if (const_uri[0] != 0x10) { // we already parsed this uri?
53
1.40k
        if (strncmp(const_uri, "data:", 5) != 0) // not a data uri?
54
295
            return false;
55
1.40k
    }
56
57
    // set defaults
58
1.10k
    out.mediaType = "text/plain";
59
1.10k
    out.charset = "US-ASCII";
60
1.10k
    out.base64 = false;
61
62
1.10k
    char *uri = const_cast<char *>(const_uri);
63
1.10k
    if (uri[0] != 0x10) {
64
1.10k
        uri[0] = 0x10;
65
1.10k
        uri[1] = uri[2] = uri[3] = uri[4] = 0;
66
67
1.10k
        size_t i = 5, j;
68
1.10k
        if (uri[i] != ';' && uri[i] != ',') { // has media type?
69
1.10k
            uri[1] = char(i);
70
27.9k
            for (;i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
71
                // nothing to do!
72
26.8k
            }
73
1.10k
        }
74
2.32k
        while (i < uriLen && uri[i] == ';') {
75
1.21k
            uri[i++] = '\0';
76
15.0k
            for (j = i; i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
77
                // nothing to do!
78
13.8k
            }
79
80
1.21k
            if (strncmp(uri + j, "charset=", 8) == 0) {
81
6
                uri[2] = char(j + 8);
82
1.20k
            } else if (strncmp(uri + j, "base64", 6) == 0) {
83
1.06k
                uri[3] = char(j);
84
1.06k
            }
85
1.21k
        }
86
1.10k
        if (i < uriLen) {
87
1.08k
            uri[i++] = '\0';
88
1.08k
            uri[4] = char(i);
89
1.08k
        } else {
90
20
            uri[1] = uri[2] = uri[3] = 0;
91
20
            uri[4] = 5;
92
20
        }
93
1.10k
    }
94
95
1.10k
    if (uri[1] != 0) {
96
1.08k
        out.mediaType = uri + uri[1];
97
1.08k
    }
98
1.10k
    if (uri[2] != 0) {
99
2
        out.charset = uri + uri[2];
100
2
    }
101
1.10k
    if (uri[3] != 0) {
102
1.06k
        out.base64 = true;
103
1.06k
    }
104
1.10k
    out.data = uri + uri[4];
105
1.10k
    out.dataLength = (uri + uriLen) - out.data;
106
107
1.10k
    return true;
108
1.40k
}
109
110
} // namespace glTFCommon::Uti