Skip to content

Commit

Permalink
Making changes to string utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Dec 12, 2023
1 parent ae9657f commit 301adcd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macosx-clang-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: lukka/[email protected]
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3'
vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7'

- name: run build
uses: lukka/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-gcc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: lukka/[email protected]
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3'
vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7'

- name: run build
uses: lukka/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-msvc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: lukka/[email protected]
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3'
vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7'

- name: run build
uses: lukka/[email protected]
Expand Down
10 changes: 8 additions & 2 deletions seika/utils/se_string_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ void se_strcpy(char* destination, const char* source) {
strcpy(destination, source);
}

void se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount) {
bool se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount) {
#if defined(WIN32) || defined(WIN64)
strncpy_s(destination, sizeInBytes, source, maxCount);
if (strncpy_s(destination, sizeInBytes, source, maxCount) != 0) {
return false;
}
#else
strncpy(destination, source, maxCount);
if (maxCount > 0) {
destination[maxCount - 1] = '\0';
}
#endif
return true;
}

void se_strcat(char* destination, const char* source) {
Expand Down
2 changes: 1 addition & 1 deletion seika/utils/se_string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ char* se_strdup(const char* string);
// Copies string from a void pointer and allocated new memory
char* se_strdup_from_memory(void* data, size_t size);
void se_strcpy(char* destination, const char* source);
void se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount);
bool se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount);
void se_strcat(char* destination, const char* source);
void se_strncat(char* destination, const char* source, size_t sizeInBytes);
const char* se_bool_to_string(bool value);
Expand Down
11 changes: 11 additions & 0 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ void seika_string_utils_test(void) {
// Test string dup
char* filePath = se_strdup("project.cscn");
TEST_ASSERT_EQUAL_STRING("project.cscn", filePath);
// Test string copy funcs
char stringTestBuffer[256];
se_strcpy(stringTestBuffer, "test");
TEST_ASSERT_EQUAL_STRING("test", stringTestBuffer);
se_strncpy(stringTestBuffer, sizeof(stringTestBuffer), "other test", 5);
TEST_ASSERT_EQUAL_STRING("other", stringTestBuffer);
// Test string cat funcs
se_strcat(stringTestBuffer, " message");
TEST_ASSERT_EQUAL_STRING("other message", stringTestBuffer);
se_strncat(stringTestBuffer, " okay", sizeof(char) * 3);
TEST_ASSERT_EQUAL_STRING("other message ok", stringTestBuffer);
// Test trim
char* filePathWithoutExtension = se_str_trim(filePath, '.');
TEST_ASSERT_EQUAL_STRING("project", filePathWithoutExtension);
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"version>=": "2.12.1"
}
],
"builtin-baseline": "91393faf123c4f1d22ef3dbfb4ec03531bac907a"
"builtin-baseline": "efca044b75fbf481d6650ce4d3b223d8af94f7a7"
}

0 comments on commit 301adcd

Please sign in to comment.