[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2139: const correctness is cool. (There are several other places t (in trunk: . src/util)
Author: edmanm
Date: 2007-11-25 22:59:54 -0500 (Sun, 25 Nov 2007)
New Revision: 2139
Modified:
trunk/
trunk/src/util/string.cpp
trunk/src/util/string.h
Log:
r2160@lysithea: edmanm | 2007-11-25 22:59:42 -0500
const correctness is cool. (There are several other places that need to be
fixed up, too.)
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /local/vidalia/trunk [r2160] on 0108964c-5b0b-4c9e-969f-e2288315d100
Modified: trunk/src/util/string.cpp
===================================================================
--- trunk/src/util/string.cpp 2007-11-25 06:22:48 UTC (rev 2138)
+++ trunk/src/util/string.cpp 2007-11-26 03:59:54 UTC (rev 2139)
@@ -43,7 +43,7 @@
* This is a seemingly pointless function, but it saves some messiness in
* methods whose QString *errmsg parameter is optional. */
bool
-err(QString *str, QString errmsg)
+err(QString *str, const QString &errmsg)
{
if (str) {
*str = errmsg;
@@ -55,7 +55,7 @@
* in str but not in validChars, it will be removed and the resulting
* string returned. */
QString
-ensure_valid_chars(QString str, QString validChars)
+ensure_valid_chars(const QString &str, const QString &validChars)
{
QString out = str;
for (int i = 0; i < str.length(); i++) {
@@ -69,7 +69,7 @@
/** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
QString
-scrub_email_addr(QString email)
+scrub_email_addr(const QString &email)
{
QString scrubbed = email;
scrubbed = scrubbed.replace("@", " at ");
@@ -81,7 +81,8 @@
* word separator (" ", for example), and placing the line ending <b>le</b> at
* the end of each line, except the last. */
QString
-string_wrap(QString str, int width, QString sep, QString le)
+string_wrap(const QString &str, int width,
+ const QString &sep, const QString &le)
{
QString wrapped;
int pos, nextsep, wordlen, n;
@@ -120,7 +121,7 @@
* returns the result. This function is derived from base16_encode() in Tor's
* util.c. See LICENSE for details on Tor's license. */
QString
-base16_encode(const QByteArray buf)
+base16_encode(const QByteArray &buf)
{
QString hex;
for (int i = 0; i < buf.size(); i++) {
@@ -133,7 +134,7 @@
/** Given a string <b>str</b>, this function returns a quoted string with all
* '"' and '\' characters escaped with a single '\'. */
QString
-string_escape(const QString str)
+string_escape(const QString &str)
{
QString out;
out.append('\"');
@@ -149,7 +150,7 @@
/** Given a quoted string <b>str</b>, this function returns an unquoted,
* unescaped string. <b>str</b> must start and end with an unescaped quote. */
QString
-string_unescape(const QString str, bool *ok)
+string_unescape(const QString &str, bool *ok)
{
QString out;
@@ -174,7 +175,7 @@
* <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable
* to be parsed, <b>ok</b> is set to false. */
QHash<QString,QString>
-string_parse_keyvals(const QString str, bool *ok)
+string_parse_keyvals(const QString &str, bool *ok)
{
int i, len;
bool tmp_ok;
Modified: trunk/src/util/string.h
===================================================================
--- trunk/src/util/string.h 2007-11-25 06:22:48 UTC (rev 2138)
+++ trunk/src/util/string.h 2007-11-26 03:59:54 UTC (rev 2139)
@@ -38,37 +38,38 @@
/** Ensures all characters in str are in validChars. If a character appears
* in str but not in validChars, it will be removed and the resulting
* string returned. */
-QString ensure_valid_chars(QString str, QString validChars);
+QString ensure_valid_chars(const QString &str, const QString &validChars);
/** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
-QString scrub_email_addr(QString email);
+QString scrub_email_addr(const QString &email);
/** Conditionally assigns errmsg to string if str is not null and returns
* false. */
-bool err(QString *str, QString errmsg);
+bool err(QString *str, const QString &errmsg);
/** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the
* word separator (" ", for example), and placing the line ending <b>le</b> at
* the end of each line, except the last.*/
-QString string_wrap(QString str, int width, QString sep, QString le);
+QString string_wrap(const QString &str, int width,
+ const QString &sep, const QString &le);
/** Encodes the bytes in <b>buf</b> as an uppercase hexadecimal string and
* returns the result. This function is derived from base16_encode() in Tor's
* util.c. See LICENSE for details on Tor's license. */
-QString base16_encode(const QByteArray buf);
+QString base16_encode(const QByteArray &buf);
/** Given a string <b>str</b>, this function returns a quoted string with all
* '"' and '\' characters escaped with a single '\'. */
-QString string_escape(const QString str);
+QString string_escape(const QString &str);
/** Given a quoted string <b>str</b>, this function returns an unquoted,
* unescaped string. <b>str</b> must start and end with an unescaped quote. */
-QString string_unescape(const QString str, bool *ok = 0);
+QString string_unescape(const QString &str, bool *ok = 0);
/** Parses a series of space-separated key[=value|="value"] tokens from
* <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable
* to be parsed, <b>ok</b> is set to false. */
-QHash<QString,QString> string_parse_keyvals(const QString str, bool *ok = 0);
+QHash<QString,QString> string_parse_keyvals(const QString &str, bool *ok = 0);
/** Returns true if <b>str</b> is a valid hexademical string. Returns false
* otherwise. */