Differential D2399 Diff 14390 ps/trunk/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.hpp
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.hpp
/* | /* | ||||
Copyright (C) 2005-2007 Feeling Software Inc. | Copyright (C) 2005-2007 Feeling Software Inc. | ||||
Portions of the code are: | Portions of the code are: | ||||
Copyright (C) 2005-2007 Sony Computer Entertainment America | Copyright (C) 2005-2007 Sony Computer Entertainment America | ||||
MIT License: http://www.opensource.org/licenses/mit-license.php | MIT License: https://www.opensource.org/licenses/mit-license.php | ||||
*/ | */ | ||||
/* | /* | ||||
Based on the FS Import classes: | Based on the FS Import classes: | ||||
Copyright (C) 2005-2006 Feeling Software Inc | Copyright (C) 2005-2006 Feeling Software Inc | ||||
Copyright (C) 2005-2006 Autodesk Media Entertainment | Copyright (C) 2005-2006 Autodesk Media Entertainment | ||||
MIT License: http://www.opensource.org/licenses/mit-license.php | MIT License: http://www.opensource.org/licenses/mit-license.php | ||||
*/ | */ | ||||
/* | |||||
musl | |||||
Copyright (C) 2005-2019 Rich Felker, et al. | |||||
https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT | |||||
MIT License: http://www.opensource.org/licenses/mit-license.php | |||||
*/ | |||||
#include <limits> | #include <limits> | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#include <float.h> | #include <float.h> | ||||
#endif | #endif | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#define ecvt _ecvt | #define ecvt _ecvt | ||||
#endif // WIN32 | #elif !HAS_ECVT | ||||
#include <stdio.h> | |||||
char* ecvt(double x, int n, int *dp, int *sign) | |||||
{ | |||||
static char buf[16]; | |||||
char tmp[32]; | |||||
int i, j; | |||||
if (n - 1 > 15) | |||||
n = 15; | |||||
sprintf(tmp, "%.*e", n - 1, x); | |||||
i = *sign = (tmp[0] == '-'); | |||||
for (j = 0; tmp[i] != 'e'; j += (tmp[i++] != '.')) | |||||
buf[j] = tmp[i]; | |||||
buf[j] = 0; | |||||
*dp = atoi(tmp + i + 1) + 1; | |||||
return buf; | |||||
} | |||||
#endif | |||||
#ifndef SAFE_DELETE_ARRAY | #ifndef SAFE_DELETE_ARRAY | ||||
#define SAFE_DELETE_ARRAY(ptr) if (ptr != NULL) { delete [] ptr; ptr = NULL; } | #define SAFE_DELETE_ARRAY(ptr) { delete [] ptr; ptr = NULL; } | ||||
#endif | #endif | ||||
template <class Char, class FloatType> | template <class Char, class FloatType> | ||||
void FloatToString(FloatType f, Char* sz) | void FloatToString(FloatType f, Char* sz) | ||||
{ | { | ||||
Char* buffer = sz + 1; | Char* buffer = sz + 1; | ||||
static const int digitCount = 6; | static const int digitCount = 6; | ||||
int decimal, sign; | int decimal, sign; | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
template <class Char> | template <class Char> | ||||
FUStringBuilderT<Char>::FUStringBuilderT(const String& sz) | FUStringBuilderT<Char>::FUStringBuilderT(const String& sz) | ||||
{ | { | ||||
this->buffer = NULL; | this->buffer = NULL; | ||||
this->size = 0; | this->size = 0; | ||||
this->reserved = 0; | this->reserved = 0; | ||||
reserve(sz.size() + 32); | reserve(sz.size() + 32); | ||||
append(sz.c_str()); | append(sz.c_str()); | ||||
} | } | ||||
template <class Char> | template <class Char> | ||||
FUStringBuilderT<Char>::FUStringBuilderT(const Char* sz) | FUStringBuilderT<Char>::FUStringBuilderT(const Char* sz) | ||||
{ | { | ||||
this->buffer = NULL; | this->buffer = NULL; | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
template <class Char> | template <class Char> | ||||
void FUStringBuilderT<Char>::append(const FMVector3& v) | void FUStringBuilderT<Char>::append(const FMVector3& v) | ||||
{ | { | ||||
if (!empty() && (back() != (Char) ' ' || back() != (Char) '\t' || back() != (Char) '\n' || back() != (Char) '\r')) | if (!empty() && (back() != (Char) ' ' || back() != (Char) '\t' || back() != (Char) '\n' || back() != (Char) '\r')) | ||||
{ | { | ||||
append((Char)' '); | append((Char)' '); | ||||
} | } | ||||
append(v.x); append((Char)' '); append(v.y); append((Char)' '); append(v.z); | append(v.x); append((Char)' '); append(v.y); append((Char)' '); append(v.z); | ||||
} | } | ||||
template <class Char> | template <class Char> | ||||
void FUStringBuilderT<Char>::append(const FMVector4& v) | void FUStringBuilderT<Char>::append(const FMVector4& v) | ||||
{ | { | ||||
if (!empty() && (back() != (Char) ' ' || back() != (Char) '\t' || back() != (Char) '\n' || back() != (Char) '\r')) | if (!empty() && (back() != (Char) ' ' || back() != (Char) '\t' || back() != (Char) '\n' || back() != (Char) '\r')) | ||||
{ | { | ||||
append((Char)' '); | append((Char)' '); | ||||
} | } | ||||
append(v.x); append((Char)' '); append(v.y); append((Char)' '); append(v.z); append((Char)' '); append(v.w); | append(v.x); append((Char)' '); append(v.y); append((Char)' '); append(v.z); append((Char)' '); append(v.w); | ||||
} | } | ||||
template <class Char> | template <class Char> | ||||
void FUStringBuilderT<Char>::appendLine(const Char* sz) | void FUStringBuilderT<Char>::appendLine(const Char* sz) | ||||
{ | { | ||||
append(sz); | append(sz); | ||||
append((Char)'\n'); | append((Char)'\n'); | ||||
} | } | ||||
Show All 25 Lines | if ((int32)size >= end && start >= 0 && diff > 0) | ||||
for (Char* p = buffer + start; p != stop; ++p) | for (Char* p = buffer + start; p != stop; ++p) | ||||
{ | { | ||||
*p = *(p + diff); | *p = *(p + diff); | ||||
} | } | ||||
size -= diff; | size -= diff; | ||||
} | } | ||||
} | } | ||||
template <class Char> | template <class Char> | ||||
const Char* FUStringBuilderT<Char>::ToCharPtr() const | const Char* FUStringBuilderT<Char>::ToCharPtr() const | ||||
{ | { | ||||
FUStringBuilderT<Char>* ncThis = const_cast< FUStringBuilderT<Char>* >(this); | FUStringBuilderT<Char>* ncThis = const_cast< FUStringBuilderT<Char>* >(this); | ||||
if (size + 1 > reserved) ncThis->enlarge(1); | if (size + 1 > reserved) ncThis->enlarge(1); | ||||
ncThis->buffer[size] = 0; | ncThis->buffer[size] = 0; | ||||
return buffer; | return buffer; | ||||
} | } | ||||
Show All 26 Lines |
Wildfire Games · Phabricator