Core/Misc: update g3dlite lib (#2904)

* Core/Misc: update g3dlite lib

* update

Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
This commit is contained in:
Viste
2020-07-30 13:35:45 +03:00
committed by GitHub
parent 91bbbf08eb
commit fcaf91b8b2
183 changed files with 13258 additions and 8022 deletions

View File

@@ -1,10 +1,10 @@
/**
@file stringutils.cpp
\file stringutils.cpp
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
\maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2000-09-09
@edited 2008-01-10
\created 2000-09-09
\edited 2011-08-20
*/
#include "G3D/platform.h"
@@ -12,6 +12,14 @@
#include "G3D/BinaryInput.h"
#include <algorithm>
#ifdef G3D_WINDOWS
extern "C" {
// Define functions for ffmpeg since we don't link in gcc's c library
extern int strncasecmp(const char *string1, const char *string2, size_t count) { return _strnicmp(string1, string2, count); }
extern int strcasecmp(const char *string1, const char *string2) { return _stricmp(string1, string2); }
}
#endif
namespace G3D {
#ifdef _MSC_VER
@@ -19,7 +27,7 @@ namespace G3D {
# pragma warning (push)
# pragma warning (disable : 4530)
#endif
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
const char* NEWLINE = "\r\n";
#else
const char* NEWLINE = "\n";
@@ -56,7 +64,7 @@ void parseCommaSeparated(const std::string s, Array<std::string>& array, bool st
if (stripQuotes) {
for (int i = 0; i < array.length(); ++i) {
std::string& t = array[i];
int L = t.length();
size_t L = t.length();
if ((L > 1) && (t[0] == quote) && (t[L - 1] == quote)) {
if ((L > 6) && (t[1] == quote) && (t[2] == quote) && (t[L - 3] == quote) && (t[L - 2] == quote)) {
// Triple-quote
@@ -86,15 +94,44 @@ bool beginsWith(
}
}
std::string replace(const std::string& s, const std::string& pattern, const std::string& replacement) {
if (pattern.length() == 0) {
return s;
}
std::string temp = "";
size_t lastindex = 0;
size_t nextindex = 0;
do {
nextindex = s.find(pattern, lastindex);
if (nextindex == std::string::npos) {
break;
}
temp += s.substr(lastindex, nextindex - lastindex) + replacement;
lastindex = nextindex + pattern.length();
} while (lastindex + pattern.length() <= s.length());
return temp + (lastindex < s.length() ? s.substr(lastindex) : "");
}
bool isValidIdentifier(const std::string& s) {
if (s.length() > 0 && (isLetter(s[0]) || s[0] == '_')) {
for (size_t i = 1; i < s.length() ; ++i) {
if (!( isLetter(s[i]) || (s[i] == '_') || isDigit(s[i]) )) {
return false;
}
}
return true;
}
return false;
}
bool endsWith(
const std::string& test,
const std::string& pattern) {
if (test.size() >= pattern.size()) {
int te = test.size() - 1;
int pe = pattern.size() - 1;
for (int i = pattern.size() - 1; i >= 0; --i) {
size_t te = test.size() - 1;
size_t pe = pattern.size() - 1;
for (int i = (int)pattern.size() - 1; i >= 0; --i) {
if (pattern[pe - i] != test[te - i]) {
return false;
}
@@ -151,7 +188,7 @@ std::string wordWrap(
if (c < input.size()) {
// Collapse multiple spaces.
while ((input[c] == ' ') && (c < input.size())) {
c++;
++c;
}
}
}
@@ -248,9 +285,11 @@ std::string stringJoin(
}
std::string trimWhitespace(
const std::string& s) {
std::string trimWhitespace(const std::string& s) {
if (s.length() == 0) {
return s;
}
size_t left = 0;
// Trim from left
@@ -258,15 +297,16 @@ std::string trimWhitespace(
++left;
}
int right = s.length() - 1;
size_t right = s.length() - 1;
// Trim from right
while ((right > (int)left) && iswspace(s[right])) {
while ((right > left) && iswspace(s[right])) {
--right;
}
return s.substr(left, right - left + 1);
}
}; // namespace
#undef NEWLINE