<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Vidalia: stringutil.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a> » <a class="el" href="dir_3459d97d61361c9d41d467fba45f9c61.html">common</a> </div> </div> <div class="contents"> <h1>stringutil.h</h1><a href="stringutil_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment">** This file is part of Vidalia, and is subject to the license terms in the</span> <a name="l00003"></a>00003 <span class="comment">** LICENSE file, found in the top level directory of this distribution. If you</span> <a name="l00004"></a>00004 <span class="comment">** did not receive the LICENSE file with this file, you may obtain it from the</span> <a name="l00005"></a>00005 <span class="comment">** Vidalia source package distributed by the Vidalia Project at</span> <a name="l00006"></a>00006 <span class="comment">** http://www.vidalia-project.net/. No part of Vidalia, including this file,</span> <a name="l00007"></a>00007 <span class="comment">** may be copied, modified, propagated, or distributed except according to the</span> <a name="l00008"></a>00008 <span class="comment">** terms described in the LICENSE file.</span> <a name="l00009"></a>00009 <span class="comment">*/</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="comment">/*</span> <a name="l00012"></a>00012 <span class="comment">** \file stringutil.h</span> <a name="l00013"></a>00013 <span class="comment">** \version $Id: stringutil.h 4085 2009-08-29 18:39:35Z edmanm $</span> <a name="l00014"></a>00014 <span class="comment">** \brief Common string manipulation functions</span> <a name="l00015"></a>00015 <span class="comment">*/</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#ifndef _STRINGUTIL_H</span> <a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _STRINGUTIL_H</span> <a name="l00019"></a>00019 <span class="preprocessor"></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <QStringList></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <QHash></span> <a name="l00022"></a>00022 <span class="preprocessor">#include <QDateTime></span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="comment"></span> <a name="l00025"></a>00025 <span class="comment">/** Creates a QStringList from the array of C strings. */</span> <a name="l00026"></a>00026 QStringList <a class="code" href="stringutil_8cpp.html#aeff472cf5de3a95aa5190d35ffd9661c">char_array_to_stringlist</a>(<span class="keywordtype">char</span> **arr, <span class="keywordtype">int</span> len); <a name="l00027"></a>00027 <span class="comment"></span> <a name="l00028"></a>00028 <span class="comment">/** Ensures all characters in str are in validChars. If a character appears</span> <a name="l00029"></a>00029 <span class="comment"> * in str but not in validChars, it will be removed and the resulting</span> <a name="l00030"></a>00030 <span class="comment"> * string returned. */</span> <a name="l00031"></a>00031 QString <a class="code" href="stringutil_8cpp.html#a3160a90d93ee7f5b4c2abebdfe4e8afc">ensure_valid_chars</a>(<span class="keyword">const</span> QString &str, <span class="keyword">const</span> QString &validChars); <a name="l00032"></a>00032 <span class="comment"></span> <a name="l00033"></a>00033 <span class="comment">/** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */</span> <a name="l00034"></a>00034 QString <a class="code" href="stringutil_8cpp.html#ad6c76e6ae682c586a541b8391b02df5d">scrub_email_addr</a>(<span class="keyword">const</span> QString &email); <a name="l00035"></a>00035 <span class="comment"></span> <a name="l00036"></a>00036 <span class="comment">/** Conditionally assigns errmsg to string if str is not null and returns</span> <a name="l00037"></a>00037 <span class="comment"> * false. */</span> <a name="l00038"></a>00038 <span class="keywordtype">bool</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>(QString *str, <span class="keyword">const</span> QString &errmsg); <a name="l00039"></a>00039 <span class="comment"></span> <a name="l00040"></a>00040 <span class="comment">/** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the</span> <a name="l00041"></a>00041 <span class="comment"> * word separator (" ", for example), and placing the line ending <b>le</b> at</span> <a name="l00042"></a>00042 <span class="comment"> * the end of each line, except the last.*/</span> <a name="l00043"></a>00043 QString <a class="code" href="stringutil_8cpp.html#a5a9147db4c941c08f95e403b9d322e9b">string_wrap</a>(<span class="keyword">const</span> QString &str, <span class="keywordtype">int</span> width, <a name="l00044"></a>00044 <span class="keyword">const</span> QString &sep = QString(<span class="stringliteral">" "</span>), <a name="l00045"></a>00045 <span class="keyword">const</span> QString &le = QString(<span class="stringliteral">"\n"</span>)); <a name="l00046"></a>00046 <span class="comment"></span> <a name="l00047"></a>00047 <span class="comment">/** Encodes the bytes in <b>buf</b> as an uppercase hexadecimal string and</span> <a name="l00048"></a>00048 <span class="comment"> * returns the result. This function is derived from base16_encode() in Tor's</span> <a name="l00049"></a>00049 <span class="comment"> * util.c. See LICENSE for details on Tor's license. */</span> <a name="l00050"></a>00050 QString <a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(<span class="keyword">const</span> QByteArray &buf); <a name="l00051"></a>00051 <span class="comment"></span> <a name="l00052"></a>00052 <span class="comment">/** Given a string <b>str</b>, this function returns a quoted string with all</span> <a name="l00053"></a>00053 <span class="comment"> * '"' and '\' characters escaped with a single '\'. */</span> <a name="l00054"></a>00054 QString <a class="code" href="stringutil_8cpp.html#a2323f625d9f361167e0455447c3fc83a">string_escape</a>(<span class="keyword">const</span> QString &str); <a name="l00055"></a>00055 <span class="comment"></span> <a name="l00056"></a>00056 <span class="comment">/** Given a quoted string <b>str</b>, this function returns an unquoted,</span> <a name="l00057"></a>00057 <span class="comment"> * unescaped string. <b>str</b> must start and end with an unescaped quote. */</span> <a name="l00058"></a>00058 QString <a class="code" href="stringutil_8cpp.html#a559eaa8ad9e4fab04d5bb5b6732283ea">string_unescape</a>(<span class="keyword">const</span> QString &str, <span class="keywordtype">bool</span> *ok = 0); <a name="l00059"></a>00059 <span class="comment"></span> <a name="l00060"></a>00060 <span class="comment">/** Parses a series of space-separated key[=value|="value"] tokens from</span> <a name="l00061"></a>00061 <span class="comment"> * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable</span> <a name="l00062"></a>00062 <span class="comment"> * to be parsed, <b>ok</b> is set to false. */</span> <a name="l00063"></a>00063 QHash<QString,QString> <a class="code" href="stringutil_8cpp.html#a2be53af228dd65232621f02a47bd8488">string_parse_keyvals</a>(<span class="keyword">const</span> QString &str, <span class="keywordtype">bool</span> *ok = 0); <a name="l00064"></a>00064 <span class="comment"></span> <a name="l00065"></a>00065 <span class="comment">/** Parses a series of command line arguments from <b>str</b>. If <b>str</b></span> <a name="l00066"></a>00066 <span class="comment"> * was unable to be parsed, <b>ok</b> is set to false. */</span> <a name="l00067"></a>00067 QStringList <a class="code" href="stringutil_8cpp.html#af8d2b1877609953a0b67d43665b773b4">string_parse_arguments</a>(<span class="keyword">const</span> QString &str, <span class="keywordtype">bool</span> *ok = 0); <a name="l00068"></a>00068 <span class="comment"></span> <a name="l00069"></a>00069 <span class="comment">/** Formats the list of command line arguments in <b>args</b> as a string.</span> <a name="l00070"></a>00070 <span class="comment"> * Arguments that contain ' ', '\', or '"' tokens will be escaped and wrapped</span> <a name="l00071"></a>00071 <span class="comment"> * in double quotes. */</span> <a name="l00072"></a>00072 QString <a class="code" href="stringutil_8cpp.html#ac226e398784e0eac1842837f552d740b">string_format_arguments</a>(<span class="keyword">const</span> QStringList &args); <a name="l00073"></a>00073 <span class="comment"></span> <a name="l00074"></a>00074 <span class="comment">/** Returns true if <b>str</b> is a valid hexademical string. Returns false</span> <a name="l00075"></a>00075 <span class="comment"> * otherwise. */</span> <a name="l00076"></a>00076 <span class="keywordtype">bool</span> <a class="code" href="stringutil_8cpp.html#a3a137a7377e9df6cdb6be274238e505e">string_is_hex</a>(<span class="keyword">const</span> QString &str); <a name="l00077"></a>00077 <span class="comment"></span> <a name="l00078"></a>00078 <span class="comment">/** Returns a human-readable description of the time elapsed given by</span> <a name="l00079"></a>00079 <span class="comment"> * <b>seconds</b>, broken down into days, hours, minutes and seconds. */</span> <a name="l00080"></a>00080 QString <a class="code" href="stringutil_8cpp.html#adc62dcb23eb63ad2cc3373689091aee3">string_format_uptime</a>(quint64 seconds); <a name="l00081"></a>00081 <span class="comment"></span> <a name="l00082"></a>00082 <span class="comment">/** Returns a string representation of <b>date</b> formatted according to</span> <a name="l00083"></a>00083 <span class="comment"> * "yyyy-MM-dd HH:mm:ss". */</span> <a name="l00084"></a>00084 QString <a class="code" href="stringutil_8cpp.html#a457c2b0b9a0e212819ab340227117440">string_format_datetime</a>(<span class="keyword">const</span> QDateTime &date); <a name="l00085"></a>00085 <span class="comment"></span> <a name="l00086"></a>00086 <span class="comment">/** Returns a string representation of <b>bytes</b> with the appropriate</span> <a name="l00087"></a>00087 <span class="comment"> * (localized) suffix of either "B/s", "KB/s", "MB/s" or "GB/s". */</span> <a name="l00088"></a>00088 QString <a class="code" href="stringutil_8cpp.html#a2be37f42e0b68ec6af355f453c80f1df">string_format_bandwidth</a>(quint64 bytes); <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="preprocessor">#endif</span> <a name="l00091"></a>00091 <span class="preprocessor"></span> </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>