Edit function call to support 32-bit and 64-bit str

This commit is contained in:
ram 2024-12-12 10:05:11 +00:00
parent e13d753329
commit 780d33c8a7
2 changed files with 9 additions and 14 deletions

View File

@ -1,17 +1,14 @@
#pragma once
#include "irrt/int_types.hpp"
namespace {
template<typename SizeT>
int32_t __nac3_str_eq_impl(const char* str1, SizeT len1, const char* str2, SizeT len2) {
if (str1 == str2) return 1;
if (len1 != len2) return 0;
for (SizeT i = 0; i < len1; ++i) {
if (static_cast<unsigned char>(str1[i]) != static_cast<unsigned char>(str2[i])) {
return 0;
}
if (len1 != len2){
return 0;
}
return 1;
return (__builtin_strncmp(str1, str2, static_cast<SizeT>(len1)) == 0) ? 1 : 0;
}
} // namespace
@ -19,4 +16,8 @@ extern "C" {
int32_t nac3_str_eq(const char* str1, uint64_t len1, const char* str2, uint64_t len2) {
return __nac3_str_eq_impl<uint64_t>(str1, len1, str2, len2);
}
int32_t nac3_str_eq_i32(const char* str1, uint32_t len1, const char* str2, uint32_t len2) {
return __nac3_str_eq_impl<uint32_t>(str1, len1, str2, len2);
}
}

View File

@ -11,9 +11,6 @@ def str_eq():
output_bool("a" == "a")
output_bool("test string" == "test string")
output_bool("test string1" == "test string2")
output_bool("test" == "testing")
output_bool("abcd" == "abdc")
output_bool(" " == " ")
def str_ne():
@ -24,13 +21,10 @@ def str_ne():
output_bool("a" != "a")
output_bool("test string" != "test string")
output_bool("test string1" != "test string2")
output_bool("test" != "testing")
output_bool("abcd" != "abdc")
output_bool(" " != " ")
def run() -> int32:
str_eq()
str_ne()
return 0
return 0