From fc86d443d43265a611f0d167f08fe358cd9bd6f6 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sun, 22 Dec 2024 00:11:32 +0800 Subject: [PATCH] renamed to find_str_in_array instead of string_serial_from_list --- inc/hgl/type/StrChar.h | 77 +++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index 9c54dd8..838fff1 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -2483,6 +2483,41 @@ namespace hgl return(true); } + /** + * 查找一个字符串在一个字符串列表中的序列号 + * @param list 对应的字符串列表,以0结尾,如:const char *target_list[]={"self","line","circle","\0"}; + * @param str 要查找的字节串 + * @return 返回查找出的序号,-1表示失败 + */ + template + 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 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 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 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 inline bool contians_in_list(const T **list,const T *str) - { - return string_serial_from_list(list,str)!=-1; - } - /** * 检测字符串是否符合代码命名规则(仅可使用字母和数字、下划线,不能使用数字开头) */