added qse_mbsfcpy()/qse_wcsfcpy() and related functions

This commit is contained in:
hyung-hwan 2011-03-25 08:20:55 +00:00
parent 9255381669
commit 486c2b53d5
13 changed files with 951 additions and 417 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 410 2011-03-23 15:07:24Z hyunghwan.chung $
* $Id: str.h 411 2011-03-24 14:20:55Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -244,85 +244,196 @@ qse_size_t qse_wcsxncpy (
# define qse_strxncpy(buf,bsz,str,len) qse_wcsxncpy(buf,bsz,str,len)
#endif
qse_size_t qse_mbsput (
qse_mchar_t* buf,
const qse_mchar_t* str
);
qse_size_t qse_wcsput (
qse_wchar_t* buf,
const qse_wchar_t* str
);
/**
* The qse_strxput() function copies the string @a str into the buffer @a buf
* The qse_mbsxput() function copies the string @a str into the buffer @a buf
* of the size @a bsz. Unlike qse_strxcpy(), it does not null-terminate the
* buffer.
*/
qse_size_t qse_strxput (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str
);
qse_size_t qse_strxnput (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str,
qse_size_t len
qse_size_t qse_mbsxput (
qse_mchar_t* buf,
qse_size_t bsz,
const qse_mchar_t* str
);
/**
* The qse_strfcpy() function formats a string by position.
* The qse_wcsxput() function copies the string @a str into the buffer @a buf
* of the size @a bsz. Unlike qse_strxcpy(), it does not null-terminate the
* buffer.
*/
qse_size_t qse_wcsxput (
qse_wchar_t* buf,
qse_size_t bsz,
const qse_wchar_t* str
);
qse_size_t qse_mbsxnput (
qse_mchar_t* buf,
qse_size_t bsz,
const qse_mchar_t* str,
qse_size_t len
);
qse_size_t qse_wcsxnput (
qse_wchar_t* buf,
qse_size_t bsz,
const qse_wchar_t* str,
qse_size_t len
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strput(buf,str) qse_mbsput(buf,str)
# define qse_strxput(buf,bsz,str) qse_mbsxput(buf,bsz,str)
# define qse_strxnput(buf,bsz,str,len) qse_mbsxnput(buf,bsz,str,len)
#else
# define qse_strput(buf,str) qse_wcsput(buf,str)
# define qse_strxput(buf,bsz,str) qse_wcsxput(buf,bsz,str)
# define qse_strxnput(buf,bsz,str,len) qse_wcsxnput(buf,bsz,str,len)
#endif
/**
* The qse_mbsfcpy() function formats a string by position.
* The position specifier is a number enclosed in ${ and }.
* When ${ is preceeded by a backslash, it is treated literally.
* See the example below:
* @code
* qse_char_t buf[256]
* qse_char_t* colors[] = { QSE_T("blue"), QSE_T("green"), QSE_T("red") };
* qse_strfcpy(buf, QSE_T("RGB: ${2}, ${1}, ${0}"), colors);
* qse_char_t* colors[] = { QSE_MT("blue"), QSE_MT("green"), QSE_MT("red") };
* qse_mbsfcpy(buf, QSE_MT("RGB: ${2}, ${1}, ${0}"), colors);
* @endcode
* @sa qse_strfncpy, qse_strxfcpy, qse_strxfncpy
* @sa qse_mbsfncpy, qse_mbsxfcpy, qse_mbsxfncpy
*/
qse_size_t qse_strfcpy (
qse_char_t* buf,
const qse_char_t* fmt,
const qse_char_t* str[]
qse_size_t qse_mbsfcpy (
qse_mchar_t* buf,
const qse_mchar_t* fmt,
const qse_mchar_t* str[]
);
/**
* The qse_strfncpy() function formats a string by position.
* It differs from qse_strfcpy() in that @a str is an array of the
* #qse_cstr_t type.
* @sa qse_strfcpy, qse_strxfcpy, qse_strxfncpy
* The qse_wcsfcpy() function formats a string by position.
* The position specifier is a number enclosed in ${ and }.
* When ${ is preceeded by a backslash, it is treated literally.
* See the example below:
* @code
* qse_char_t buf[256]
* qse_char_t* colors[] = { QSE_WT("blue"), QSE_WT("green"), QSE_WT("red") };
* qse_wcsfcpy(buf, QSE_WT("RGB: ${2}, ${1}, ${0}"), colors);
* @endcode
* @sa qse_wcsfncpy, qse_wcsxfcpy, qse_wcsxfncpy
*/
qse_size_t qse_strfncpy (
qse_char_t* buf,
const qse_char_t* fmt,
const qse_cstr_t str[]
qse_size_t qse_wcsfcpy (
qse_wchar_t* buf,
const qse_wchar_t* fmt,
const qse_wchar_t* str[]
);
/**
* The qse_strxfcpy() function formats a string by position.
* The qse_mbsfncpy() function formats a string by position.
* It differs from qse_mbsfcpy() in that @a str is an array of the
* #qse_mcstr_t type.
* @sa qse_mbsfcpy, qse_mbsxfcpy, qse_mbsxfncpy
*/
qse_size_t qse_mbsfncpy (
qse_mchar_t* buf,
const qse_mchar_t* fmt,
const qse_mcstr_t str[]
);
/**
* The qse_wcsfncpy() function formats a string by position.
* It differs from qse_wcsfcpy() in that @a str is an array of the
* #qse_wcstr_t type.
* @sa qse_wcsfcpy, qse_wcsxfcpy, qse_wcsxfncpy
*/
qse_size_t qse_wcsfncpy (
qse_wchar_t* buf,
const qse_wchar_t* fmt,
const qse_wcstr_t str[]
);
/**
* The qse_mbsxfcpy() function formats a string by position.
* It differs from qse_strfcpy() in that @a buf is length-bounded of @a bsz
* characters.
* @code
* qse_char_t buf[256]
* qse_char_t* colors[] = { QSE_T("blue"), QSE_T("green"), QSE_T("red") };
* qse_strxfcpy(buf, QSE_COUNTOF(buf), QSE_T("RGB: ${2}, ${1}, ${0}"), colors);
* qse_mchar_t buf[256]
* qse_mchar_t* colors[] = { QSE_MT("blue"), QSE_MT("green"), QSE_MT("red") };
* qse_mbsxfcpy(buf, QSE_COUNTOF(buf), QSE_MT("RGB: ${2}, ${1}, ${0}"), colors);
* @endcode
* @sa qse_strfcpy, qse_strfncpy, qse_strxfncpy
* @sa qse_mbsfcpy, qse_mbsfncpy, qse_mbsxfncpy
*/
qse_size_t qse_strxfcpy (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* fmt,
const qse_char_t* str[]
qse_size_t qse_mbsxfcpy (
qse_mchar_t* buf,
qse_size_t bsz,
const qse_mchar_t* fmt,
const qse_mchar_t* str[]
);
/**
* The qse_strxfncpy() function formats a string by position.
* It differs from qse_strfcpy() in that @a buf is length-bounded of @a bsz
* characters and @a str is an array of the #qse_cstr_t type.
* @sa qse_strfcpy, qse_strfncpy, qse_strxfcpy
* The qse_wcsxfcpy() function formats a string by position.
* It differs from qse_wcsfcpy() in that @a buf is length-bounded of @a bsz
* characters.
* @code
* qse_char_t buf[256]
* qse_char_t* colors[] = { QSE_WT("blue"), QSE_WT("green"), QSE_WT("red") };
* qse_wcsxfcpy(buf, QSE_COUNTOF(buf), QSE_WT("RGB: ${2}, ${1}, ${0}"), colors);
* @endcode
* @sa qse_wcsfcpy, qse_wcsfncpy, qse_wcsxfncpy
*/
qse_size_t qse_strxfncpy (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* fmt,
const qse_cstr_t str[]
qse_size_t qse_wcsxfcpy (
qse_wchar_t* buf,
qse_size_t bsz,
const qse_wchar_t* fmt,
const qse_wchar_t* str[]
);
/**
* The qse_mbsxfncpy() function formats a string by position.
* It differs from qse_strfcpy() in that @a buf is length-bounded of @a bsz
* characters and @a str is an array of the #qse_mcstr_t type.
* @sa qse_mbsfcpy, qse_mbsfncpy, qse_mbsxfcpy
*/
qse_size_t qse_mbsxfncpy (
qse_mchar_t* buf,
qse_size_t bsz,
const qse_mchar_t* fmt,
const qse_mcstr_t str[]
);
/**
* The qse_wcsxfncpy() function formats a string by position.
* It differs from qse_strfcpy() in that @a buf is length-bounded of @a bsz
* characters and @a str is an array of the #qse_wcstr_t type.
* @sa qse_wcsfcpy, qse_wcsfncpy, qse_wcsxfcpy
*/
qse_size_t qse_wcsxfncpy (
qse_wchar_t* buf,
qse_size_t bsz,
const qse_wchar_t* fmt,
const qse_wcstr_t str[]
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strfcpy(buf,fmt,str) qse_mbsfcpy(buf,fmt,str)
# define qse_strfncpy(buf,fmt,str) qse_mbsfncpy(buf,fmt,str)
# define qse_strxfcpy(buf,bsz,fmt,str) qse_mbsxfcpy(buf,bsz,fmt,str)
# define qse_strxfncpy(buf,bsz,fmt,str) qse_mbsxfncpy(buf,bsz,fmt,str)
#else
# define qse_strfcpy(buf,fmt,str) qse_wcsfcpy(buf,fmt,str)
# define qse_strfncpy(buf,fmt,str) qse_wcsfncpy(buf,fmt,str)
# define qse_strxfcpy(buf,bsz,fmt,str) qse_wcsxfcpy(buf,bsz,fmt,str)
# define qse_strxfncpy(buf,bsz,fmt,str) qse_wcsxfncpy(buf,bsz,fmt,str)
#endif
/**
* The qse_strxsubst() function expands @a fmt into a buffer @a buf of the size
* @a bsz by substituting new values for ${} segments within it. The actual

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 402 2011-03-18 15:07:21Z hyunghwan.chung $
* $Id: types.h 411 2011-03-24 14:20:55Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -345,7 +345,7 @@ typedef int qse_mcint_t;
typedef wchar_t qse_wcint_t;
/* all the way down from here for C */
#elif defined(__WCHAR_TYPE__) && defined(__WINT_TYPE__)
#elif defined(__GNUC__) && defined(__WCHAR_TYPE__) && defined(__WINT_TYPE__)
typedef __WCHAR_TYPE__ qse_wchar_t;
typedef __WINT_TYPE__ qse_wcint_t;
#elif (QSE_SIZEOF_WCHAR_T == 2) || (QSE_SIZEOF_WCHAR_T == 0)
@ -396,12 +396,12 @@ typedef int qse_mcint_t;
* The qse_cint_t typep defines a type that can hold a qse_char_t value and
* #QSE_CHAR_EOF.
*/
#if defined(QSE_CHAR_IS_WCHAR)
typedef qse_wchar_t qse_char_t;
typedef qse_wcint_t qse_cint_t;
#elif defined(QSE_CHAR_IS_MCHAR)
#if defined(QSE_CHAR_IS_MCHAR)
typedef qse_mchar_t qse_char_t;
typedef qse_mcint_t qse_cint_t;
#elif defined(QSE_CHAR_IS_WCHAR)
typedef qse_wchar_t qse_char_t;
typedef qse_wcint_t qse_cint_t;
#else
/* If the character type is not determined in the conf_xxx files */
@ -431,29 +431,62 @@ typedef int qse_mcint_t;
#endif
/**
* The qse_xstr_t type defines a structure combining a pointer to a character
* The qse_mxstr_t type defines a structure combining a pointer to a character
* string and the number of characters. It is designed to be interchangeable
* with the #qse_cstr_t type except the constness on the @a ptr field.
* with the #qse_mcstr_t type except the constness on the @a ptr field.
*/
struct qse_xstr_t
struct qse_mxstr_t
{
qse_char_t* ptr; /**< pointer to a character string */
qse_size_t len; /**< the number of characters */
qse_mchar_t* ptr; /**< pointer to a character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_xstr_t qse_xstr_t;
typedef struct qse_mxstr_t qse_mxstr_t;
/**
* The qse_cstr_t type defines a structure combining a pointer to
* The qse_wxstr_t type defines a structure combining a pointer to a character
* string and the number of characters. It is designed to be interchangeable
* with the #qse_wcstr_t type except the constness on the @a ptr field.
*/
struct qse_wxstr_t
{
qse_wchar_t* ptr; /**< pointer to a character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_wxstr_t qse_wxstr_t;
/**
* The qse_mcstr_t type defines a structure combining a pointer to
* a constant character string and the number of characters.
* It is designed to be interchangeable with the #qse_xstr_t type
* It is designed to be interchangeable with the #qse_mxstr_t type
* except the constness on the @a ptr field.
*/
struct qse_cstr_t
struct qse_mcstr_t
{
const qse_char_t* ptr; /**< pointer to a const character string */
qse_size_t len; /**< the number of characters */
const qse_mchar_t* ptr; /**< pointer to a const character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_cstr_t qse_cstr_t;
typedef struct qse_mcstr_t qse_mcstr_t;
/**
* The qse_wcstr_t type defines a structure combining a pointer to
* a constant character string and the number of characters.
* It is designed to be interchangeable with the #qse_wxstr_t type
* except the constness on the @a ptr field.
*/
struct qse_wcstr_t
{
const qse_wchar_t* ptr; /**< pointer to a const character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_wcstr_t qse_wcstr_t;
#if defined(QSE_CHAR_IS_MCHAR)
typedef qse_mxstr_t qse_xstr_t;
typedef qse_mcstr_t qse_cstr_t;
#else
typedef qse_wxstr_t qse_xstr_t;
typedef qse_wcstr_t qse_cstr_t;
#endif
/**
* allocate a memory chunk of the size @a n.

View File

@ -9,7 +9,8 @@ lib_LTLIBRARIES = libqsecmn.la
libqsecmn_la_SOURCES = \
syscall.h mem.h \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_fcpy.c \
str_pbrk.c str_put.c str_spn.c str_utl.c \
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \
tio.c tio_get.c tio_put.c \
fio.c pio.c sio.c \

View File

@ -73,10 +73,10 @@ am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsecmn_la_DEPENDENCIES =
am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \
rex.lo str_bas.lo str_cnv.lo str_dyn.lo str_pbrk.lo str_spn.lo \
str_utl.lo lda.lo oht.lo htb.lo rbt.lo sll.lo gdl.lo dll.lo \
opt.lo tio.lo tio_get.lo tio_put.lo fio.lo pio.lo sio.lo \
alg_search.lo alg_sort.lo time.lo misc.lo assert.lo main.lo \
rex.lo str_bas.lo str_cnv.lo str_dyn.lo str_fcpy.lo str_pbrk.lo \
str_put.lo str_spn.lo str_utl.lo lda.lo oht.lo htb.lo rbt.lo sll.lo \
gdl.lo dll.lo opt.lo tio.lo tio_get.lo tio_put.lo fio.lo pio.lo \
sio.lo alg_search.lo alg_sort.lo time.lo misc.lo assert.lo main.lo \
stdio.lo
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@ -265,7 +265,8 @@ lib_LTLIBRARIES = libqsecmn.la $(am__append_1)
libqsecmn_la_SOURCES = \
syscall.h mem.h \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_fcpy.c \
str_pbrk.c str_put.c str_spn.c str_utl.c \
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \
tio.c tio_get.c tio_put.c \
fio.c pio.c sio.c \
@ -386,7 +387,9 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_dyn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_fcpy.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_pbrk.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_put.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_spn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_utl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@

View File

@ -1,5 +1,5 @@
/*
* $Id: str_bas.c 410 2011-03-23 15:07:24Z hyunghwan.chung $
* $Id: str_bas.c 411 2011-03-24 14:20:55Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -43,264 +43,6 @@ qse_size_t qse_strbytes (const qse_char_t* str)
return (p - str) * QSE_SIZEOF(qse_char_t);
}
qse_size_t qse_strxput (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str)
{
qse_char_t* p, * p2;
p = buf; p2 = buf + bsz;
while (p < p2)
{
if (*str == QSE_T('\0')) break;
*p++ = *str++;
}
return p - buf;
}
qse_size_t qse_strxnput (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len)
{
qse_char_t* p, * p2;
const qse_char_t* end;
p = buf; p2 = buf + bsz; end = str + len;
while (p < p2)
{
if (str >= end) break;
*p++ = *str++;
}
return p - buf;
}
qse_size_t qse_strfcpy (
qse_char_t* buf, const qse_char_t* fmt, const qse_char_t* str[])
{
qse_char_t* b = buf;
const qse_char_t* f = fmt;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_T('\0')) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strfncpy (
qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t str[])
{
qse_char_t* b = buf;
const qse_char_t* f = fmt;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_T('\0')) f++;
}
else if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxfcpy (
qse_char_t* buf, qse_size_t bsz,
const qse_char_t* fmt, const qse_char_t* str[])
{
qse_char_t* b = buf;
qse_char_t* end = buf + bsz - 1;
const qse_char_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_T('\0')) f++;
}
else if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_T('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxfncpy (
qse_char_t* buf, qse_size_t bsz,
const qse_char_t* fmt, const qse_cstr_t str[])
{
qse_char_t* b = buf;
qse_char_t* end = buf + bsz - 1;
const qse_char_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_T('\0')) f++;
}
else if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
const qse_char_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxsubst (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt,
qse_strxsubst_subst_t subst, void* ctx)

View File

@ -1,5 +1,5 @@
/*
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.

471
qse/lib/cmn/str_fcpy.c Normal file
View File

@ -0,0 +1,471 @@
/*
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/str.h>
qse_size_t qse_mbsfcpy (
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mchar_t* str[])
{
qse_mchar_t* b = buf;
const qse_mchar_t* f = fmt;
while (*f != QSE_MT('\0'))
{
if (*f == QSE_MT('$'))
{
if (f[1] == QSE_MT('{') &&
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
{
const qse_mchar_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_MT('0'));
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
if (*f != QSE_MT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_MT('\0')) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_MT('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_MT('\0');
return b - buf;
}
qse_size_t qse_mbsfncpy (
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mcstr_t str[])
{
qse_mchar_t* b = buf;
const qse_mchar_t* f = fmt;
while (*f != QSE_MT('\0'))
{
if (*f == QSE_MT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_MT('\0')) f++;
}
else if (*f == QSE_MT('$'))
{
if (f[1] == QSE_MT('{') &&
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
{
const qse_mchar_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_MT('0'));
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
if (*f != QSE_MT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_MT('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_MT('\0');
return b - buf;
}
qse_size_t qse_mbsxfcpy (
qse_mchar_t* buf, qse_size_t bsz,
const qse_mchar_t* fmt, const qse_mchar_t* str[])
{
qse_mchar_t* b = buf;
qse_mchar_t* end = buf + bsz - 1;
const qse_mchar_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_MT('\0'))
{
if (*f == QSE_MT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_MT('\0')) f++;
}
else if (*f == QSE_MT('$'))
{
if (f[1] == QSE_MT('{') &&
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
{
const qse_mchar_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_MT('0'));
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
if (*f != QSE_MT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_MT('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_MT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_MT('\0');
return b - buf;
}
qse_size_t qse_mbsxfncpy (
qse_mchar_t* buf, qse_size_t bsz,
const qse_mchar_t* fmt, const qse_mcstr_t str[])
{
qse_mchar_t* b = buf;
qse_mchar_t* end = buf + bsz - 1;
const qse_mchar_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_MT('\0'))
{
if (*f == QSE_MT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_MT('\0')) f++;
}
else if (*f == QSE_MT('$'))
{
if (f[1] == QSE_MT('{') &&
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
{
const qse_mchar_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_MT('0'));
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
if (*f != QSE_MT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_MT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_MT('\0');
return b - buf;
}
qse_size_t qse_wcsfcpy (
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wchar_t* str[])
{
qse_wchar_t* b = buf;
const qse_wchar_t* f = fmt;
while (*f != QSE_WT('\0'))
{
if (*f == QSE_WT('$'))
{
if (f[1] == QSE_WT('{') &&
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
{
const qse_wchar_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_WT('0'));
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
if (*f != QSE_WT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_WT('\0')) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_WT('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_WT('\0');
return b - buf;
}
qse_size_t qse_wcsfncpy (
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wcstr_t str[])
{
qse_wchar_t* b = buf;
const qse_wchar_t* f = fmt;
while (*f != QSE_WT('\0'))
{
if (*f == QSE_WT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_WT('\0')) f++;
}
else if (*f == QSE_WT('$'))
{
if (f[1] == QSE_WT('{') &&
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
{
const qse_wchar_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_WT('0'));
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
if (*f != QSE_WT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_WT('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_WT('\0');
return b - buf;
}
qse_size_t qse_wcsxfcpy (
qse_wchar_t* buf, qse_size_t bsz,
const qse_wchar_t* fmt, const qse_wchar_t* str[])
{
qse_wchar_t* b = buf;
qse_wchar_t* end = buf + bsz - 1;
const qse_wchar_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_WT('\0'))
{
if (*f == QSE_WT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_WT('\0')) f++;
}
else if (*f == QSE_WT('$'))
{
if (f[1] == QSE_WT('{') &&
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
{
const qse_wchar_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_WT('0'));
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
if (*f != QSE_WT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != QSE_WT('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_WT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_WT('\0');
return b - buf;
}
qse_size_t qse_wcsxfncpy (
qse_wchar_t* buf, qse_size_t bsz,
const qse_wchar_t* fmt, const qse_wcstr_t str[])
{
qse_wchar_t* b = buf;
qse_wchar_t* end = buf + bsz - 1;
const qse_wchar_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_WT('\0'))
{
if (*f == QSE_WT('\\'))
{
// get the escaped character and treat it normally.
// if the escaper is the last character, treat it
// normally also.
if (f[1] != QSE_WT('\0')) f++;
}
else if (*f == QSE_WT('$'))
{
if (f[1] == QSE_WT('{') &&
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
{
const qse_wchar_t* tmp, * tmpend;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_WT('0'));
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
if (*f != QSE_WT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_WT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_WT('\0');
return b - buf;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.

101
qse/lib/cmn/str_put.c Normal file
View File

@ -0,0 +1,101 @@
/*
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/str.h>
qse_size_t qse_mbsput (qse_mchar_t* buf, const qse_mchar_t* str)
{
qse_mchar_t* org = buf;
while (*str != QSE_MT('\0')) *buf++ = *str++;
return buf - org;
}
qse_size_t qse_wcsput (qse_wchar_t* buf, const qse_wchar_t* str)
{
qse_wchar_t* org = buf;
while (*str != QSE_WT('\0')) *buf++ = *str++;
return buf - org;
}
qse_size_t qse_mbsxput (
qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str)
{
qse_mchar_t* p, * p2;
p = buf; p2 = buf + bsz;
while (p < p2)
{
if (*str == QSE_MT('\0')) break;
*p++ = *str++;
}
return p - buf;
}
qse_size_t qse_mbsxnput (
qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str, qse_size_t len)
{
qse_mchar_t* p, * p2;
const qse_mchar_t* end;
p = buf; p2 = buf + bsz; end = str + len;
while (p < p2)
{
if (str >= end) break;
*p++ = *str++;
}
return p - buf;
}
qse_size_t qse_wcsxput (
qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str)
{
qse_wchar_t* p, * p2;
p = buf; p2 = buf + bsz;
while (p < p2)
{
if (*str == QSE_WT('\0')) break;
*p++ = *str++;
}
return p - buf;
}
qse_size_t qse_wcsxnput (
qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str, qse_size_t len)
{
qse_wchar_t* p, * p2;
const qse_wchar_t* end;
p = buf; p2 = buf + bsz; end = str + len;
while (p < p2)
{
if (str >= end) break;
*p++ = *str++;
}
return p - buf;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.

View File

@ -42,7 +42,7 @@ WVList
0
10
WPickList
38
40
11
MItem
3
@ -548,7 +548,7 @@ WVList
123
MItem
33
..\..\..\..\..\lib\cmn\str_pbrk.c
..\..\..\..\..\lib\cmn\str_fcpy.c
124
WString
4
@ -565,8 +565,8 @@ WVList
0
127
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
33
..\..\..\..\..\lib\cmn\str_pbrk.c
128
WString
4
@ -584,7 +584,7 @@ WVList
131
MItem
32
..\..\..\..\..\lib\cmn\str_utl.c
..\..\..\..\..\lib\cmn\str_put.c
132
WString
4
@ -601,8 +601,8 @@ WVList
0
135
MItem
29
..\..\..\..\..\lib\cmn\time.c
32
..\..\..\..\..\lib\cmn\str_spn.c
136
WString
4
@ -619,8 +619,8 @@ WVList
0
139
MItem
28
..\..\..\..\..\lib\cmn\tio.c
32
..\..\..\..\..\lib\cmn\str_utl.c
140
WString
4
@ -637,8 +637,8 @@ WVList
0
143
MItem
32
..\..\..\..\..\lib\cmn\tio_get.c
29
..\..\..\..\..\lib\cmn\time.c
144
WString
4
@ -655,8 +655,8 @@ WVList
0
147
MItem
32
..\..\..\..\..\lib\cmn\tio_put.c
28
..\..\..\..\..\lib\cmn\tio.c
148
WString
4
@ -673,8 +673,8 @@ WVList
0
151
MItem
28
..\..\..\..\..\lib\cmn\xma.c
32
..\..\..\..\..\lib\cmn\tio_get.c
152
WString
4
@ -691,44 +691,44 @@ WVList
0
155
MItem
3
*.h
32
..\..\..\..\..\lib\cmn\tio_put.c
156
WString
3
NIL
4
COBJ
157
WVList
0
158
WVList
0
-1
11
1
1
0
159
MItem
28
..\..\..\..\..\lib\cmn\mem.h
..\..\..\..\..\lib\cmn\xma.c
160
WString
3
NIL
4
COBJ
161
WVList
0
162
WVList
0
155
11
1
1
0
163
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
3
*.h
164
WString
3
@ -739,7 +739,43 @@ WVList
166
WVList
0
155
-1
1
1
0
167
MItem
28
..\..\..\..\..\lib\cmn\mem.h
168
WString
3
NIL
169
WVList
0
170
WVList
0
163
1
1
0
171
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
172
WString
3
NIL
173
WVList
0
174
WVList
0
163
1
1
0

View File

@ -60,14 +60,14 @@ WRect
1680
5700
4240
1
0
0
16
WFileName
30
release/os2/lib/cmn/qsecmn.tgt
24
25
27
17
VComponent
18
@ -120,8 +120,8 @@ release/os2/lib/scm/qsescm.tgt
VComponent
27
WRect
430
320
1340
413
5700
4240
0
@ -130,8 +130,8 @@ WRect
WFileName
28
debug/os2/lib/cmn/qsecmn.tgt
19
22
21
24
29
VComponent
30
@ -180,4 +180,4 @@ WFileName
debug/os2/cmd/scm/qsescm.tgt
0
1
35
26

View File

@ -42,7 +42,7 @@ WVList
0
10
WPickList
38
40
11
MItem
3
@ -612,7 +612,7 @@ WVList
139
MItem
33
..\..\..\..\..\lib\cmn\str_pbrk.c
..\..\..\..\..\lib\cmn\str_fcpy.c
140
WString
4
@ -629,8 +629,8 @@ WVList
0
143
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
33
..\..\..\..\..\lib\cmn\str_pbrk.c
144
WString
4
@ -648,29 +648,31 @@ WVList
147
MItem
32
..\..\..\..\..\lib\cmn\str_utl.c
..\..\..\..\..\lib\cmn\str_put.c
148
WString
4
COBJ
149
WVList
1
0
150
MVState
WVList
0
11
1
1
0
151
WString
3
WCC
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
152
WString
25
o?2??Include directories:
1
4
COBJ
153
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
WVList
0
154
WVList
@ -681,32 +683,30 @@ WVList
0
155
MItem
29
..\..\..\..\..\lib\cmn\time.c
32
..\..\..\..\..\lib\cmn\str_utl.c
156
WString
4
COBJ
157
WVList
0
1
158
WVList
0
11
1
1
0
MVState
159
MItem
28
..\..\..\..\..\lib\cmn\tio.c
WString
3
WCC
160
WString
4
COBJ
25
o?2??Include directories:
1
161
WVList
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0
162
WVList
@ -717,8 +717,8 @@ WVList
0
163
MItem
32
..\..\..\..\..\lib\cmn\tio_get.c
29
..\..\..\..\..\lib\cmn\time.c
164
WString
4
@ -735,8 +735,8 @@ WVList
0
167
MItem
32
..\..\..\..\..\lib\cmn\tio_put.c
28
..\..\..\..\..\lib\cmn\tio.c
168
WString
4
@ -753,8 +753,8 @@ WVList
0
171
MItem
28
..\..\..\..\..\lib\cmn\xma.c
32
..\..\..\..\..\lib\cmn\tio_get.c
172
WString
4
@ -771,44 +771,44 @@ WVList
0
175
MItem
3
*.h
32
..\..\..\..\..\lib\cmn\tio_put.c
176
WString
3
NIL
4
COBJ
177
WVList
0
178
WVList
0
-1
11
1
1
0
179
MItem
28
..\..\..\..\..\lib\cmn\mem.h
..\..\..\..\..\lib\cmn\xma.c
180
WString
3
NIL
4
COBJ
181
WVList
0
182
WVList
0
175
11
1
1
0
183
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
3
*.h
184
WString
3
@ -819,7 +819,43 @@ WVList
186
WVList
0
175
-1
1
1
0
187
MItem
28
..\..\..\..\..\lib\cmn\mem.h
188
WString
3
NIL
189
WVList
0
190
WVList
0
183
1
1
0
191
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
192
WString
3
NIL
193
WVList
0
194
WVList
0
183
1
1
0