📄 str.c
字号:
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&字符串函数库&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//*文件名称:str.c
//*文件作用:字符串函数库
//*文件作者:翟 鹏
//*创建日期:2004年5月
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
#include <include.h>
//***********************************************************************************************************************
//函数作用:判断目的串是否等于给定的串
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:如果相等返回1
//***********************************************************************************************************************
uchar str_compare(uchar *dest, uchar *src)
{
while(*src)if((*dest++)!=(*src++))return 0;
if(*dest)return 0;//如果目的串还没有完 说明不相等
return 1;
}
//***********************************************************************************************************************
//函数作用:判断目的串是否包含给定的串
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:如果相等返回1
//***********************************************************************************************************************
uchar str_comprise(uchar *dest, uchar *src)
{
while(*src)if((*dest++)!=(*src++))return 0;
return 1;
}
//***********************************************************************************************************************
//函数作用:把给定的串拷贝到目的串中
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:返回目的串
//***********************************************************************************************************************
void str_copy(uchar *dest, uchar *src)
{
while((*dest++ = *src++)!=0);
}
//***********************************************************************************************************************
//函数作用:把给定的串添加到目的串末尾
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:返回目的串
//***********************************************************************************************************************
void str_cat(uchar *dest, uchar *src)
{
while(*dest)dest++;
while((*dest++ = *src++)!=0);
}
//***********************************************************************************************************************
//函数作用:把给定的串拷贝到目的串中 直到发现给定字符为止 并添加结束符
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:返回目的串
//***********************************************************************************************************************
void str_char_copy(uchar *dest, uchar *src, uchar ch)
{
while((*dest++ = *src++)!=ch);
dest--;
*dest=0;
}
//***********************************************************************************************************************
//函数作用:把给定的串拷贝到目的unicode串中
//参数说明:dest---目的串 src---给定的串
//注意事项:
//返回说明:返回目的串
//***********************************************************************************************************************
void str_unicode_copy(uint *dest, uchar *src)
{
while((*dest++ = *src++)!=0);
}
//***********************************************************************************************************************
//函数作用:计算字符串长度
//参数说明:str---给定的串
//注意事项:
//返回说明:字节型长度数值
//***********************************************************************************************************************
uint str_length(uchar *str)
{
uint i=0;
while(str[i])i++;
return i;
}
//***********************************************************************************************************************
//函数作用:内存拷贝
//参数说明:dest---目的串 src---给定的串 n---拷贝长度
//注意事项:
//返回说明:如果相等返回1
//***********************************************************************************************************************
void mem_copy(uchar *dest, uchar *src, uint n)
{
while(n--)*dest++=*src++;
}
//***********************************************************************************************************************
//*函数作用:把整数转化成十进制串
//*参数说明:dec---转化成的十进制串 n--要转化的整数
//*注意事项:
//*返回说明:无
//***********************************************************************************************************************
void int_to_dec(uchar *dec, uint n)
{
uchar i=0;
uchar result;
uint divisor, remainder;
remainder=n;
for(divisor=10000;divisor>0;divisor/=10)
{
result=remainder/divisor;
remainder%=divisor;
if(result!=0 || divisor==1 || i>0)
dec[i++]=result+0x30;
}
dec[i]=0;
}
void long_to_dec(uchar *dec, ulong n)
{
uchar i=0;
uchar result;
ulong divisor, remainder;
remainder=n;
for(divisor=1000000000;divisor>0;divisor/=10)
{
result=remainder/divisor;
remainder%=divisor;
if(result!=0 || divisor==1 || i>0)
dec[i++]=result+0x30;
}
dec[i]=0;
}
//***********************************************************************************************************************
//函数作用:把hex字符串--转化为整数
//参数说明:hex---给定的串
//注意事项:
//返回说明:返回是否成功
//***********************************************************************************************************************
static char xdigitvalue(uchar isdigit)//判断是否是十六进制数字
{
if(isdigit>='0' && isdigit<='9')return isdigit-'0';
else if(isdigit>='A' && isdigit<='F')return isdigit-'7';
return -1;
}
uchar hex_to_char(uchar *hex, uchar *n)
{
char i,k;
*n=0;
for(k=0;k<2;k++)
{
if((i=xdigitvalue(hex[k]))==-1)return 0;
*n=((*n)<<4)|i;
}
return 1;
}
//***********************************************************************************************************************
//函数作用:把缓冲区内容转化成为hex字符串
//参数说明:buf
//注意事项:
//返回说明:如果相等返回1
//***********************************************************************************************************************
void buf_to_hex(uchar *hex, uchar *buf, uint length)
{
uchar asiic[]="0123456789ABCDEF";
while(length--)
{
*hex++=asiic[(*buf)>>4];
*hex++=asiic[(*buf++)&0x0F];
}
*hex=0;
}
//***********************************************************************************************************************
//*函数作用:把整数转化成hex串
//*参数说明:hex---转化成的hex串 n--要转化的整数
//*注意事项:
//*返回说明:
//***********************************************************************************************************************
void char_to_hex(uchar *hex, uchar n)
{
buf_to_hex(hex,&n,1);
}
//***********************************************************************************************************************
//函数作用:把十进制字符串转化成整数
//参数说明:dec--要转化的十进制串 n--转化成的整数
//注意事项:
//返回说明:返回是否成功
//***********************************************************************************************************************
//static char digitvalue(uchar isdigit)//判断是否是十进制数字
//{
// if(isdigit>='0' && isdigit<='9')return isdigit-'0';
// return -1;
//}
//uchar dec_to_int(uchar *dec, uint *n)
//{
// char i;
// *n=0;
// while(*dec)
// {
// if((i=digitvalue(*dec))==-1)return 0;
// *n=((*n)*10)+i;
// dec++;
// }
// return 1;
//}
//uchar dec_to_long(uchar *dec, ulong *n)
//{
// char i;
// *n=0;
// while(*dec)
// {
// if((i=digitvalue(*dec))==-1)return 0;
// *n=((*n)*10)+i;
// dec++;
// }
// return 1;
//}
//***********************************************************************************************************************
//函数作用:控制台打印字符串
//参数说明:linestr---给定的串
//注意事项:
//返回说明:返回是否成功
//***********************************************************************************************************************
void print_line(uchar *linestr)
{
DEBUG_SEND_STR(linestr);
DEBUG_SEND_CHAR('\r');
DEBUG_SEND_CHAR('\n');
}
/*
//***********************************************************************************************************************
//函数作用:计算unicode串长度
//参数说明:buf---给定的unicode
//注意事项:
//返回说明:字节型长度数值
//***********************************************************************************************************************
uchar unicode_length(uint *buf)
{
uchar i=0;
while(buf[i])i++;
return i;
}
//***********************************************************************************************************************
//*函数作用:把整数转化成hex串
//*参数说明:hex---转化成的hex串 n--要转化的整数
//*注意事项:
//*返回说明:
//***********************************************************************************************************************
//void int_to_hex(uchar *hex, uint n)
//{
// buf_to_hex(hex,(uchar *)&n,2);
//}
//uchar hex_to_int(uchar *hex, uint *n)
//{
// char i,k;
// *n=0;
// for(k=0;k<4;k++)
// {
// if((i=xdigitvalue(hex[k]))==-1)return 0;
// *n=((*n)<<4)|i;
// }
// return 1;
//}
//uchar hex_to_long(uchar *hex, ulong *n)
//{
// char i,k;
// *n=0;
// for(k=0;k<8;k++)
// {
// if((i=xdigitvalue(hex[k]))==-1)return 0;
// *n=((*n)<<4)|i;
// }
// return 1;
//}
uchar hex_to_buf(uchar *hex, uchar *buf)
{
uchar length=0;
while(*hex)
{
hex_to_char(hex,buf++);
hex+=2;
length++;
}
*buf=0;
return length;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -