1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <cassert>
#include <string>
#include "Util.h"
#include "IncExternAI.h"
namespace AIUtil {
std::string GetAbsFileName(IAICallback* icb, const std::string& relFileName) {
char dst[2048] = {0};
const char* src = relFileName.c_str();
const int len = relFileName.size();
// last char ('\0') in dst
// should not be overwritten
assert(len < (2048 - 1));
memcpy(dst, src, len);
// get the absolute path to the file
// (and create folders along the way)
icb->GetValue(AIVAL_LOCATE_FILE_W, dst);
return (std::string(dst));
}
bool IsFSGoodChar(const char c) {
if ((c >= '0') && (c <= '9')) {
return true;
} else if ((c >= 'a') && (c <= 'z')) {
return true;
} else if ((c >= 'A') && (c <= 'Z')) {
return true;
} else if ((c == '.') || (c == '_') || (c == '-')) {
return true;
}
return false;
}
std::string MakeFileSystemCompatible(const std::string& str) {
std::string cleaned = str;
for (std::string::size_type i=0; i < cleaned.size(); i++) {
if (!IsFSGoodChar(cleaned[i])) {
cleaned[i] = '_';
}
}
return cleaned;
}
void StringToLowerInPlace(std::string& s) {
std::transform(s.begin(), s.end(), s.begin(), (int (*)(int))tolower);
}
std::string StringToLower(std::string s) {
StringToLowerInPlace(s);
return s;
}
}
|