added new string functions and fixed get_file_name() for sed

- added qse_str_setlen() & qse_str_getlen()
- changed get_file_name() to ignore trailing spaces of a file name.
This commit is contained in:
2009-03-24 23:52:27 +00:00
parent d3534abd0f
commit 1e45c03f82
4 changed files with 93 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: str_dyn.c 109 2009-03-24 01:44:31Z hyunghwan.chung $
* $Id: str_dyn.c 110 2009-03-24 05:52:27Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -159,6 +159,31 @@ qse_size_t qse_str_setcapa (qse_str_t* str, qse_size_t capa)
return str->capa;
}
qse_size_t qse_str_getlen (qse_str_t* str)
{
return QSE_STR_LEN (str);
}
qse_size_t qse_str_setlen (qse_str_t* str, qse_size_t len)
{
if (len == str->len) return len;
if (len < str->len)
{
str->len = len;
str->ptr[len] = QSE_T('\0');
return len;
}
if (len > str->capa)
{
if (qse_str_setcapa (str, len) == (qse_size_t)-1)
return (qse_size_t)-1;
}
while (str->len < len) str->ptr[str->len++] = QSE_T(' ');
return str->len;
}
void qse_str_clear (qse_str_t* str)
{
str->len = 0;

View File

@ -580,11 +580,7 @@ static int get_file_name (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (trailing_spaces > 0)
{
qse_str_delete (
t,
QSE_STR_LEN(t) - trailing_spaces,
trailing_spaces
);
qse_str_setlen (t, QSE_STR_LEN(t) - trailing_spaces);
}
qse_str_yield (t, &cmd->u.filename, 0);