stringutil.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file stringutil.h
00013 ** \version $Id: stringutil.h 2486 2008-04-05 14:43:08Z edmanm $
00014 ** \brief Common string manipulation functions
00015 */
00016 
00017 #ifndef _STRINGUTIL_H
00018 #define _STRINGUTIL_H
00019 
00020 #include <QStringList>
00021 #include <QHash>
00022 
00023 
00024 /** Creates a QStringList from the array of C strings. */
00025 QStringList char_array_to_stringlist(char **arr, int len);
00026 
00027 /** Ensures all characters in str are in validChars. If a character appears
00028  * in str but not in validChars, it will be removed and the resulting
00029  * string returned. */
00030 QString ensure_valid_chars(const QString &str, const QString &validChars);
00031 
00032 /** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
00033 QString scrub_email_addr(const QString &email);
00034 
00035 /** Conditionally assigns errmsg to string if str is not null and returns
00036  * false. */
00037 bool err(QString *str, const QString &errmsg);
00038 
00039 /** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the
00040  * word separator (" ", for example), and placing the line ending <b>le</b> at
00041  * the end of each line, except the last.*/
00042 QString string_wrap(const QString &str, int width, 
00043                     const QString &sep, const QString &le);
00044 
00045 /** Encodes the bytes in <b>buf</b> as an uppercase hexadecimal string and
00046  * returns the result. This function is derived from base16_encode() in Tor's
00047  * util.c. See LICENSE for details on Tor's license. */
00048 QString base16_encode(const QByteArray &buf);
00049 
00050 /** Given a string <b>str</b>, this function returns a quoted string with all
00051  * '"' and '\' characters escaped with a single '\'. */
00052 QString string_escape(const QString &str);
00053 
00054 /** Given a quoted string <b>str</b>, this function returns an unquoted,
00055  * unescaped string. <b>str</b> must start and end with an unescaped quote. */
00056 QString string_unescape(const QString &str, bool *ok = 0);
00057 
00058 /** Parses a series of space-separated key[=value|="value"] tokens from
00059  * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable
00060  * to be parsed, <b>ok</b> is set to false. */
00061 QHash<QString,QString> string_parse_keyvals(const QString &str, bool *ok = 0);
00062 
00063 /** Parses a series of command line arguments from <b>str</b>. If <b>str</b>
00064  * was unable to be parsed, <b>ok</b> is set to false. */
00065 QStringList string_parse_arguments(const QString &str, bool *ok = 0);
00066 
00067 /** Formats the list of command line arguments in <b>args</b> as a string.
00068  * Arguments that contain ' ', '\', or '"' tokens will be escaped and wrapped
00069  * in double quotes. */
00070 QString string_format_arguments(const QStringList &args);
00071 
00072 /** Returns true if <b>str</b> is a valid hexademical string. Returns false
00073  * otherwise. */
00074 bool string_is_hex(const QString &str);
00075 
00076 #endif
00077 

Generated on Tue Jul 7 17:00:56 2009 for Vidalia by  doxygen 1.4.7