-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rcore] Fix GetFileNameWithoutExt()
#3771
Conversation
fix [rcore] GetFileNameWithoutExt
GetFileNameWithoutExt()
Not entirely related to the PR but this is one of the (many) operations that becomes so much easier if you stop using null-terminated strings #define s8(s) (s8) { (unsigned char*) s, (ptrdiff_t) sizeof(s)-1 }
typedef struct
{
unsigned char* str;
ptrdiff_t len;
} s8;
s8 GetExtensionlessFilename(s8 fileName)
{
s8 ret = fileName;
for (ptrdiff_t i = ret.len-1; i >= 0; --i)
{
--ret.len;
if (ret.str[i] == '.') return ret;
}
return fileName;
} You can eliminate the need to copy the string (and therefore skip the hardcoded size static buffer), and also the O(n) useless strlen call. It's only an issue if you need to pass the string later on to something that expects null-terminated, which is unfortunately common. (not suggesting or implying raylib should change its string convention - just wanted to "spread awareness" I guess) |
It's fix thank for help Peter0x44 and raysan5 |
@oblerion thank you very much for the review! |
* Update rtext.c * Add gamepad support to PLATFORM_DESKTOP_SDL (#3776) Co-authored-by: Arthur <hi@thenightwat.ch> * [rcore] Fix `GetFileNameWithoutExt()` (#3771) * Update rcore.c fix [rcore] GetFileNameWithoutExt * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Update rcore.c * Review formating and some defines naming consistency * Added viewport independent raycast (#3709) * added viewport independent raycast * Renamed GetMouseRayEx to GetViewRay * Update raylib_api.* by CI * REVIEWED: `rlLoadFramebuffer()`, parameters not required * Reorder functions * Update raylib_api.* by CI * Update rtext.c (#3777) (#3779) * REVIEWED: `rlLoadFramebuffer()` --------- Co-authored-by: A <kirk25000@gmail.com> Co-authored-by: Arthur <hi@thenightwat.ch> Co-authored-by: oblerion <82583559+oblerion@users.noreply.github.com> Co-authored-by: Luís Almeida <60551627+luis605@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
[with fix]
Use reverse search '.' for remove extension.