1 Star 0 Fork 344

seasky100 / awtk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils_t.md 13.19 KB
一键复制 编辑 原始数据 按行查看 历史
xianjimli 提交于 2020-04-07 09:44 . update idl/docs

utils_t

概述

工具类。

函数

函数名称 说明
tk_atob 将字符串转换为布尔类型。
tk_atof 将字符串转换为浮点类型。
tk_atoi 将字符串转换为整形。
tk_ftoa 将浮点型转换为字符串。
tk_itoa 将整形转换为字符串。
tk_skip_to_num 跳过字符串函数,如:字符串"hello123world",返回的结果是"123world"。
tk_snprintf 将可变参数(...)按照format格式化字符串,并将字符串复制到str中。
tk_sscanf 从字符串读取格式化输入。
tk_str_append 字符串追加函数。
tk_str_cmp 字符串比较函数。
tk_str_icmp 字符串比较函数(不区分大小写)。
tk_str_start_with 检查字符串是否以指定的字符串prefix开头。
tk_str_tolower 将大写字母转换为小写字母。
tk_str_toupper 将小写字母转换为大写字母。
tk_strcpy 将src所指向的字符串复制到dst。
tk_strdup 字符串拷贝函数。
tk_strlen 获取字符串的长度。str为空时返回0。
tk_strncpy 将src所指向的字符串复制到dst,最多复制len个字符串。
tk_strndup 字符串拷贝函数,最多复制len个字符串。
tk_strtol 将字符串转换为长整形。
tk_watob 将宽字符串转换为布尔类型。
tk_watof 将宽字符串转换为浮点类型。
tk_watoi 将宽字符串转换为整形。
tk_wstrdup 宽字符串拷贝函数。

tk_atob 函数


  • 函数功能:

将字符串转换为布尔类型。

  • 函数原型:
bool_t tk_atob (const char* str);
  • 参数说明:
参数 类型 说明
返回值 bool_t 返回转换后的布尔类型。
str const char* 要转换为布尔类型的字符串。

tk_atof 函数


  • 函数功能:

将字符串转换为浮点类型。

  • 函数原型:
double tk_atof (const char* str);
  • 参数说明:
参数 类型 说明
返回值 double 返回转换后的浮点类型。
str const char* 要转换为浮点类型的字符串。

tk_atoi 函数


  • 函数功能:

将字符串转换为整形。

  • 函数原型:
int tk_atoi (const char* str);
  • 参数说明:
参数 类型 说明
返回值 int 返回转换后的整形。
str const char* 要转换为整形的字符串。

tk_ftoa 函数


  • 函数功能:

将浮点型转换为字符串。

  • 函数原型:
const char* tk_ftoa (char* str, int len, double f);
  • 参数说明:
参数 类型 说明
返回值 const char* 返回字符串。
str char* 保存字符串缓冲区。
len int 缓冲区大小。
f double 要转换的浮点型。

tk_itoa 函数


  • 函数功能:

将整形转换为字符串。

  • 函数原型:
const char* tk_itoa (char* str, int len, int n);
  • 参数说明:
参数 类型 说明
返回值 const char* 返回字符串。
str char* 保存字符串缓冲区。
len int 缓冲区大小。
n int 要转换的整形。

tk_skip_to_num 函数


  • 函数功能:

跳过字符串函数,如:字符串"hello123world",返回的结果是"123world"。

  • 函数原型:
const char* tk_skip_to_num (const char* str);
  • 参数说明:
参数 类型 说明
返回值 const char* 返回转换后的字符串。
str const char* 要输入的原始字符串。

tk_snprintf 函数


  • 函数功能:

将可变参数(...)按照format格式化字符串,并将字符串复制到str中。

  • 函数原型:
int tk_snprintf (char* str, size_t size, const char* format);
  • 参数说明:
参数 类型 说明
返回值 int 返回格式化后的字符串长度+1。
str char* 目标字符串。
size size_t 拷贝字节数。
format const char* 格式化字符串。

tk_sscanf 函数


  • 函数功能:

从字符串读取格式化输入。

  • 函数原型:
int tk_sscanf (char* str, const char* format);
  • 参数说明:
参数 类型 说明
返回值 int 返回成功匹配和赋值的个数。
str char* 要输入的字符串。
format const char* 格式化字符串。

tk_str_append 函数


  • 函数功能:

字符串追加函数。

  • 函数原型:
ret_t tk_str_append (char* str, uint32_t max_len, const char* s);
  • 参数说明:
参数 类型 说明
返回值 ret_t 返回RET_OK表示成功,否则表示失败。
str char* 被追加字符串。
max_len uint32_t 字符串的最大长度。
s const char* 要追加的字符串。

tk_str_cmp 函数


  • 函数功能:

字符串比较函数。

  • 函数原型:
int32_t tk_str_cmp (const char* a, const char* b);
  • 参数说明:
参数 类型 说明
返回值 int32_t 如果返回值=-1,则表示a为NULL;如果返回值=1,则表示b为NULL;如果返回值<0,则表示a小于b;如果返回值>0,则表示a大于b;如果返回值=0,则表示a等于b。
a const char* 要进行比较的第一个字符串。
b const char* 要进行比较的第二个字符串。

