string.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file string.h
00024  * \version $Id: string.h 1856 2007-08-23 01:58:58Z edmanm $
00025  * \brief Common string manipulation functions
00026  */
00027 
00028 #ifndef __STRING_H
00029 #define __STRING_H
00030 
00031 #include <QStringList>
00032 #include <QHash>
00033 
00034 
00035 /** Creates a QStringList from the array of C strings. */
00036 QStringList char_array_to_stringlist(char **arr, int len);
00037 
00038 /** Ensures all characters in str are in validChars. If a character appears
00039  * in str but not in validChars, it will be removed and the resulting
00040  * string returned. */
00041 QString ensure_valid_chars(QString str, QString validChars);
00042 
00043 /** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
00044 QString scrub_email_addr(QString email);
00045 
00046 /** Conditionally assigns errmsg to string if str is not null and returns
00047  * false. */
00048 bool err(QString *str, QString errmsg);
00049 
00050 /** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the
00051  * word separator (" ", for example), and placing the line ending <b>le</b> at
00052  * the end of each line, except the last.*/
00053 QString string_wrap(QString str, int width, QString sep, QString le);
00054 
00055 /** Encodes the bytes in <b>buf</b> as an uppercase hexadecimal string and
00056  * returns the result. This function is derived from base16_encode() in Tor's
00057  * util.c. See LICENSE for details on Tor's license. */
00058 QString base16_encode(const QByteArray buf);
00059 
00060 /** Given a string <b>str</b>, this function returns a quoted string with all
00061  * '"' and '\' characters escaped with a single '\'. */
00062 QString string_escape(const QString str);
00063 
00064 /** Given a quoted string <b>str</b>, this function returns an unquoted,
00065  * unescaped string. <b>str</b> must start and end with an unescaped quote. */
00066 QString string_unescape(const QString str, bool *ok = 0);
00067 
00068 /** Parses a series of space-separated key[=value|="value"] tokens from
00069  * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable
00070  * to be parsed, <b>ok</b> is set to false. */
00071 QHash<QString,QString> string_parse_keyvals(const QString str, bool *ok = 0);
00072 
00073 #endif
00074 

Generated on Wed Sep 5 15:49:28 2007 for Vidalia by  doxygen 1.5.3