Skip to content
Snippets Groups Projects
Commit 096fcddb authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add iniGetClampedInt() to return an int key val clamped to a min/max range

Very similar to iniGetIntInRange(), but the default value is only returned
if the key or value is missing.
parent aa33f300
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3792 passed
......@@ -1728,6 +1728,7 @@ int iniGetInteger(str_list_t list, const char* section, const char* key, int def
return(parseInteger(vp));
}
/* Returns the default value if key value is out of range */
int iniGetIntInRange(str_list_t list, const char* section, const char* key, int min, int deflt, int max)
{
char* vp=NULL;
......@@ -1744,6 +1745,24 @@ int iniGetIntInRange(str_list_t list, const char* section, const char* key, int
return result;
}
/* Returns the min or max value if key value is out of range */
int iniGetClampedInt(str_list_t list, const char* section, const char* key, int min, int deflt, int max)
{
char* vp=NULL;
int result;
get_value(list, section, key, NULL, &vp, /* literals_supported: */FALSE);
if(vp==NULL || *vp==0) /* blank value or missing key */
return deflt;
result = parseInteger(vp);
if(result < min)
return min;
if(result > max)
return max;
return result;
}
uint iniGetUInteger(str_list_t list, const char* section, const char* key, uint deflt)
{
......
......@@ -158,6 +158,8 @@ DLLEXPORT int iniGetInteger(str_list_t, const char* section, const char* key
,int deflt);
DLLEXPORT int iniGetIntInRange(str_list_t, const char* section, const char* key
,int min, int deflt, int max);
DLLEXPORT int iniGetClampedInt(str_list_t, const char* section, const char* key
,int min, int deflt, int max);
DLLEXPORT uint iniGetUInteger(str_list_t, const char* section, const char* key
,uint deflt);
DLLEXPORT short iniGetShortInt(str_list_t, const char* section, const char* key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment