mirror of https://github.com/ecmwf/eccodes.git
ECC-1936: Compilation error: identifier 'strcasestr' is undefined with nec compilers
This commit is contained in:
parent
c71df54c8f
commit
db935ef8ff
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "grib_api_internal.h"
|
#include "grib_api_internal.h"
|
||||||
|
#include <string>
|
||||||
/*
|
/*
|
||||||
This is used by make_class.pl
|
This is used by make_class.pl
|
||||||
|
|
||||||
|
@ -71,28 +71,21 @@ grib_expression_class* grib_expression_class_functor = &_grib_expression_class_f
|
||||||
|
|
||||||
/* END_CLASS_IMP */
|
/* END_CLASS_IMP */
|
||||||
|
|
||||||
|
static bool string_contains_case(const char* haystack, const char* needle, bool case_sensitive)
|
||||||
#ifdef ECCODES_ON_WINDOWS
|
|
||||||
// Windows does not have strcasestr
|
|
||||||
static char* strcasestr(const char *haystack, const char* needle)
|
|
||||||
{
|
{
|
||||||
char c, sc;
|
std::string copy_haystack = haystack;
|
||||||
size_t len = 0;
|
std::string copy_needle = needle;
|
||||||
|
|
||||||
if ((c = *needle++) != 0) {
|
if (!case_sensitive) {
|
||||||
c = tolower((unsigned char)c);
|
// Convert both strings to lowercase if we don't care about case
|
||||||
len = strlen(needle);
|
std::transform(copy_needle.begin(), copy_needle.end(), copy_needle.begin(),
|
||||||
do {
|
[](unsigned char c) { return std::tolower(c); });
|
||||||
do {
|
std::transform(copy_haystack.begin(), copy_haystack.end(), copy_haystack.begin(),
|
||||||
if ((sc = *haystack++) == 0)
|
[](unsigned char c) { return std::tolower(c); });
|
||||||
return (NULL);
|
|
||||||
} while ((char)tolower((unsigned char)sc) != c);
|
|
||||||
} while (_strnicmp(haystack, needle, len) != 0);
|
|
||||||
haystack--;
|
|
||||||
}
|
}
|
||||||
return ((char *)haystack);
|
// Perform the search
|
||||||
|
return copy_haystack.find(copy_needle) != std::string::npos;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
|
static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
|
||||||
{
|
{
|
||||||
|
@ -214,8 +207,8 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
|
||||||
err = grib_get_string(h, keyName, keyValue, &len);
|
err = grib_get_string(h, keyName, keyValue, &len);
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
const char* sValue = grib_arguments_get_string(h, e->args, 1);
|
const char* sValue = grib_arguments_get_string(h, e->args, 1);
|
||||||
const bool case_sens = grib_arguments_get_long(h, e->args, 2) != 0;
|
const bool case_sens = grib_arguments_get_long(h, e->args, 2) == 0; // 0=case-sensitive, 1=case-insensitive
|
||||||
const bool contains = case_sens? strcasestr(keyValue, sValue) : strstr(keyValue, sValue);
|
const bool contains = string_contains_case(keyValue, sValue, case_sens);
|
||||||
if (sValue && contains) {
|
if (sValue && contains) {
|
||||||
*lres = 1;
|
*lres = 1;
|
||||||
return GRIB_SUCCESS;
|
return GRIB_SUCCESS;
|
||||||
|
|
|
@ -22,10 +22,10 @@ sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||||
cat > $tempFilt <<EOF
|
cat > $tempFilt <<EOF
|
||||||
if (! contains(identifier, "GR", 0) ) { assert (false); }
|
if (! contains(identifier, "GR", 0) ) { assert (false); }
|
||||||
if (! contains(identifier, "ib", 1) ) { assert (false); }
|
if (! contains(identifier, "ib", 1) ) { assert (false); }
|
||||||
if (! contains(identifier, "", 1) ) { assert (false); }
|
if (! contains(identifier, "", 1) ) { assert (false); }
|
||||||
|
|
||||||
if (contains(identifier, "grb", 1) ) { assert (false); }
|
if (contains(identifier, "grb", 1) ) { assert (false); }
|
||||||
if (contains(identifier, "ib", 0) ) { assert (false); }
|
if (contains(identifier, "ib", 0) ) { assert (false); }
|
||||||
EOF
|
EOF
|
||||||
cat $tempFilt
|
cat $tempFilt
|
||||||
${tools_dir}/grib_filter $tempFilt $sample
|
${tools_dir}/grib_filter $tempFilt $sample
|
||||||
|
|
Loading…
Reference in New Issue