2011-03-30 05:20:29 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2011-03-30 05:20:29 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2011-03-30 05:20:29 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
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.
|
2011-03-30 05:20:29 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
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.
|
2011-03-30 05:20:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qse/cmn/str.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "mem-prv.h"
|
2011-03-30 05:20:29 +00:00
|
|
|
|
|
|
|
qse_mchar_t* qse_mbsdup (const qse_mchar_t* str, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_mchar_t* tmp;
|
|
|
|
|
2011-06-23 10:17:35 +00:00
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
tmp = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (qse_mbslen(str)+1)*QSE_SIZEOF(qse_mchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_mbscpy (tmp, str);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_mchar_t* qse_mbsdup2 (
|
|
|
|
const qse_mchar_t* str1, const qse_mchar_t* str2, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
return qse_mbsxdup2 (
|
|
|
|
str1, qse_mbslen(str1), str2, qse_mbslen(str2), mmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_mchar_t* qse_mbsxdup (
|
|
|
|
const qse_mchar_t* str, qse_size_t len, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_mchar_t* tmp;
|
|
|
|
|
|
|
|
tmp = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (len+1)*QSE_SIZEOF(qse_mchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_mbsncpy (tmp, str, len);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_mchar_t* qse_mbsxdup2 (
|
|
|
|
const qse_mchar_t* str1, qse_size_t len1,
|
|
|
|
const qse_mchar_t* str2, qse_size_t len2, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_mchar_t* tmp;
|
|
|
|
|
2011-06-23 10:17:35 +00:00
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
tmp = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (len1+len2+1) * QSE_SIZEOF(qse_mchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_mbsncpy (tmp, str1, len1);
|
|
|
|
qse_mbsncpy (tmp + len1, str2, len2);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
qse_mchar_t* qse_mbsadup (const qse_mchar_t* str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
2011-10-15 23:18:55 +00:00
|
|
|
{
|
|
|
|
qse_mchar_t* buf, * ptr;
|
|
|
|
qse_size_t i;
|
|
|
|
qse_size_t capa = 0;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
for (i = 0; str[i]; i++) capa += qse_mbslen(str[i]);
|
|
|
|
|
|
|
|
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
ptr = buf;
|
|
|
|
for (i = 0; str[i]; i++) ptr += qse_mbscpy (ptr, str[i]);
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
if (len) *len = capa;
|
2011-10-15 23:18:55 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_mchar_t* qse_mcstrdup (const qse_mcstr_t* str, qse_mmgr_t* mmgr)
|
2012-10-28 14:46:37 +00:00
|
|
|
{
|
|
|
|
qse_mchar_t* buf;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (str->len + 1) * QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_mbsncpy (buf, str->ptr, str->len);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_mchar_t* qse_mcstradup (const qse_mcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
|
|
|
qse_mchar_t* buf, * ptr;
|
|
|
|
qse_size_t i;
|
|
|
|
qse_size_t capa = 0;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
for (i = 0; str[i].ptr; i++) capa += str[i].len;
|
|
|
|
|
|
|
|
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
ptr = buf;
|
|
|
|
for (i = 0; str[i].ptr; i++) ptr += qse_mbsncpy (ptr, str[i].ptr, str[i].len);
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
if (len) *len = capa;
|
2012-09-30 13:56:20 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-10-15 23:18:55 +00:00
|
|
|
/* --------------------------------------------------------------- */
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
qse_wchar_t* qse_wcsdup (const qse_wchar_t* str, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_wchar_t* tmp;
|
|
|
|
|
2011-06-23 10:17:35 +00:00
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
tmp = (qse_wchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (qse_wcslen(str)+1)*QSE_SIZEOF(qse_wchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_wcscpy (tmp, str);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_wchar_t* qse_wcsdup2 (
|
|
|
|
const qse_wchar_t* str1, const qse_wchar_t* str2, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
return qse_wcsxdup2 (
|
|
|
|
str1, qse_wcslen(str1), str2, qse_wcslen(str2), mmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_wchar_t* qse_wcsxdup (
|
|
|
|
const qse_wchar_t* str, qse_size_t len, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_wchar_t* tmp;
|
|
|
|
|
2011-06-23 10:17:35 +00:00
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
tmp = (qse_wchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (len+1)*QSE_SIZEOF(qse_wchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_wcsncpy (tmp, str, len);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_wchar_t* qse_wcsxdup2 (
|
|
|
|
const qse_wchar_t* str1, qse_size_t len1,
|
|
|
|
const qse_wchar_t* str2, qse_size_t len2, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
qse_wchar_t* tmp;
|
|
|
|
|
2011-06-23 10:17:35 +00:00
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
2011-03-30 05:20:29 +00:00
|
|
|
tmp = (qse_wchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (len1+len2+1) * QSE_SIZEOF(qse_wchar_t));
|
|
|
|
if (tmp == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_wcsncpy (tmp, str1, len1);
|
|
|
|
qse_wcsncpy (tmp + len1, str2, len2);
|
|
|
|
return tmp;
|
|
|
|
}
|
2011-10-15 23:18:55 +00:00
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
qse_wchar_t* qse_wcsadup (const qse_wchar_t* str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
2011-10-15 23:18:55 +00:00
|
|
|
{
|
|
|
|
qse_wchar_t* buf, * ptr;
|
|
|
|
qse_size_t i;
|
|
|
|
qse_size_t capa = 0;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
for (i = 0; str[i]; i++) capa += qse_wcslen(str[i]);
|
|
|
|
|
|
|
|
buf = (qse_wchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
ptr = buf;
|
|
|
|
for (i = 0; str[i]; i++) ptr += qse_wcscpy (ptr, str[i]);
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
if (len) *len = capa;
|
2011-10-15 23:18:55 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_wchar_t* qse_wcstrdup (const qse_wcstr_t* str, qse_mmgr_t* mmgr)
|
2012-10-28 14:46:37 +00:00
|
|
|
{
|
|
|
|
qse_wchar_t* buf;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
buf = (qse_wchar_t*) QSE_MMGR_ALLOC (
|
|
|
|
mmgr, (str->len + 1) * QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
qse_wcsncpy (buf, str->ptr, str->len);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_wchar_t* qse_wcstradup (const qse_wcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
|
|
|
qse_wchar_t* buf, * ptr;
|
|
|
|
qse_size_t i;
|
|
|
|
qse_size_t capa = 0;
|
|
|
|
|
|
|
|
QSE_ASSERT (mmgr != QSE_NULL);
|
|
|
|
|
|
|
|
for (i = 0; str[i].ptr; i++) capa += str[i].len;
|
|
|
|
|
|
|
|
buf = (qse_wchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
|
|
|
|
if (buf == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
ptr = buf;
|
|
|
|
for (i = 0; str[i].ptr; i++) ptr += qse_wcsncpy (ptr, str[i].ptr, str[i].len);
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
if (len) *len = capa;
|
2012-09-30 13:56:20 +00:00
|
|
|
return buf;
|
|
|
|
}
|