reorganized strjoin and related functions
added qse_thr_t
This commit is contained in:
@ -15,6 +15,7 @@ noinst_HEADERS = \
|
||||
fs.h \
|
||||
glob.h \
|
||||
mem.h \
|
||||
str-cat.h \
|
||||
str-dyn.h \
|
||||
str-fcpy.h \
|
||||
str-fmt.h \
|
||||
|
@ -458,6 +458,7 @@ noinst_HEADERS = \
|
||||
fs.h \
|
||||
glob.h \
|
||||
mem.h \
|
||||
str-cat.h \
|
||||
str-dyn.h \
|
||||
str-fcpy.h \
|
||||
str-fmt.h \
|
||||
|
@ -26,162 +26,42 @@
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
qse_size_t qse_mbscat (qse_mchar_t* buf, const qse_mchar_t* str)
|
||||
{
|
||||
qse_mchar_t* org = buf;
|
||||
buf += qse_mbslen(buf);
|
||||
while ((*buf++ = *str++) != QSE_MT('\0'));
|
||||
return buf - org - 1;
|
||||
}
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef strcat
|
||||
#undef strncat
|
||||
#undef strcatn
|
||||
#undef strxcat
|
||||
#undef strxncat
|
||||
#undef strlen
|
||||
|
||||
qse_size_t qse_mbsncat (qse_mchar_t* buf, const qse_mchar_t* str, qse_size_t len)
|
||||
{
|
||||
qse_size_t x;
|
||||
const qse_mchar_t* end = str + len;
|
||||
#define T(x) QSE_MT(x)
|
||||
#define char_t qse_mchar_t
|
||||
#define strcat qse_mbscat
|
||||
#define strncat qse_mbsncat
|
||||
#define strcatn qse_mbscatn
|
||||
#define strxcat qse_mbsxcat
|
||||
#define strxncat qse_mbsxncat
|
||||
#define strlen qse_mbslen
|
||||
#include "str-cat.h"
|
||||
|
||||
x = qse_mbslen(buf); buf += x;
|
||||
while (str < end) *buf++ = *str++;
|
||||
*buf = QSE_MT('\0');
|
||||
return len + x;
|
||||
}
|
||||
/* ----------------------------------- */
|
||||
|
||||
qse_size_t qse_mbscatn (qse_mchar_t* buf, const qse_mchar_t* str, qse_size_t n)
|
||||
{
|
||||
qse_size_t x;
|
||||
qse_mchar_t* org = buf;
|
||||
const qse_mchar_t* end = str + n;
|
||||
|
||||
x = qse_mbslen(buf); buf += x;
|
||||
while (str < end)
|
||||
{
|
||||
if ((*buf++ = *str++) == QSE_MT('\0')) return buf - org - 1;
|
||||
}
|
||||
return n + x;
|
||||
}
|
||||
|
||||
|
||||
qse_size_t qse_mbsxcat (qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str)
|
||||
{
|
||||
qse_mchar_t* p, * p2;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = qse_mbslen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == QSE_MT('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = QSE_MT('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxncat (
|
||||
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;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = qse_mbslen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = QSE_MT('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcscat (qse_wchar_t* buf, const qse_wchar_t* str)
|
||||
{
|
||||
qse_wchar_t* org = buf;
|
||||
buf += qse_wcslen(buf);
|
||||
while ((*buf++ = *str++) != QSE_WT('\0'));
|
||||
return buf - org - 1;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsncat (qse_wchar_t* buf, const qse_wchar_t* str, qse_size_t len)
|
||||
{
|
||||
qse_size_t x;
|
||||
const qse_wchar_t* end = str + len;
|
||||
|
||||
x = qse_wcslen(buf); buf += x;
|
||||
while (str < end) *buf++ = *str++;
|
||||
*buf = QSE_WT('\0');
|
||||
return len + x;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcscatn (qse_wchar_t* buf, const qse_wchar_t* str, qse_size_t n)
|
||||
{
|
||||
qse_size_t x;
|
||||
qse_wchar_t* org = buf;
|
||||
const qse_wchar_t* end = str + n;
|
||||
|
||||
x = qse_wcslen(buf); buf += x;
|
||||
while (str < end)
|
||||
{
|
||||
if ((*buf++ = *str++) == QSE_WT('\0')) return buf - org - 1;
|
||||
}
|
||||
return n + x;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxcat (qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str)
|
||||
{
|
||||
qse_wchar_t* p, * p2;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = qse_wcslen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == QSE_WT('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = QSE_WT('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxncat (
|
||||
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;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = qse_wcslen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = QSE_WT('\0');
|
||||
return p - buf;
|
||||
}
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef strcat
|
||||
#undef strncat
|
||||
#undef strcatn
|
||||
#undef strxcat
|
||||
#undef strxncat
|
||||
#undef strlen
|
||||
|
||||
#define T(x) QSE_WT(x)
|
||||
#define char_t qse_wchar_t
|
||||
#define strcat qse_wcscat
|
||||
#define strncat qse_wcsncat
|
||||
#define strcatn qse_wcscatn
|
||||
#define strxcat qse_wcsxcat
|
||||
#define strxncat qse_wcsxncat
|
||||
#define strlen qse_wcslen
|
||||
#include "str-cat.h"
|
||||
|
109
qse/lib/cmn/str-cat.h
Normal file
109
qse/lib/cmn/str-cat.h
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if !defined(char_t) && !defined(strcat) && !defined(strxcat)
|
||||
# error Never include this file
|
||||
#endif
|
||||
|
||||
qse_size_t strcat (char_t* buf, const char_t* str)
|
||||
{
|
||||
char_t* org = buf;
|
||||
buf += strlen(buf);
|
||||
while ((*buf++ = *str++) != T('\0'));
|
||||
return buf - org - 1;
|
||||
}
|
||||
|
||||
qse_size_t strncat (char_t* buf, const char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_size_t x;
|
||||
const char_t* end = str + len;
|
||||
|
||||
x = strlen(buf); buf += x;
|
||||
while (str < end) *buf++ = *str++;
|
||||
*buf = T('\0');
|
||||
return len + x;
|
||||
}
|
||||
|
||||
qse_size_t strcatn (char_t* buf, const char_t* str, qse_size_t n)
|
||||
{
|
||||
qse_size_t x;
|
||||
char_t* org = buf;
|
||||
const char_t* end = str + n;
|
||||
|
||||
x = strlen(buf); buf += x;
|
||||
while (str < end)
|
||||
{
|
||||
/* copies not more than n characters and stop if '\0' is met */
|
||||
if ((*buf++ = *str++) == T('\0')) return buf - org - 1;
|
||||
}
|
||||
return n + x;
|
||||
}
|
||||
|
||||
qse_size_t strxcat (char_t* buf, qse_size_t bsz, const char_t* str)
|
||||
{
|
||||
char_t* p, * p2;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = strlen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == T('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t strxncat (char_t* buf, qse_size_t bsz, const char_t* str, qse_size_t len)
|
||||
{
|
||||
char_t* p, * p2;
|
||||
const char_t* end;
|
||||
qse_size_t blen;
|
||||
|
||||
blen = strlen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
@ -24,8 +24,7 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
qse_size_t strfcpy (
|
||||
char_t* buf, const char_t* fmt, const char_t* str[])
|
||||
qse_size_t strfcpy (char_t* buf, const char_t* fmt, const char_t* str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
const char_t* f = fmt;
|
||||
@ -69,8 +68,7 @@ qse_size_t strfcpy (
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strfncpy (
|
||||
char_t* buf, const char_t* fmt, const cstr_t str[])
|
||||
qse_size_t strfncpy (char_t* buf, const char_t* fmt, const cstr_t str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
const char_t* f = fmt;
|
||||
@ -123,9 +121,7 @@ qse_size_t strfncpy (
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strxfcpy (
|
||||
char_t* buf, qse_size_t bsz,
|
||||
const char_t* fmt, const char_t* str[])
|
||||
qse_size_t strxfcpy (char_t* buf, qse_size_t bsz, const char_t* fmt, const char_t* str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
char_t* end = buf + bsz - 1;
|
||||
@ -185,9 +181,7 @@ fini:
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strxfncpy (
|
||||
char_t* buf, qse_size_t bsz,
|
||||
const char_t* fmt, const cstr_t str[])
|
||||
qse_size_t strxfncpy (char_t* buf, qse_size_t bsz, const char_t* fmt, const cstr_t str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
char_t* end = buf + bsz - 1;
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* ----------------------------------- */
|
||||
|
||||
@ -64,20 +63,3 @@
|
||||
#define strcpy qse_wcscpy
|
||||
#define strxcpy qse_wcsxcpy
|
||||
#include "str-join.h"
|
||||
|
||||
#undef char_t
|
||||
#undef strjoin
|
||||
#undef strjoinv
|
||||
#undef strxjoin
|
||||
#undef strxjoinv
|
||||
#undef strcpy
|
||||
#undef strxcpy
|
||||
|
||||
#define char_t qse_char_t
|
||||
#define strjoin qse_strjoin
|
||||
#define strjoinv qse_strjoinv
|
||||
#define strxjoin qse_strxjoin
|
||||
#define strxjoinv qse_strxjoinv
|
||||
#define strcpy qse_strcpy
|
||||
#define strxcpy qse_strxcpy
|
||||
#include "str-join.h"
|
||||
|
@ -47,7 +47,6 @@ qse_size_t strxjoinv (char_t* buf, qse_size_t size, va_list ap)
|
||||
return size - left;
|
||||
}
|
||||
|
||||
|
||||
qse_size_t strxjoin (char_t* buf, qse_size_t size, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
Reference in New Issue
Block a user