Skip to content

Commit 1ea61a7

Browse files
committed
ResourceEmbedder: Fix special chars (+-*/=!...) in names
1 parent 740a0e3 commit 1ea61a7

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

ResourceEmbedder/ResourceEmbedder.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ std::vector<std::string> split(const std::string& s, char seperator)
4949
return output;
5050
}
5151

52+
void ReplaceSpecialsChars(std::string& sString)
53+
{
54+
ReplaceAll(sString, ".", "_");
55+
ReplaceAll(sString, " ", "_");
56+
ReplaceAll(sString, "-", "_");
57+
ReplaceAll(sString, "+", "_");
58+
ReplaceAll(sString, "*", "_");
59+
ReplaceAll(sString, "/", "_");
60+
ReplaceAll(sString, "%", "_");
61+
ReplaceAll(sString, "<", "_");
62+
ReplaceAll(sString, ">", "_");
63+
ReplaceAll(sString, "&", "_");
64+
ReplaceAll(sString, "!", "_");
65+
ReplaceAll(sString, "=", "_");
66+
ReplaceAll(sString, "(", "_");
67+
ReplaceAll(sString, ")", "_");
68+
ReplaceAll(sString, "[", "_");
69+
ReplaceAll(sString, "]", "_");
70+
}
71+
5272
void PrintRow(FILE* dst, const unsigned char* buf, unsigned count)
5373
{
5474
fprintf(dst, "\n ");
@@ -94,7 +114,7 @@ void ExportFile(const char* pName, const char* pInputFilename, const char* pOutp
94114
{
95115
char* pCompressed = (char*)malloc(iCompressBound);
96116
iCompressedSize = LZ4_compress_default(pData, pCompressed, iOriginSize, iCompressBound);
97-
117+
98118
if (iCompressedSize >= iOriginSize)
99119
{
100120
printf("Useless compression for this file\n");
@@ -173,24 +193,24 @@ void ExportFile(const char* pName, const char* pInputFilename, const char* pOutp
173193
std::string sIndent(iIndent, '\t');
174194
std::string sIndentP(iIndent + 1, '\t');
175195
std::string sIndentPP(iIndent + 2, '\t');
176-
196+
177197

178198
std::string sName = pName;
179-
ReplaceAll(sName, ".", "_");
180-
ReplaceAll(sName, " ", "_");
199+
ReplaceSpecialsChars(sName);
181200

182201
std::string sDefine = "__RESOURCES_";
183202
if (NULL != pRelativePath)
184203
{
185-
sDefine += pRelativePath;
204+
std::string sRelativePath;
205+
ReplaceSpecialsChars(sRelativePath);
206+
207+
sDefine += sRelativePath;
186208
sDefine += "_";
187209
}
188210
sDefine += sName;
189211
sDefine += "_H__";
190212
std::transform(sDefine.begin(), sDefine.end(), sDefine.begin(), ::toupper);
191-
ReplaceAll(sDefine, ".", "_");
192-
ReplaceAll(sDefine, " ", "_");
193-
ReplaceAll(sDefine, "/", "_");
213+
ReplaceSpecialsChars(sDefine);
194214

195215
fprintf(pHeaderFile, "#ifndef %s\n", sDefine.c_str());
196216
fprintf(pHeaderFile, "#define %s\n\n", sDefine.c_str());
@@ -200,8 +220,7 @@ void ExportFile(const char* pName, const char* pInputFilename, const char* pOutp
200220
for (size_t iNamespace = 0; iNamespace < oNamespaces.size(); ++iNamespace)
201221
{
202222
std::string sNamespace = oNamespaces[iNamespace];
203-
ReplaceAll(sDefine, ".", "_");
204-
ReplaceAll(sDefine, " ", "_");
223+
ReplaceSpecialsChars(sNamespace);
205224
std::string sNamespaceIndent(iNamespace, '\t');
206225
fprintf(pHeaderFile, "%snamespace %s \n%s{\n", sNamespaceIndent.c_str(), sNamespace.c_str(), sNamespaceIndent.c_str());
207226
fprintf(pSourceFile, "%snamespace %s \n%s{\n", sNamespaceIndent.c_str(), sNamespace.c_str(), sNamespaceIndent.c_str());
@@ -253,7 +272,7 @@ void ExportFile(const char* pName, const char* pInputFilename, const char* pOutp
253272
if (iPos < (iSize - 1))
254273
fprintf(pSourceFile, ",");
255274
}
256-
275+
257276
fprintf(pSourceFile, "\n%s};\n", sIndentP.c_str());
258277

259278
//Closing namespaces
@@ -319,8 +338,7 @@ void ScanFolder(const char* pInputFolder, const char* pOutputFolderBase, const c
319338
}
320339
sOutPath += "/";
321340
std::string sName = file.name;
322-
ReplaceAll(sName, ".", "_");
323-
ReplaceAll(sName, " ", "_");
341+
ReplaceSpecialsChars(sName);
324342
sOutPath += sName;
325343

326344
ExportFile(file.name, file.path, sOutPath.c_str(), pOutputRelative, eCompressMode);
@@ -379,7 +397,7 @@ void main(int argn, char** argv)
379397
printf("Invalid argument");
380398
return;
381399
}
382-
400+
383401
++iArg;
384402
}
385403

0 commit comments

Comments
 (0)