2011-10-02 10:05:45 +00:00
|
|
|
#ifdef NALL_STRING_INTERNAL_HPP
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2013-05-05 09:21:30 +00:00
|
|
|
string substr(rstring source, unsigned offset, unsigned length) {
|
|
|
|
string result;
|
|
|
|
if(length == ~0u) length = source.size() - offset;
|
|
|
|
result.resize(length);
|
|
|
|
memcpy(result.data(), source.data() + offset, length);
|
|
|
|
return result;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
string sha256(const uint8_t* data, unsigned size) {
|
2011-07-07 12:59:26 +00:00
|
|
|
sha256_ctx sha;
|
|
|
|
uint8_t hash[32];
|
|
|
|
sha256_init(&sha);
|
|
|
|
sha256_chunk(&sha, data, size);
|
|
|
|
sha256_final(&sha);
|
|
|
|
sha256_hash(&sha, hash);
|
|
|
|
string result;
|
2013-05-05 09:21:30 +00:00
|
|
|
for(auto& byte : hash) result.append(hex<2>(byte));
|
2011-07-07 12:59:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-05 09:21:30 +00:00
|
|
|
bool tokenize(lstring& list, const char* s, const char* p) {
|
|
|
|
while(*s) {
|
|
|
|
if(*p == '*') {
|
|
|
|
const char* b = s;
|
|
|
|
while(*s) {
|
|
|
|
if(tokenize(list, s++, p + 1)) {
|
|
|
|
list.prepend(substr(b, 0, --s - b));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list.prepend(b);
|
|
|
|
return !*++p;
|
|
|
|
}
|
|
|
|
if(*s++ != *p++) return false;
|
|
|
|
}
|
|
|
|
while(*p == '*') { list.prepend(s); p++; }
|
|
|
|
return !*p;
|
|
|
|
}
|
2011-10-24 11:35:34 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
char* integer(char* result, intmax_t value) {
|
2011-10-24 11:35:34 +00:00
|
|
|
bool negative = value < 0;
|
|
|
|
if(negative) value = -value;
|
|
|
|
|
|
|
|
char buffer[64];
|
|
|
|
unsigned size = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unsigned n = value % 10;
|
|
|
|
buffer[size++] = '0' + n;
|
|
|
|
value /= 10;
|
|
|
|
} while(value);
|
2013-01-05 09:19:04 +00:00
|
|
|
if(negative) buffer[size++] = '-';
|
|
|
|
//buffer[size++] = negative ? '-' : '+';
|
2011-10-24 11:35:34 +00:00
|
|
|
|
|
|
|
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
|
|
|
|
result[size] = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
char* decimal(char* result, uintmax_t value) {
|
2011-10-24 11:35:34 +00:00
|
|
|
char buffer[64];
|
|
|
|
unsigned size = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unsigned n = value % 10;
|
|
|
|
buffer[size++] = '0' + n;
|
|
|
|
value /= 10;
|
|
|
|
} while(value);
|
|
|
|
|
|
|
|
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
|
|
|
|
result[size] = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
//using sprintf is certainly not the most ideal method to convert
|
|
|
|
//a double to a string ... but attempting to parse a double by
|
|
|
|
//hand, digit-by-digit, results in subtle rounding errors.
|
2013-07-29 09:42:45 +00:00
|
|
|
unsigned real(char* str, long double value) {
|
2010-08-09 13:28:56 +00:00
|
|
|
char buffer[256];
|
Update to v084r03 release.
(r02 was not posted to the WIP thread)
byuu says:
Internally, all color is processed with 30-bit precision. The filters
also operate at 30-bit depth.
There's a new config file setting, video.depth, which defaults to 24.
This causes the final output to downsample to 24-bit, as most will
require.
If you set it to 30-bit, the downsampling will not occur, and bsnes will
ask ruby for a 30-bit surface. If you don't have one available, you're
going to get bad colors. Or maybe even a crash with OpenGL.
I don't yet have detection code to make sure you have an appropriate
visual in place.
30-bit mode will really only work if you are running Linux, running Xorg
at Depth 30, use the OpenGL or XShm driver, have an nVidia Quadro or AMD
FireGL card with the official drivers, and have a 30-bit capable
monitor.
Lots of planning and work for very little gain here, but it's nice that
it's finally finished.
Oh, I had to change the contrast/brightness formulas a tiny bit, but
they still work and look nice.
2011-12-03 03:22:54 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
//Windows C-runtime does not support long double via sprintf()
|
|
|
|
sprintf(buffer, "%f", (double)value);
|
|
|
|
#else
|
|
|
|
sprintf(buffer, "%Lf", value);
|
|
|
|
#endif
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//remove excess 0's in fraction (2.500000 -> 2.5)
|
2013-05-02 11:25:45 +00:00
|
|
|
for(char* p = buffer; *p; p++) {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(*p == '.') {
|
2013-05-02 11:25:45 +00:00
|
|
|
char* p = buffer + strlen(buffer) - 1;
|
2010-08-09 13:28:56 +00:00
|
|
|
while(*p == '0') {
|
|
|
|
if(*(p - 1) != '.') *p = 0; //... but not for eg 1.0 -> 1.
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned length = strlen(buffer);
|
|
|
|
if(str) strcpy(str, buffer);
|
|
|
|
return length + 1;
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
string real(long double value) {
|
2010-08-09 13:28:56 +00:00
|
|
|
string temp;
|
2013-07-29 09:42:45 +00:00
|
|
|
temp.resize(real(nullptr, value));
|
|
|
|
real(temp.data(), value);
|
2010-08-09 13:28:56 +00:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|