tk_str_icmp 函数


  • 函数功能:

字符串比较函数(不区分大小写)。

  • 函数原型:
int32_t tk_str_icmp (const char* a, const char* b);
  • 参数说明:
参数 类型 说明
返回值 int32_t 如果返回值=-1,则表示a为NULL;如果返回值=1,则表示b为NULL;如果返回值<0,则表示a小于b;如果返回值>0,则表示a大于b;如果返回值=0,则表示a等于b。
a const char* 要进行比较的第一个字符串。
b const char* 要进行比较的第二个字符串。

tk_str_start_with 函数


  • 函数功能:

检查字符串是否以指定的字符串prefix开头。

  • 函数原型:
bool_t tk_str_start_with (const char* str, const char* prefix);
  • 参数说明:
参数 类型 说明
返回值 bool_t 返回TRUE表示是;否则表示不是。
str const char* 要检查字符串。
prefix const char* 被检查的字符串。

tk_str_tolower 函数


  • 函数功能:

将大写字母转换为小写字母。

  • 函数原型:
char* tk_str_tolower (char* str);
  • 参数说明:
参数 类型 说明
返回值 char* 返回转换后的小写字母字符串。
str char* 要被转换成小写字母的字符串。

tk_str_toupper 函数


  • 函数功能:

将小写字母转换为大写字母。

  • 函数原型:
char* tk_str_toupper (char* str);
  • 参数说明:
参数 类型 说明
返回值 char* 返回转换后的大写字母字符串。
str char* 要被转换成大写字母的字符串。

tk_strcpy 函数


  • 函数功能:

将src所指向的字符串复制到dst。

  • 函数原型:
char* tk_strcpy (char* dst, const char* src);
  • 参数说明:
参数 类型 说明
返回值 char* 返回目标字符串。
dst char* 目标字符串。
src const char* 原字符串。

tk_strdup 函数


  • 函数功能:

字符串拷贝函数。

  • 函数原型:
char* tk_strdup (const char* str);
  • 参数说明:
参数 类型 说明
返回值 char* 返回指向的复制字符串指针,如果失败则返回NULL。
str const char* 原字符串。

tk_strlen 函数


  • 函数功能:

获取字符串的长度。str为空时返回0。

  • 函数原型:
uint32_t tk_strlen (const char* str);
  • 参数说明:
参数 类型 说明
返回值 uint32_t 返回字符串的长度。
str const char* 字符串。

tk_strncpy 函数


  • 函数功能:

将src所指向的字符串复制到dst,最多复制len个字符串。

  • 函数原型:
char* tk_strncpy (char* dst, const char* src, size_t len);
  • 参数说明:
参数 类型 说明
返回值 char* 返回目标字符串。
dst char* 目标字符串。
src const char* 原字符串。
len size_t 要复制的字符串个数。

tk_strndup 函数


  • 函数功能:

字符串拷贝函数,最多复制len个字符串。

  • 函数原型:
char* tk_strndup (const char* str, uint32_t len);
  • 参数说明:
参数 类型 说明
返回值 char* 返回指向的复制字符串指针,如果失败则返回NULL。
str const char* 原字符串。
len uint32_t 要复制的字符串个数。

tk_strtol 函数


  • 函数功能:

将字符串转换为长整形。

  • 函数原型:
long tk_strtol (const char* str, const char** end, int base);
  • 参数说明:
参数 类型 说明
返回值 long 返回转换后的长整形。
str const char* 要转换为长整形的字符串。
end const char** 对类型char*的对象的引用。
base int 基数。

tk_watob 函数


  • 函数功能:

将宽字符串转换为布尔类型。

  • 函数原型:
bool_t tk_watob (const wchar_t* str);
  • 参数说明:
参数 类型 说明
返回值 bool_t 返回转换后的布尔类型。
str const wchar_t* 要转换为布尔类型的宽字符串。

tk_watof 函数


  • 函数功能:

将宽字符串转换为浮点类型。

  • 函数原型:
double tk_watof (const wchar_t* str);
  • 参数说明:
参数 类型 说明
返回值 double 返回转换后的浮点类型。
str const wchar_t* 要转换为浮点类型的宽字符串。

tk_watoi 函数


  • 函数功能:

将宽字符串转换为整形。

  • 函数原型:
int tk_watoi (const wchar_t* str);
  • 参数说明:
参数 类型 说明
返回值 int 返回转换后的整形。
str const wchar_t* 要转换为整形的宽字符串。

tk_wstrdup 函数


  • 函数功能:

宽字符串拷贝函数。

  • 函数原型:
wchar_t* tk_wstrdup (const wchar_t* str);
  • 参数说明:
参数 类型 说明
返回值 wchar_t* 返回指向的复制宽字符串指针,如果失败则返回NULL。
str const wchar_t* 原宽字符串。
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/seasky100/awtk.git
git@gitee.com:seasky100/awtk.git
seasky100
awtk
awtk
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891