File indexing completed on 2024-05-12 17:16:25

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 http://kdesvn.alwins-world.de.           *
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 =
0059             &APR_ARRAY_IDX(apr_targets, i, const char *);
0060 
0061         m_content.push_back(QString::fromUtf8(*target));
0062     }
0063     setNull(m_content.isEmpty());
0064 }
0065 
0066 /*!
0067     \fn svn::StringArray::size()const
0068  */
0069 QStringList::size_type svn::StringArray::size()const
0070 {
0071     if (isNull()) {
0072         return 0;
0073     }
0074     return m_content.size();
0075 }
0076 
0077 const QString &svn::StringArray::operator[](QStringList::size_type which)const
0078 {
0079     return m_content[which];
0080 }
0081 
0082 QString &svn::StringArray::operator[](QStringList::size_type which)
0083 {
0084     return m_content[which];
0085 }
0086 
0087 /*!
0088     \fn svn::StringArray::array (const Pool & pool) const
0089  */
0090 apr_array_header_t *svn::StringArray::array(const Pool &pool) const
0091 {
0092     if (isNull()) {
0093         return nullptr;
0094     }
0095     QStringList::const_iterator it;
0096 
0097     apr_pool_t *apr_pool = pool.pool();
0098     apr_array_header_t *apr_targets =
0099         apr_array_make(apr_pool, m_content.size(), sizeof(const char *));
0100 
0101     for (it = m_content.begin(); it != m_content.end(); ++it) {
0102         QByteArray s = (*it).toUtf8();
0103         char *t2 = apr_pstrndup(apr_pool, s, s.size());
0104 
0105         (*((const char **) apr_array_push(apr_targets))) = t2;
0106     }
0107     return apr_targets;
0108 }
0109 
0110 bool svn::StringArray::isNull()const
0111 {
0112     return m_isNull;
0113 }
0114 
0115 void svn::StringArray::setNull(bool _n)
0116 {
0117     if (_n) {
0118         m_content.clear();
0119     }
0120     m_isNull = _n;
0121 }