Avoided to convert empty PVD components copyright_file_id, abstract_file_id, or

bibliographic_file_id to " " and then "_" during multi-session loading and
writing. New util function iso_util_strcopy_untail().
This commit is contained in:
2009-10-05 17:18:20 +02:00
parent 6bc1395e15
commit f88d8a76b0
3 changed files with 40 additions and 4 deletions

View File

@ -1392,13 +1392,36 @@ char *strcopy(const char *buf, size_t len)
strncpy(str, buf, len);
str[len] = '\0';
/* remove trailing spaces */
/* remove trailing spaces
(This leaves the space at str[0] existing. Bug or feature ?)
*/
for (len = len-1; str[len] == ' ' && len > 0; --len)
str[len] = '\0';
return str;
}
char *iso_util_strcopy_untail(const char *buf, size_t len)
{
char *str;
str = malloc((len + 1) * sizeof(char));
if (str == NULL) {
return NULL;
}
strncpy(str, buf, len);
str[len] = 0;
/* remove trailing spaces */
for (len = len-1; len >= 0; --len) {
if (str[len] != ' ')
break;
str[len] = 0;
}
return str;
}
/**
* Copy up to \p max characters from \p src to \p dest. If \p src has less than
* \p max characters, we pad dest with " " characters.