diff --git a/src/bacnet/indtext.c b/src/bacnet/indtext.c index 9c8da85b..f132bf23 100644 --- a/src/bacnet/indtext.c +++ b/src/bacnet/indtext.c @@ -33,13 +33,18 @@ ####COPYRIGHTEND####*/ #include #include +#include #include "bacnet/indtext.h" /** @file indtext.c Maps text strings and indices of type INDTEXT_DATA */ -#if !defined(__BORLANDC__) && !defined(_MSC_VER) -#include -int stricmp(const char *s1, const char *s2) +/** + * @brief Compare two strings ignoring case + * @param s1 - first string + * @param s2 - second string + * @return 0 if the strings are equal, otherwise non-zero + */ +static int indtext_stricmp(const char *s1, const char *s2) { unsigned char c1, c2; @@ -54,11 +59,14 @@ int stricmp(const char *s1, const char *s2) return (int)c1 - c2; } -#endif -#if defined(_MSC_VER) -#define stricmp _stricmp -#endif +/** + * @brief Search a list of strings to find a matching string + * @param data_list - list of strings and indices + * @param search_name - string to search for + * @param found_index - index of the string found + * @return true if the string is found + */ bool indtext_by_string( INDTEXT_DATA *data_list, const char *search_name, unsigned *found_index) { @@ -83,7 +91,13 @@ bool indtext_by_string( return found; } -/* case insensitive version */ +/** + * @brief Search a list of strings to find a matching string, case insensitive + * @param data_list - list of strings and indices + * @param search_name - string to search for + * @param found_index - index of the string found + * @return true if the string is found + */ bool indtext_by_istring( INDTEXT_DATA *data_list, const char *search_name, unsigned *found_index) { @@ -92,7 +106,7 @@ bool indtext_by_istring( if (data_list && search_name) { while (data_list->pString) { - if (stricmp(data_list->pString, search_name) == 0) { + if (indtext_stricmp(data_list->pString, search_name) == 0) { index = data_list->index; found = true; break; @@ -108,6 +122,14 @@ bool indtext_by_istring( return found; } +/** + * @brief Search a list of strings to find a matching string, + * or return a default index + * @param data_list - list of strings and indices + * @param search_name - string to search for + * @param default_index - index to return if the string is not found + * @return index of the string found, or the default index + */ unsigned indtext_by_string_default( INDTEXT_DATA *data_list, const char *search_name, unsigned default_index) { @@ -120,6 +142,14 @@ unsigned indtext_by_string_default( return index; } +/** + * @brief Search a list of strings to find a matching string, case insensitive + * or return a default index + * @param data_list - list of strings and indices + * @param search_name - string to search for + * @param default_index - index to return if the string is not found + * @return index of the string found, or the default index + */ unsigned indtext_by_istring_default( INDTEXT_DATA *data_list, const char *search_name, unsigned default_index) { @@ -132,6 +162,12 @@ unsigned indtext_by_istring_default( return index; } +/** + * @brief Return the string for a given index + * @param data_list - list of strings and indices + * @param index - index to search for + * @return the string found, or NULL if not found + */ const char *indtext_by_index_default( INDTEXT_DATA *data_list, unsigned index, const char *default_string) { @@ -150,6 +186,15 @@ const char *indtext_by_index_default( return pString ? pString : default_string; } +/** + * @brief Return the string for a given index, or a default string + * @param data_list - list of strings and indices + * @param index - index to search for + * @param before_split_default_name - default string to return if the index + * is before the split_index + * @param default_name - default string to return if the index is not found + * @return the string found, or a default string + */ const char *indtext_by_index_split_default(INDTEXT_DATA *data_list, unsigned index, unsigned split_index, @@ -164,11 +209,22 @@ const char *indtext_by_index_split_default(INDTEXT_DATA *data_list, } } +/** + * @brief Return the string for a given index + * @param data_list - list of strings and indices + * @param index - index to search for + * @return the string found, or NULL if not found + */ const char *indtext_by_index(INDTEXT_DATA *data_list, unsigned index) { return indtext_by_index_default(data_list, index, NULL); } +/** + * @brief Return the number of elements in the list + * @param data_list - list of strings and indices + * @return the number of elements in the list + */ unsigned indtext_count(INDTEXT_DATA *data_list) { unsigned count = 0; /* return value */