Rewrote the comments in the libraries under 'includes' in English (excluding those inside folders)
This commit is contained in:
@@ -2,7 +2,7 @@ from stdint import *
|
||||
import t, c
|
||||
|
||||
|
||||
# 字符串复制函数
|
||||
# String copy function
|
||||
def strcpy(dest: str, src: str) -> str:
|
||||
if dest == None or src == None: return None
|
||||
original_dest: str = dest
|
||||
@@ -13,14 +13,14 @@ def strcpy(dest: str, src: str) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 字符串拼接函数: 将 src 追加到 dest 末尾
|
||||
# String concatenate function
|
||||
def strcat(dest: str, src: str) -> str:
|
||||
if dest == None or src == None: return dest
|
||||
original_dest: str = dest
|
||||
# 找到 dest 末尾
|
||||
# Find end of dest
|
||||
while dest[0] != '\0':
|
||||
dest += 1
|
||||
# 复制 src
|
||||
# Copy src
|
||||
for s in src:
|
||||
dest[0] = s
|
||||
dest += 1
|
||||
@@ -28,7 +28,7 @@ def strcat(dest: str, src: str) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 有限长度字符串复制函数
|
||||
# String copy function with limited length
|
||||
def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
if dest == None or src == None or n == 0: return dest
|
||||
original_dest: str = dest
|
||||
@@ -38,7 +38,7 @@ def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
dest[0] = s
|
||||
dest += 1
|
||||
i += 1
|
||||
# 填充剩余空间为 '\0'(只填充 n-i 个,避免缓冲区溢出)
|
||||
# Fill remaining space with '\0'
|
||||
while i < n:
|
||||
dest[0] = 0
|
||||
dest += 1
|
||||
@@ -46,14 +46,14 @@ def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
return original_dest
|
||||
|
||||
|
||||
# 字符串长度函数
|
||||
# String length function
|
||||
def strlen(src: str) -> t.CSizeT | t.CExport:
|
||||
length: t.CSizeT = 0
|
||||
for _ in src:
|
||||
length += 1
|
||||
return length
|
||||
|
||||
# 字符串比较函数
|
||||
# String comparison function
|
||||
def strcmp(str1: str, str2: str) -> t.CInt:
|
||||
while str1[0] != '\0' and str2[0] != '\0':
|
||||
if str1[0] != str2[0]:
|
||||
@@ -66,7 +66,7 @@ def samestr(str1: str, str2: str) -> bool:
|
||||
return str1 == str2
|
||||
|
||||
|
||||
# 有限长度字符串比较函数
|
||||
# String compare function with limited length
|
||||
def strncmp(str1: str, str2: str, n: t.CSizeT) -> t.CInt:
|
||||
i: t.CSizeT = 0
|
||||
while str1[0] != '\0' and str2[0] != '\0' and i < n:
|
||||
@@ -80,7 +80,7 @@ def strncmp(str1: str, str2: str, n: t.CSizeT) -> t.CInt:
|
||||
return 0
|
||||
|
||||
|
||||
# 内存比较函数
|
||||
# Memory compare function
|
||||
def memcmp(ptr1: t.CVoid | t.CPtr, ptr2: t.CVoid | t.CPtr, n: t.CSizeT) -> t.CInt:
|
||||
p1: BYTEPTR = BYTEPTR(ptr1)
|
||||
p2: BYTEPTR = BYTEPTR(ptr2)
|
||||
@@ -92,7 +92,7 @@ def memcmp(ptr1: t.CVoid | t.CPtr, ptr2: t.CVoid | t.CPtr, n: t.CSizeT) -> t.CIn
|
||||
return 0
|
||||
|
||||
|
||||
# 字符串查找函数
|
||||
# String find function
|
||||
def strchr(s: str, cr: t.CInt) -> str:
|
||||
while s[0] != '\0':
|
||||
if s[0] == t.CChar(cr):
|
||||
@@ -102,7 +102,7 @@ def strchr(s: str, cr: t.CInt) -> str:
|
||||
return str(s)
|
||||
return None
|
||||
|
||||
# 字符串反向查找函数(找最后一次出现的字符)
|
||||
# String reverse find function (find last occurrence of character)
|
||||
def strrchr(s: str, cr: t.CInt) -> str:
|
||||
last: str = None
|
||||
while s[0] != '\0':
|
||||
@@ -113,7 +113,7 @@ def strrchr(s: str, cr: t.CInt) -> str:
|
||||
return last
|
||||
|
||||
|
||||
# 子串查找函数(在 s 中查找 needle 第一次出现的位置,返回指向该位置的指针,未找到返回 None)
|
||||
# Substring search function (find first occurrence of needle in s, return pointer to that position, or None if not found)
|
||||
def strstr(s: str, needle: str) -> str:
|
||||
if needle[0] == 0:
|
||||
return s
|
||||
@@ -128,7 +128,7 @@ def strstr(s: str, needle: str) -> str:
|
||||
i += 1
|
||||
return None
|
||||
|
||||
# 跳过字符
|
||||
# String skip function
|
||||
def strspn(s: str, skip: str = " ") -> int:
|
||||
si: int = 0
|
||||
while s[si] != 0:
|
||||
@@ -144,9 +144,9 @@ def strspn(s: str, skip: str = " ") -> int:
|
||||
si += 1
|
||||
return si
|
||||
|
||||
# 内存设置函数
|
||||
# Memory set function
|
||||
def memset(ptr: t.CVoid | t.CPtr, value: t.CInt, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# p: BYTEPTR = BYTEPTR(ptr)
|
||||
# i: t.CSizeT
|
||||
# for i in range(num):
|
||||
@@ -162,7 +162,7 @@ def memset(ptr: t.CVoid | t.CPtr, value: t.CInt, num: t.CSizeT) -> t.CVoid | t.C
|
||||
|
||||
|
||||
def memset32(ptr: t.CVoid | t.CPtr, value: t.CUInt32T, count: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# p: UINT32PTR = UINT32PTR(ptr)
|
||||
# i: t.CSizeT
|
||||
# for i in range(count):
|
||||
@@ -177,9 +177,9 @@ def memset32(ptr: t.CVoid | t.CPtr, value: t.CUInt32T, count: t.CSizeT) -> t.CVo
|
||||
return ptr
|
||||
|
||||
|
||||
# 内存复制函数
|
||||
# Memory copy function
|
||||
def memcpy(dest: t.CVoid | t.CPtr, src: t.CVoid | t.CPtr, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
# 原始实现:
|
||||
# Original implementation:
|
||||
# d: BYTEPTR = BYTEPTR(dest)
|
||||
# s: BYTEPTR = BYTEPTR(src)
|
||||
# i: t.CSizeT
|
||||
|
||||
Reference in New Issue
Block a user