Coverage Report

Created: 2026-03-12 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/FBX/FBXTokenizer.h
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
42
/** @file  FBXTokenizer.h
43
 *  @brief FBX lexer
44
 */
45
#ifndef INCLUDED_AI_FBX_TOKENIZER_H
46
#define INCLUDED_AI_FBX_TOKENIZER_H
47
48
#include "FBXCompileConfig.h"
49
#include "Common/StackAllocator.h"
50
#include <assimp/ai_assert.h>
51
#include <assimp/defs.h>
52
#include <vector>
53
#include <string>
54
55
namespace Assimp {
56
namespace FBX {
57
58
/** Rough classification for text FBX tokens used for constructing the
59
 *  basic scope hierarchy. */
60
enum TokenType
61
{
62
    // {
63
    TokenType_OPEN_BRACKET = 0,
64
65
    // }
66
    TokenType_CLOSE_BRACKET,
67
68
    // '"blablubb"', '2', '*14' - very general token class,
69
    // further processing happens at a later stage.
70
    TokenType_DATA,
71
72
    //
73
    TokenType_BINARY_DATA,
74
75
    // ,
76
    TokenType_COMMA,
77
78
    // blubb:
79
    TokenType_KEY
80
};
81
82
83
/** Represents a single token in a FBX file. Tokens are
84
 *  classified by the #TokenType enumerated types.
85
 *
86
 *  Offers iterator protocol. Tokens are immutable. */
87
class Token
88
{
89
private:
90
    static const unsigned int BINARY_MARKER = static_cast<unsigned int>(-1);
91
92
public:
93
    /** construct a textual token */
94
    Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column);
95
96
    /** construct a binary token */
97
    Token(const char* sbegin, const char* send, TokenType type, size_t offset);
98
99
    ~Token() = default;
100
101
public:
102
933k
    std::string StringContents() const {
103
933k
        return std::string(begin(),end());
104
933k
    }
105
106
1.46M
    bool IsBinary() const {
107
1.46M
        return column == BINARY_MARKER;
108
1.46M
    }
109
110
3.24M
    const char* begin() const {
111
3.24M
        return sbegin;
112
3.24M
    }
113
114
3.47M
    const char* end() const {
115
3.47M
        return send;
116
3.47M
    }
117
118
17.0M
    TokenType Type() const {
119
17.0M
        return type;
120
17.0M
    }
121
122
6.75k
    size_t Offset() const {
123
6.75k
        ai_assert(IsBinary());
124
6.75k
        return offset;
125
6.75k
    }
126
127
15.2k
    unsigned int Line() const {
128
15.2k
        ai_assert(!IsBinary());
129
15.2k
        return static_cast<unsigned int>(line);
130
15.2k
    }
131
132
11.3k
    unsigned int Column() const {
133
11.3k
        ai_assert(!IsBinary());
134
11.3k
        return column;
135
11.3k
    }
136
137
private:
138
139
#ifdef DEBUG
140
    // full string copy for the sole purpose that it nicely appears
141
    // in msvc's debugger window.
142
    const std::string contents;
143
#endif
144
145
146
    const char* const sbegin;
147
    const char* const send;
148
    const TokenType type;
149
150
    union {
151
        size_t line;
152
        size_t offset;
153
    };
154
    const unsigned int column;
155
};
156
157
typedef const Token* TokenPtr;
158
typedef std::vector< TokenPtr > TokenList;
159
160
17.4M
#define new_Token new (token_allocator.Allocate(sizeof(Token))) Token
161
#define delete_Token(_p) (_p)->~Token()
162
163
164
/** Main FBX tokenizer function. Transform input buffer into a list of preprocessed tokens.
165
 *
166
 *  Skips over comments and generates line and column numbers.
167
 *
168
 * @param output_tokens Receives a list of all tokens in the input data.
169
 * @param input_buffer Textual input buffer to be processed, 0-terminated.
170
 * @throw DeadlyImportError if something goes wrong */
171
void Tokenize(TokenList &output_tokens, const char *input, StackAllocator &tokenAllocator);
172
173
174
/** Tokenizer function for binary FBX files.
175
 *
176
 *  Emits a token list suitable for direct parsing.
177
 *
178
 * @param output_tokens Receives a list of all tokens in the input data.
179
 * @param input_buffer Binary input buffer to be processed.
180
 * @param length Length of input buffer, in bytes. There is no 0-terminal.
181
 * @throw DeadlyImportError if something goes wrong */
182
void TokenizeBinary(TokenList &output_tokens, const char *input, size_t length, StackAllocator &tokenAllocator);
183
184
185
} // ! FBX
186
} // ! Assimp
187
188
#endif // ! INCLUDED_AI_FBX_PARSER_H