renamed to find_str_in_array instead of string_serial_from_list
This commit is contained in:
parent
df2e13d8de
commit
fc86d443d4
@ -2483,6 +2483,41 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找一个字符串在一个字符串列表中的序列号
|
||||
* @param list 对应的字符串列表,以0结尾,如:const char *target_list[]={"self","line","circle","\0"};
|
||||
* @param str 要查找的字节串
|
||||
* @return 返回查找出的序号,-1表示失败
|
||||
*/
|
||||
template<typename T>
|
||||
inline const int find_str_in_array(const T **list,const T *str)
|
||||
{
|
||||
if(!str||!list)return(-1);
|
||||
|
||||
int index=0;
|
||||
|
||||
do
|
||||
{
|
||||
if(*list[index]==0)
|
||||
return(-1);
|
||||
|
||||
if(stricmp(list[index],str)==0)
|
||||
return index;
|
||||
|
||||
++index;
|
||||
}while(*list[index]);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找一个字符串在一个字符串列表中的序列号
|
||||
* @param count 字符串列表中的字符串数量
|
||||
* @param str_array 对应的字符串列表
|
||||
* @param str 要查找的字节串
|
||||
* @param str_len 要查找的字节串长度(0表示不限定长度)
|
||||
* @return 返回查找出的序号,-1表示失败
|
||||
*/
|
||||
template<typename T>
|
||||
inline const int find_str_in_array(int count,const T **str_array,const T *str,int str_len=0)
|
||||
{
|
||||
@ -2503,6 +2538,14 @@ namespace hgl
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个字符串是否在当前字符串列表中
|
||||
*/
|
||||
template<typename T> inline bool string_in_list(const T **list,const T *str)
|
||||
{
|
||||
return find_str_in_array(list,str)!=-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从字符串中解晰数值阵列,如"1,2,3"或"1 2 3"
|
||||
*/
|
||||
@ -2797,40 +2840,6 @@ namespace hgl
|
||||
return(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个字符串在一个字符串列表中的序列号
|
||||
* @param list 对应的字符串列表,以0结尾,如:const char *target_list[]={"self","line","circle","\0"};
|
||||
* @param str 要查找的字节串
|
||||
* @return 返回查找出的序号,-1表示失败
|
||||
*/
|
||||
template<typename T> inline const int string_serial_from_list(const T **list,const T *str)
|
||||
{
|
||||
if(!str||!list)return(-1);
|
||||
|
||||
int index=0;
|
||||
|
||||
do
|
||||
{
|
||||
if(*list[index]==0)
|
||||
return(-1);
|
||||
|
||||
if(stricmp(list[index],str)==0)
|
||||
return index;
|
||||
|
||||
++index;
|
||||
}while(*list[index]);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个字符串是否在当前字符串列表中
|
||||
*/
|
||||
template<typename T> inline bool contians_in_list(const T **list,const T *str)
|
||||
{
|
||||
return string_serial_from_list(list,str)!=-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测字符串是否符合代码命名规则(仅可使用字母和数字、下划线,不能使用数字开头)
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user