Replaced snprintf with stringstream
Deleted now unused TINYOBJ_SSCANF_BUFFER_SIZE
This commit is contained in:
@@ -44,6 +44,7 @@ THE SOFTWARE.
|
||||
#define TINY_OBJ_LOADER_H_
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -364,7 +365,6 @@ namespace tinyobj {
|
||||
|
||||
MaterialReader::~MaterialReader() {}
|
||||
|
||||
#define TINYOBJ_SSCANF_BUFFER_SIZE (4096)
|
||||
|
||||
struct vertex_index {
|
||||
int v_idx, vt_idx, vn_idx;
|
||||
@@ -1030,10 +1030,10 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
||||
has_tr = false;
|
||||
|
||||
// set new mtl name
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 7;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
material.name = namebuf;
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
material.name = ss.str();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1537,9 +1537,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
|
||||
// use mtl
|
||||
if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) {
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 7;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
std::string namebuf = ss.str();
|
||||
|
||||
int newMaterialId = -1;
|
||||
if (material_map.find(namebuf) != material_map.end()) {
|
||||
@@ -1653,10 +1654,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
shape = shape_t();
|
||||
|
||||
// @todo { multiple object name? }
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 2;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
name = std::string(namebuf);
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
name = ss.str();
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -1664,10 +1665,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
if (token[0] == 't' && IS_SPACE(token[1])) {
|
||||
tag_t tag;
|
||||
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 2;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
tag.name = std::string(namebuf);
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
tag.name = ss.str();
|
||||
|
||||
token += tag.name.size() + 1;
|
||||
|
||||
@@ -1688,10 +1689,9 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
|
||||
tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
|
||||
char stringValueBuffer[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
|
||||
std::snprintf(stringValueBuffer, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
tag.stringValues[i] = stringValueBuffer;
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
tag.stringValues[i] = ss.str();
|
||||
token += tag.stringValues[i].size() + 1;
|
||||
}
|
||||
|
||||
@@ -1830,9 +1830,10 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||
|
||||
// use mtl
|
||||
if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) {
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 7;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
std::string namebuf = ss.str();
|
||||
|
||||
int newMaterialId = -1;
|
||||
if (material_map.find(namebuf) != material_map.end()) {
|
||||
@@ -1846,7 +1847,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||
}
|
||||
|
||||
if (callback.usemtl_cb) {
|
||||
callback.usemtl_cb(user_data, namebuf, material_id);
|
||||
callback.usemtl_cb(user_data, namebuf.c_str(), material_id);
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -1940,10 +1941,11 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||
// object name
|
||||
if (token[0] == 'o' && IS_SPACE((token[1]))) {
|
||||
// @todo { multiple object name? }
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 2;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
std::string object_name = std::string(namebuf);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
std::string object_name = ss.str();
|
||||
|
||||
if (callback.object_cb) {
|
||||
callback.object_cb(user_data, object_name.c_str());
|
||||
@@ -1956,10 +1958,10 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||
if (token[0] == 't' && IS_SPACE(token[1])) {
|
||||
tag_t tag;
|
||||
|
||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
token += 2;
|
||||
std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
tag.name = std::string(namebuf);
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
tag.name = ss.str();
|
||||
|
||||
token += tag.name.size() + 1;
|
||||
|
||||
@@ -1980,10 +1982,9 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||
|
||||
tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
|
||||
char stringValueBuffer[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||
|
||||
std::snprintf(stringValueBuffer, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
|
||||
tag.stringValues[i] = stringValueBuffer;
|
||||
std::stringstream ss;
|
||||
ss << token;
|
||||
tag.stringValues[i] = ss.str();
|
||||
token += tag.stringValues[i].size() + 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user