Skip to content

Conversation

@oblerion
Copy link
Contributor

@oblerion oblerion commented Feb 1, 2024

puts( GetFileNameWithoutExt("dir/file.name.zip") ); 
// out : "file"

[with fix]

puts( GetFileNameWithoutExt("dir/file.name.zip") );
// out : "file.name"

Use reverse search '.' for remove extension.

@oblerion oblerion marked this pull request as ready for review February 1, 2024 13:19
@oblerion oblerion changed the title fix [rcore] GetFileNameWithoutExt Fix [rcore] GetFileNameWithoutExt Feb 1, 2024
@oblerion oblerion changed the title Fix [rcore] GetFileNameWithoutExt [rcore] Fix GetFileNameWithoutExt Feb 1, 2024
@raysan5 raysan5 changed the title [rcore] Fix GetFileNameWithoutExt [rcore] Fix GetFileNameWithoutExt() Feb 1, 2024
@Peter0x44
Copy link
Contributor

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)

@oblerion
Copy link
Contributor Author

oblerion commented Feb 3, 2024

It's fix thank for help Peter0x44 and raysan5

@oblerion oblerion requested a review from raysan5 February 3, 2024 19:08
@raysan5 raysan5 merged commit d91e910 into raysan5:master Feb 4, 2024
@raysan5
Copy link
Owner

raysan5 commented Feb 4, 2024

@oblerion thank you very much for the review!

raysan5 added a commit that referenced this pull request Feb 4, 2024
* Update rtext.c

* Add gamepad support to PLATFORM_DESKTOP_SDL (#3776)

Co-authored-by: Arthur <[email protected]>

* [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 <[email protected]>
Co-authored-by: Arthur <[email protected]>
Co-authored-by: oblerion <[email protected]>
Co-authored-by: Luís Almeida <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants