diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 953552f1..ad687f5a 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 295 2009-10-06 13:47:16Z hyunghwan.chung $ + * $Id: str.h 297 2009-10-08 13:09:19Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -104,12 +104,12 @@ struct qse_str_t } /** - * The qse_strtrmc_op_t defines a string trimming operation. + * The qse_strtrmx_op_t defines a string trimming operation. */ -enum qse_strtrmc_op_t +enum qse_strtrmx_op_t { - QSE_STRTRMC_LEFT = (1 << 0), /**< trim leading spaces */ - QSE_STRTRMC_RIGHT = (1 << 1) /**< trim trailing spaces */ + QSE_STRTRMX_LEFT = (1 << 0), /**< trim leading spaces */ + QSE_STRTRMX_RIGHT = (1 << 1) /**< trim trailing spaces */ }; #ifdef __cplusplus @@ -483,13 +483,13 @@ int qse_strspltrn ( /******/ /** - * The qse_strtrmc() function removes leading spaces and/or trailing - * spaces from a string depending on the opt parameter. You can form + * The qse_strtrmx() function strips leading spaces and/or trailing + * spaces off a string depending on the opt parameter. You can form * the op parameter by bitwise-OR'ing one or more of the following * values: * - * - QSE_STRTRMC_LEFT - trim leading spaces - * - QSE_STRTRMC_RIGHT - trim trailing spaces + * - QSE_STRTRMX_LEFT - trim leading spaces + * - QSE_STRTRMX_RIGHT - trim trailing spaces * * Should it remove leading spaces, it just returns the pointer to * the first non-space character in the string. Should it remove trailing @@ -498,52 +498,72 @@ int qse_strspltrn ( * * @code * qse_char_t a[] = QSE_T(" this is a test string "); - * qse_printf (QSE_T("[%s]\n"), qse_strtrmc(a,QSE_STRTRMC_LEFT|QSE_STRTRMC_RIGHT)); + * qse_printf (QSE_T("[%s]\n"), qse_strtrmx(a,QSE_STRTRMX_LEFT|QSE_STRTRMX_RIGHT)); * @endcode * - * @return the pointer to a trimmed string. + * @return pointer to a trimmed string. */ -qse_char_t* qse_strtrmc ( +qse_char_t* qse_strtrmx ( qse_char_t* str, /**< a string */ - int op /**< operation code XOR'ed of qse_strtrmc_op_t values */ + int op /**< operation code XOR'ed of qse_strtrmx_op_t values */ ); +/* + * The qse_strtrm() function strips leading spaces and/or trailing + * spaces off a string. All characters between the first and the last non-space + * character inclusive are relocated to the beginning of memory pointed to + * by @a str; QSE_T('\0') is inserted after the last non-space character. + * @return length of the string without leading and trailing spaces. + */ qse_size_t qse_strtrm ( - qse_char_t* str + qse_char_t* str /**< string */ ); +/* + * The qse_strxtrm() function strips leading spaces and/or trailing + * spaces off a string. All characters between the first and the last non-space + * character inclusive are relocated to the beginning of memory pointed to + * by @a str; QSE_T('\0') is inserted after the last non-space character. + * @return length of the string without leading and trailing spaces. + */ qse_size_t qse_strxtrm ( - qse_char_t* str, - qse_size_t len + qse_char_t* str, /**< string */ + qse_size_t len /**< length */ ); +/** + * The qse_strpac() function folds repeated whitespaces into one as well + * as stripping leading whitespaces and trailing whitespaces. + * @return length of the string without leading and trailing spaces. + */ qse_size_t qse_strpac ( - qse_char_t* str + qse_char_t* str /**< string */ ); +/** + * The qse_strxpac() function folds repeated whitespaces into one as well + * as stripping leading whitespaces and trailing whitespaces. + * @return length of the string without leading and trailing spaces. + */ qse_size_t qse_strxpac ( - qse_char_t* str, - qse_size_t len + qse_char_t* str, /**< string */ + qse_size_t len /**< length */ ); -/****f* Common/qse_mbstowcs - * NAME - * qse_mbstowcs - convert a multibyte string to a wide character string - * SYNOPSIS +/** + * The qse_mbstowcs() function converts a multibyte string to a wide + * character string. */ qse_size_t qse_mbstowcs ( const qse_mchar_t* mbs, qse_wchar_t* wcs, qse_size_t* wcslen ); -/******/ -/****f* Common/qse_mbsntowcsn - * NAME - * qse_mbsntowcsn - convert a multibyte string to a wide character string - * RETURN - * The qse_mbstowcs() function returns the number of bytes handled. - * SYNOPSIS +/** + * The qse_mbsntowcsn() function converts a multibyte string to a + * wide character string. + * @return number of bytes handled. */ qse_size_t qse_mbsntowcsn ( const qse_mchar_t* mbs, @@ -551,61 +571,42 @@ qse_size_t qse_mbsntowcsn ( qse_wchar_t* wcs, qse_size_t* wcslen ); -/******/ /****f* Common/qse_wcstombslen - * NAME - * qse_wcstombslen - get the length - * DESCRIPTION - * The qse_wcstombslen() function scans a null-terminated wide character - * string to get the total number of multibyte characters that it can be - * converted to. The resulting number of characters is stored into memory - * pointed to by mbslen. - * RETURN - * The qse_wcstombslen() function returns the number of wide characters - * handled. - * SYNOPSIS + * The qse_wcstombslen() function scans a null-terminated wide character + * string @a wcs to get the total number of multibyte characters that it can be + * converted to. The resulting number of characters is stored into memory + * pointed to by @a mbslen. + * @return number of wide characters handled */ qse_size_t qse_wcstombslen ( const qse_wchar_t* wcs, qse_size_t* mbslen ); -/******/ -/****f* Common/qse_wcsntombsnlen - * NAME - * qse_wcsntombsnlen - get the length - * DESCRIPTION - * The qse_wcsntombsnlen() function scans a wide character wcs as long as - * wcslen characters to get the get the total number of multibyte characters - * that it can be converted to. The resulting number of characters is stored - * into memory pointed to by mbslen. - * RETURN - * The qse_wcsntombsnlen() function returns the number of wide characters - * handled. - * SYNOPSIS +/** + * The qse_wcsntombsnlen() function scans a wide character wcs as long as + * wcslen characters to get the get the total number of multibyte characters + * that it can be converted to. The resulting number of characters is stored + * into memory pointed to by @a mbslen. + * @return number of wide characters handled */ qse_size_t qse_wcsntombsnlen ( const qse_wchar_t* wcs, qse_size_t wcslen, qse_size_t* mbslen ); -/******/ -/****f* Common/qse_wcstombs - * NAME - * qse_wcstombs - convert a wide character string to a multibyte string. - * DESCRIPTION - * The qse_wcstombs() function converts a null-terminated wide character - * string to a multibyte string and stores it into the buffer pointed to - * by mbs. The pointer to a variable holding the buffer length should be - * passed to the function as the third parameter. After conversion, it holds - * the length of the multibyte string excluding the terminating-null. - * It may not null-terminate the resulting multibyte string if the buffer - * is not large enough. You can check if the resulting mbslen is equal to - * the input mbslen to know it. - * RETURN - * The qse_wcstombs() function returns the number of wide characters handled. +/** + * The qse_wcstombs() function converts a null-terminated wide character + * string to a multibyte string and stores it into the buffer pointed to + * by mbs. The pointer to a variable holding the buffer length should be + * passed to the function as the third parameter. After conversion, it holds + * the length of the multibyte string excluding the terminating-null. + * It may not null-terminate the resulting multibyte string if the buffer + * is not large enough. You can check if the resulting mbslen is equal to + * the input mbslen to know it. + * @return number of wide characters handled * SYNOPSIS */ qse_size_t qse_wcstombs ( @@ -613,7 +614,6 @@ qse_size_t qse_wcstombs ( qse_mchar_t* mbs, qse_size_t* mbslen ); -/******/ /** * The qse_wcsntombsn() function converts a wide character string to a diff --git a/qse/include/qse/cut/cut.h b/qse/include/qse/cut/cut.h index 95c662fa..4179a643 100644 --- a/qse/include/qse/cut/cut.h +++ b/qse/include/qse/cut/cut.h @@ -27,6 +27,8 @@ /** @file * cut utility + * + * @todo QSE_CUT_ORDEREDSEL - A selector 5,3,1 is ordered to 1,3,5 */ /** diff --git a/qse/lib/cmn/str_dyn.c b/qse/lib/cmn/str_dyn.c index 4f5ea460..a0fdcda3 100644 --- a/qse/lib/cmn/str_dyn.c +++ b/qse/lib/cmn/str_dyn.c @@ -1,5 +1,5 @@ /* - * $Id: str_dyn.c 295 2009-10-06 13:47:16Z hyunghwan.chung $ + * $Id: str_dyn.c 297 2009-10-08 13:09:19Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -127,6 +127,8 @@ qse_size_t qse_str_setcapa (qse_str_t* str, qse_size_t capa) { qse_char_t* tmp; + if (capa == str->capa) return capa; + if (str->mmgr->realloc != QSE_NULL && str->ptr != QSE_NULL) { tmp = (qse_char_t*) QSE_MMGR_REALLOC ( diff --git a/qse/lib/cmn/str_utl.c b/qse/lib/cmn/str_utl.c index 570bae98..d1a45a25 100644 --- a/qse/lib/cmn/str_utl.c +++ b/qse/lib/cmn/str_utl.c @@ -1,5 +1,5 @@ /* - * $Id: str_utl.c 295 2009-10-06 13:47:16Z hyunghwan.chung $ + * $Id: str_utl.c 297 2009-10-08 13:09:19Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -312,7 +312,7 @@ int qse_strspl ( return qse_strspltrn (s, delim, lquote, rquote, escape, QSE_NULL); } -qse_char_t* qse_strtrmc (qse_char_t* str, int opt) +qse_char_t* qse_strtrmx (qse_char_t* str, int opt) { qse_char_t* p = str; qse_char_t* s = QSE_NULL, * e = QSE_NULL; @@ -327,8 +327,8 @@ qse_char_t* qse_strtrmc (qse_char_t* str, int opt) p++; } - if (opt & QSE_STRTRMC_RIGHT) e[1] = QSE_T('\0'); - if (opt & QSE_STRTRMC_LEFT) str = s; + if (opt & QSE_STRTRMX_RIGHT) e[1] = QSE_T('\0'); + if (opt & QSE_STRTRMX_LEFT) str = s; return str; } diff --git a/qse/lib/cut/cut.c b/qse/lib/cut/cut.c index 1f128d16..c17b9e9d 100644 --- a/qse/lib/cut/cut.c +++ b/qse/lib/cut/cut.c @@ -28,7 +28,9 @@ static qse_cut_t* qse_cut_init (qse_cut_t* cut, qse_mmgr_t* mmgr); static void qse_cut_fini (qse_cut_t* cut); #define SETERR0(cut,num) \ -do { qse_cut_seterror (cut, num, QSE_NULL); } while (0) + do { qse_cut_seterror (cut, num, QSE_NULL); } while (0) + +#define DFL_LINE_CAPA 256 static int add_selector_block (qse_cut_t* cut) { @@ -120,6 +122,13 @@ static qse_cut_t* qse_cut_init (qse_cut_t* cut, qse_mmgr_t* mmgr) cut->e.in.cflds = QSE_COUNTOF(cut->e.in.sflds); cut->e.in.flds = cut->e.in.sflds; + if (qse_str_init ( + &cut->e.in.line, QSE_MMGR(cut), DFL_LINE_CAPA) == QSE_NULL) + { + SETERR0 (cut, QSE_CUT_ENOMEM); + return QSE_NULL; + } + return cut; } @@ -128,6 +137,7 @@ static void qse_cut_fini (qse_cut_t* cut) free_all_selector_blocks (cut); if (cut->e.in.flds != cut->e.in.sflds) QSE_MMGR_FREE (cut->mmgr, cut->e.in.flds); + qse_str_fini (&cut->e.in.line); } void qse_cut_setoption (qse_cut_t* cut, int option) @@ -147,6 +157,9 @@ void qse_cut_clear (qse_cut_t* cut) QSE_MMGR_FREE (cut->mmgr, cut->e.in.flds); cut->e.in.cflds = QSE_COUNTOF(cut->e.in.sflds); cut->e.in.flds = cut->e.in.sflds; + + qse_str_clear (&cut->e.in.line); + qse_str_setcapa (&cut->e.in.line, DFL_LINE_CAPA); } int qse_cut_comp ( @@ -589,11 +602,6 @@ int qse_cut_exec (qse_cut_t* cut, qse_cut_io_fun_t inf, qse_cut_io_fun_t outf) cut->e.in.len = 0; cut->e.in.pos = 0; cut->e.in.num = 0; - if (qse_str_init (&cut->e.in.line, QSE_MMGR(cut), 256) == QSE_NULL) - { - SETERR0 (cut, QSE_CUT_ENOMEM); - return -1; - } cut->errnum = QSE_CUT_ENOERR; n = cut->e.in.fun (cut, QSE_CUT_IO_OPEN, &cut->e.in.arg, QSE_NULL, 0); @@ -727,6 +735,5 @@ done: done2: cut->e.in.fun (cut, QSE_CUT_IO_CLOSE, &cut->e.in.arg, QSE_NULL, 0); done3: - qse_str_fini (&cut->e.in.line); return ret; } diff --git a/qse/samples/cmn/str.c b/qse/samples/cmn/str.c index 0143626c..7dbf88aa 100644 --- a/qse/samples/cmn/str.c +++ b/qse/samples/cmn/str.c @@ -515,14 +515,14 @@ static int test12 (void) qse_char_t a3[] = QSE_T(" this is a test string "); qse_printf (QSE_T("[%s] =>"), a1); - qse_printf (QSE_T("[%s]\n"), qse_strtrmc (a1, QSE_STRTRMC_LEFT)); + qse_printf (QSE_T("[%s]\n"), qse_strtrmx (a1, QSE_STRTRMX_LEFT)); qse_printf (QSE_T("[%s] =>"), a2); - qse_printf (QSE_T("[%s]\n"), qse_strtrmc (a2, QSE_STRTRMC_RIGHT)); + qse_printf (QSE_T("[%s]\n"), qse_strtrmx (a2, QSE_STRTRMX_RIGHT)); qse_printf (QSE_T("[%s] =>"), a3); qse_printf (QSE_T("[%s]\n"), - qse_strtrmc (a3, QSE_STRTRMC_LEFT|QSE_STRTRMC_RIGHT)); + qse_strtrmx (a3, QSE_STRTRMX_LEFT|QSE_STRTRMX_RIGHT)); return 0; }