Replace ad-hoc implementations of Basename with calls to it.
This commit is contained in:
parent
f2f37aeed8
commit
dbf66639aa
@ -822,8 +822,7 @@ void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string mtlBasename = mtlFilename.substr(mtlFilename.rfind(PATH_SEP) + 1);
|
||||
fprintf(f, "mtllib %s\n", mtlBasename.c_str());
|
||||
fprintf(f, "mtllib %s\n", Basename(mtlFilename).c_str());
|
||||
ExportMeshAsObjTo(f, fMtl, m);
|
||||
|
||||
fclose(fMtl);
|
||||
@ -987,24 +986,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
||||
double largerBoundXY = max((bndh.x - bndl.x), (bndh.y - bndl.y));
|
||||
double largerBoundZ = max(largerBoundXY, (bndh.z - bndl.z + 1));
|
||||
|
||||
std::string extension = filename,
|
||||
noExtFilename = filename;
|
||||
size_t dot = noExtFilename.rfind('.');
|
||||
extension.erase(0, dot + 1);
|
||||
noExtFilename.erase(dot);
|
||||
|
||||
std::string baseFilename = noExtFilename;
|
||||
size_t lastSlash = baseFilename.rfind(PATH_SEP);
|
||||
ssassert(lastSlash != std::string::npos, "Expected at least one path separator");
|
||||
baseFilename.erase(0, lastSlash + 1);
|
||||
|
||||
for(size_t i = 0; i < baseFilename.length(); i++) {
|
||||
if(!isalpha(baseFilename[i]) &&
|
||||
/* also permit UTF-8 */ !((unsigned char)baseFilename[i] >= 0x80))
|
||||
baseFilename[i] = '_';
|
||||
std::string basename = Basename(filename, /*stripExtension=*/true);
|
||||
for(size_t i = 0; i < basename.length(); i++) {
|
||||
if(!(isalnum(basename[i]) || ((unsigned)basename[i] >= 0x80))) {
|
||||
basename[i] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
if(extension == "html") {
|
||||
if(FilenameHasExtension(filename, "html")) {
|
||||
fprintf(f, htmlbegin,
|
||||
LoadStringFromGzip("threejs/three-r76.js.gz").c_str(),
|
||||
LoadStringFromGzip("threejs/hammer-2.0.8.js.gz").c_str(),
|
||||
@ -1015,7 +1004,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
||||
" bounds: {\n"
|
||||
" x: %f, y: %f, near: %f, far: %f, z: %f, edgeBias: %f\n"
|
||||
" },\n",
|
||||
baseFilename.c_str(),
|
||||
basename.c_str(),
|
||||
largerBoundXY,
|
||||
largerBoundXY,
|
||||
1.0,
|
||||
@ -1029,8 +1018,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
||||
|
||||
// Directional.
|
||||
int lightCount;
|
||||
for(lightCount = 0; lightCount < 2; lightCount++)
|
||||
{
|
||||
for(lightCount = 0; lightCount < 2; lightCount++) {
|
||||
fprintf(f, " {\n"
|
||||
" intensity: %f, direction: [%f, %f, %f]\n"
|
||||
" },\n",
|
||||
@ -1101,13 +1089,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
||||
|
||||
fputs(" ]\n};\n", f);
|
||||
|
||||
if(extension == "html")
|
||||
if(FilenameHasExtension(filename, "html")) {
|
||||
fprintf(f, htmlend,
|
||||
baseFilename.c_str(),
|
||||
basename.c_str(),
|
||||
SS.GW.scale,
|
||||
CO(SS.GW.offset),
|
||||
CO(SS.GW.projUp),
|
||||
CO(SS.GW.projRight));
|
||||
}
|
||||
|
||||
spl.Clear();
|
||||
}
|
||||
|
@ -228,37 +228,20 @@ void Group::MenuGroup(Command id) {
|
||||
|
||||
case Command::GROUP_LINK: {
|
||||
g.type = Type::LINKED;
|
||||
g.meshCombine = CombineAs::ASSEMBLE;
|
||||
if(g.linkFile.empty()) {
|
||||
if(!GetOpenFile(&g.linkFile, "", SlvsFileFilter)) return;
|
||||
}
|
||||
|
||||
// Assign the default name of the group based on the name of
|
||||
// the linked file.
|
||||
std::string groupName = g.linkFile;
|
||||
size_t pos;
|
||||
|
||||
pos = groupName.rfind(PATH_SEP);
|
||||
if(pos != std::string::npos)
|
||||
groupName.erase(0, pos + 1);
|
||||
|
||||
pos = groupName.rfind('.');
|
||||
if(pos != std::string::npos)
|
||||
groupName.erase(pos);
|
||||
|
||||
for(size_t i = 0; i < groupName.length(); i++) {
|
||||
if(!(isalnum(groupName[i]) || (unsigned)groupName[i] >= 0x80)) {
|
||||
g.name = Basename(g.linkFile, /*stripExtension=*/true);
|
||||
for(size_t i = 0; i < g.name.length(); i++) {
|
||||
if(!(isalnum(g.name[i]) || (unsigned)g.name[i] >= 0x80)) {
|
||||
// convert punctuation to dashes
|
||||
groupName[i] = '-';
|
||||
g.name[i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
if(groupName.length() > 0) {
|
||||
g.name = groupName;
|
||||
} else {
|
||||
g.name = C_("group-name", "link");
|
||||
}
|
||||
|
||||
g.meshCombine = CombineAs::ASSEMBLE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -127,11 +127,7 @@ double TtfFontList::AspectRatio(const std::string &font, const std::string &str)
|
||||
// entities that reference us will store it.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string TtfFont::FontFileBaseName() const {
|
||||
std::string baseName = fontFile;
|
||||
size_t pos = baseName.rfind(PATH_SEP);
|
||||
if(pos != std::string::npos)
|
||||
return baseName.erase(0, pos + 1);
|
||||
return "";
|
||||
return Basename(fontFile);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user