File indexing completed on 2024-04-28 05:42:11
0001 /*************************************************************************** 0002 * Copyright (C) 2006-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU Lesser General Public * 0007 * License as published by the Free Software Foundation; either * 0008 * version 2.1 of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0013 * Lesser General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU Lesser General Public * 0016 * License along with this program (in the file LGPL.txt); if not, * 0017 * write to the Free Software Foundation, Inc., 51 Franklin St, * 0018 * Fifth Floor, Boston, MA 02110-1301 USA * 0019 * * 0020 * This software consists of voluntary contributions made by many * 0021 * individuals. For exact contribution history, see the revision * 0022 * history and logs, available at https://commits.kde.org/kdesvn. * 0023 ***************************************************************************/ 0024 0025 #include "stringarray.h" 0026 #include "pool.h" 0027 0028 #include <svn_types.h> 0029 // apr api 0030 #include <apr_pools.h> 0031 #include <apr_strings.h> 0032 0033 /*! 0034 \fn svn::StringArray::StringArray() 0035 */ 0036 svn::StringArray::StringArray() 0037 : m_content() 0038 { 0039 setNull(true); 0040 } 0041 0042 /*! 0043 \fn svn::StringArray::StringArray(const QStringList&) 0044 */ 0045 svn::StringArray::StringArray(const QStringList &aList) 0046 : m_content(aList) 0047 { 0048 setNull(m_content.isEmpty()); 0049 } 0050 0051 /*! 0052 \fn svn::StringArray::StringArray(const apr_array_header_t * apr_targets) 0053 */ 0054 svn::StringArray::StringArray(const apr_array_header_t *apr_targets) 0055 : m_content() 0056 { 0057 for (int i = 0; i < apr_targets->nelts; i++) { 0058 const char **target = &APR_ARRAY_IDX(apr_targets, i, const char *); 0059 0060 m_content.push_back(QString::fromUtf8(*target)); 0061 } 0062 setNull(m_content.isEmpty()); 0063 } 0064 0065 /*! 0066 \fn svn::StringArray::size()const 0067 */ 0068 QStringList::size_type svn::StringArray::size() const 0069 { 0070 if (isNull()) { 0071 return 0; 0072 } 0073 return m_content.size(); 0074 } 0075 0076 /*! 0077 \fn svn::StringArray::array (const Pool & pool) const 0078 */ 0079 apr_array_header_t *svn::StringArray::array(const Pool &pool) const 0080 { 0081 if (isNull()) { 0082 return nullptr; 0083 } 0084 apr_pool_t *apr_pool = pool.pool(); 0085 apr_array_header_t *apr_targets = apr_array_make(apr_pool, m_content.size(), sizeof(const char *)); 0086 0087 for (const QString &content : m_content) { 0088 const QByteArray s = content.toUtf8(); 0089 char *t2 = apr_pstrndup(apr_pool, s.data(), s.size()); 0090 (*((const char **)apr_array_push(apr_targets))) = t2; 0091 } 0092 return apr_targets; 0093 } 0094 0095 bool svn::StringArray::isNull() const 0096 { 0097 return m_isNull; 0098 } 0099 0100 void svn::StringArray::setNull(bool _n) 0101 { 0102 if (_n) { 0103 m_content.clear(); 0104 } 0105 m_isNull = _n; 0106 }