Refactoring: Function renaming

This commit is contained in:
Shahram Najm 2022-06-10 20:51:39 +01:00
parent 4fe5f475e7
commit a050115789
8 changed files with 20 additions and 20 deletions

View File

@ -1047,7 +1047,7 @@ int grib_f_open_file_(int* fid, char* name , char* op, int lname, int lop) {
while (*p != '\0') { *p=tolower(*p);p++;}
trimmed = cast_char_no_cut(fname,name,lname); /* ECC-1392 */
rtrim( trimmed );
string_rtrim( trimmed );
f = fopen(trimmed, oper);
if(!f) {
ioerr=errno;
@ -2891,7 +2891,7 @@ int grib_f_index_select_string_(int* gid, char* key, char* val, int len, int val
/* ECC-1316 */
cast_char_no_cut(bufval,val,vallen);
rtrim( bufval );
string_rtrim( bufval );
return grib_index_select_string(h, cast_char(buf,key,len), bufval);
}
@ -3257,7 +3257,7 @@ int grib_f_set_string_array_(int* gid, char* key, char* val,int* nvals,int* slen
for (i=0;i<lsize;i++) {
cval[i]=(char*)grib_context_malloc_clear(c,sizeof(char)* (*slen+1));
cast_char_no_cut(cval[i],p,*slen);
rtrim( cval[i] ); /* trim spaces at end of string */
string_rtrim( cval[i] ); /* trim spaces at end of string */
p+= *slen;
}
err = grib_set_string_array(h, cast_char(buf,key,len), (const char **)cval, lsize);
@ -3327,7 +3327,7 @@ int grib_f_set_string_(int* gid, char* key, char* val, int len, int len2){
/* So do not use cast_char. cast_char_no_cut does not stop at first space */
val_str = cast_char_no_cut(buf2,val,len2);
if (val_str && !is_all_spaces(val_str)) {
rtrim( val_str ); /* trim spaces at end of string */
string_rtrim( val_str ); /* trim spaces at end of string */
}
return grib_set_string(h, cast_char(buf,key,len), val_str, &lsize);

View File

@ -282,7 +282,7 @@ static int bufr_decode_extra_rdb_keys(const void* message, long offset_section2,
}
temp[i] = '\0';
pTemp = temp;
lrtrim(&pTemp, 1, 1); /* Trim left and right */
string_lrtrim(&pTemp, 1, 1); /* Trim left and right */
strncpy(hdr->ident, pTemp, IDENT_LEN - 1);
}

View File

@ -1457,13 +1457,13 @@ int codes_bufr_key_is_header(const grib_handle* h, const char* key, int* err);
/* string_util.c */
int strcmp_nocase(const char* s1, const char* s2);
void rtrim(char* s);
void lrtrim(char** x, int do_left, int do_right);
void string_rtrim(char* s);
void string_lrtrim(char** x, int do_left, int do_right);
const char* extract_filename(const char* filepath);
char** string_split(char* inputString, const char* delimiter);
int string_to_long(const char* input, long* output);
int string_ends_with(const char* str1, const char* str2);
int count_char_in_string(const char* str, char c);
int string_count_char(const char* str, char c);
const char* codes_get_product_name(ProductKind product);
const char* grib_get_type_name(int type);
char* string_replace_char(char *str, char oldc, char newc);

View File

@ -506,7 +506,7 @@ static int grib_load_codetable(grib_context* c, const char* filename,
Assert(*abbreviation);
Assert(*title);
rtrim(title); /* ECC-1315 */
string_rtrim(title); /* ECC-1315 */
if (t->entries[code].abbreviation != NULL) {
grib_context_log(c, GRIB_LOG_WARNING, "code_table_entry: duplicate code in %s: %d (table size=%ld)", filename, code, size);

View File

@ -161,7 +161,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
err = grib_get_string(h, self->input, input, &size);
if (err) return err;
lrtrim(&pInput, self->trim_left, self->trim_right);
string_lrtrim(&pInput, self->trim_left, self->trim_right);
sprintf(val, "%s", pInput);
size = strlen(val);
*len = size + 1;
@ -189,7 +189,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
sprintf(buf, "%s", val);
pBuf = buf;
lrtrim(&pBuf, self->trim_left, self->trim_right);
string_lrtrim(&pBuf, self->trim_left, self->trim_right);
return grib_pack_string(inputAccesstor, pBuf, len);
}

View File

@ -27,7 +27,7 @@ int strcmp_nocase(const char* s1, const char* s2)
}
/* Strip whitespace from the end of a string */
void rtrim(char* s)
void string_rtrim(char* s)
{
size_t len = 0;
if (!s)
@ -38,7 +38,7 @@ void rtrim(char* s)
s[len] = '\0';
}
void lrtrim(char** x, int do_left, int do_right)
void string_lrtrim(char** x, int do_left, int do_right)
{
DebugAssert(do_left || do_right);
if (do_left) {
@ -161,7 +161,7 @@ int string_ends_with(const char* s, const char* suffix)
return 0;
}
int count_char_in_string(const char* str, char c)
int string_count_char(const char* str, char c)
{
int i = 0, count = 0;
DebugAssert(str);

View File

@ -1511,19 +1511,19 @@ static void test_trimming()
printf("Testing: test_trimming...\n");
lrtrim(&pA, 0, 1); /*right only*/
string_lrtrim(&pA, 0, 1); /*right only*/
assert( strcmp(pA, " Standing")==0 );
lrtrim(&pB, 1, 0); /*left only*/
string_lrtrim(&pB, 1, 0); /*left only*/
assert( strcmp(pB, "Weeping ")==0 );
lrtrim(&pC, 1, 1); /*both ends*/
string_lrtrim(&pC, 1, 1); /*both ends*/
assert( strcmp(pC, "Silhouette")==0 );
lrtrim(&pD, 1, 1); /*make sure other spaces are not removed*/
string_lrtrim(&pD, 1, 1); /*make sure other spaces are not removed*/
assert( strcmp(pD, "The Forest Of October")==0 );
lrtrim(&pE, 1, 1); /* Other chars */
string_lrtrim(&pE, 1, 1); /* Other chars */
assert( strcmp(pE, "Apostle In Triumph")==0 );
}

View File

@ -135,7 +135,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
if (grib_options_on("L:")) {
/* Do a very basic sanity check */
const char* str = grib_options_get_option("L:");
if (count_char_in_string(str, '%') != 2) {
if (string_count_char(str, '%') != 2) {
fprintf(stderr, "ERROR: Invalid lats/lons format option \"%s\".\nThe default is: \"%s\"\n",
str, default_format_latlons);
exit(1);