-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
107 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "util.h" | ||
|
||
void RemoveFileExtension(std::string& filePath) | ||
{ | ||
// Find the last occurrence of '.' | ||
size_t lastDotPosition = filePath.find_last_of("."); | ||
|
||
// Check if the dot is part of a directory component rather than an extension | ||
size_t lastPathSeparator = filePath.find_last_of("/\\"); | ||
|
||
if (lastDotPosition != std::string::npos) { | ||
// Ensure the dot is after the last path separator | ||
if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { | ||
return; // Dot is part of a directory name, not an extension | ||
} | ||
// Return the substring from the beginning to the dot | ||
filePath = filePath.substr(0, lastDotPosition); | ||
} | ||
|
||
// No extension found, return the original path | ||
} | ||
|
||
void COM_FixSlashes(char* pname) | ||
{ | ||
#ifdef _WIN32 | ||
while (*pname) { | ||
if (*pname == '/') | ||
*pname = '\\'; | ||
pname++; | ||
} | ||
#else | ||
while (*pname) { | ||
if (*pname == '\\') | ||
*pname = '/'; | ||
pname++; | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <string> | ||
|
||
void RemoveFileExtension(std::string& filePath); | ||
void COM_FixSlashes(char* pname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "util.h" | ||
|
||
std::string TrimString(const std::string& str) | ||
{ | ||
size_t first = str.find_first_not_of(" \t\n\r\f\v"); | ||
size_t last = str.find_last_not_of(" \t\n\r\f\v"); | ||
|
||
if (first == std::string::npos || last == std::string::npos) | ||
return ""; | ||
|
||
return str.substr(first, (last - first + 1)); | ||
} | ||
|
||
void RemoveFileExtension(std::string& filePath) | ||
{ | ||
// Find the last occurrence of '.' | ||
size_t lastDotPosition = filePath.find_last_of("."); | ||
|
||
// Check if the dot is part of a directory component rather than an extension | ||
size_t lastPathSeparator = filePath.find_last_of("/\\"); | ||
|
||
if (lastDotPosition != std::string::npos) { | ||
// Ensure the dot is after the last path separator | ||
if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { | ||
return; // Dot is part of a directory name, not an extension | ||
} | ||
// Return the substring from the beginning to the dot | ||
filePath = filePath.substr(0, lastDotPosition); | ||
} | ||
|
||
// No extension found, return the original path | ||
} | ||
|
||
void COM_FixSlashes(char* pname) | ||
{ | ||
#ifdef _WIN32 | ||
while (*pname) { | ||
if (*pname == '/') | ||
*pname = '\\'; | ||
pname++; | ||
} | ||
#else | ||
while (*pname) { | ||
if (*pname == '\\') | ||
*pname = '/'; | ||
pname++; | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <string> | ||
|
||
std::string TrimString(const std::string& str); | ||
void RemoveFileExtension(std::string& filePath); | ||
void COM_FixSlashes(char* pname); |