Coverage Report

Created: 2025-08-26 06:41

/src/assimp/code/AssetLib/glTFCommon/glTFCommon.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, 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
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
42
43
#include "AssetLib/glTFCommon/glTFCommon.h"
44
45
namespace glTFCommon {
46
47
using namespace glTFCommon::Util;
48
49
namespace Util {
50
51
0
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
52
0
    if (nullptr == const_uri) {
53
0
        return false;
54
0
    }
55
56
0
    if (const_uri[0] != 0x10) { // we already parsed this uri?
57
0
        if (strncmp(const_uri, "data:", 5) != 0) // not a data uri?
58
0
            return false;
59
0
    }
60
61
    // set defaults
62
0
    out.mediaType = "text/plain";
63
0
    out.charset = "US-ASCII";
64
0
    out.base64 = false;
65
66
0
    char *uri = const_cast<char *>(const_uri);
67
0
    if (uri[0] != 0x10) {
68
0
        uri[0] = 0x10;
69
0
        uri[1] = uri[2] = uri[3] = uri[4] = 0;
70
71
0
        size_t i = 5, j;
72
0
        if (uri[i] != ';' && uri[i] != ',') { // has media type?
73
0
            uri[1] = char(i);
74
0
            for (;i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
75
                // nothing to do!
76
0
            }
77
0
        }
78
0
        while (i < uriLen && uri[i] == ';') {
79
0
            uri[i++] = '\0';
80
0
            for (j = i; i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
81
                // nothing to do!
82
0
            }
83
84
0
            if (strncmp(uri + j, "charset=", 8) == 0) {
85
0
                uri[2] = char(j + 8);
86
0
            } else if (strncmp(uri + j, "base64", 6) == 0) {
87
0
                uri[3] = char(j);
88
0
            }
89
0
        }
90
0
        if (i < uriLen) {
91
0
            uri[i++] = '\0';
92
0
            uri[4] = char(i);
93
0
        } else {
94
0
            uri[1] = uri[2] = uri[3] = 0;
95
0
            uri[4] = 5;
96
0
        }
97
0
    }
98
99
0
    if (uri[1] != 0) {
100
0
        out.mediaType = uri + uri[1];
101
0
    }
102
0
    if (uri[2] != 0) {
103
0
        out.charset = uri + uri[2];
104
0
    }
105
0
    if (uri[3] != 0) {
106
0
        out.base64 = true;
107
0
    }
108
0
    out.data = uri + uri[4];
109
0
    out.dataLength = (uri + uriLen) - out.data;
110
111
0
    return true;
112
0
}
113
114
} // namespace Util
115
} // namespace glTFCommon
116
117
#endif