[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2144: Rename string.* to stringutil.*, so cmake doesn't get so con (in trunk: . src src/gui src/gui/config src/gui/log src/util)
Author: edmanm
Date: 2007-11-30 20:48:30 -0500 (Fri, 30 Nov 2007)
New Revision: 2144
Added:
trunk/src/util/stringutil.cpp
trunk/src/util/stringutil.h
Modified:
trunk/
trunk/src/gui/config/networkpage.cpp
trunk/src/gui/config/nicknamevalidator.cpp
trunk/src/gui/log/logfile.cpp
trunk/src/gui/log/logtreeitem.cpp
trunk/src/gui/log/logtreeitem.h
trunk/src/gui/mainwindow.cpp
trunk/src/util/util.pri
trunk/src/vidalia.cpp
trunk/src/vidalia.h
Log:
r2169@lysithea: edmanm | 2007-11-30 20:48:20 -0500
Rename string.* to stringutil.*, so cmake doesn't get so confused.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /local/vidalia/trunk [r2169] on 0108964c-5b0b-4c9e-969f-e2288315d100
Modified: trunk/src/gui/config/networkpage.cpp
===================================================================
--- trunk/src/gui/config/networkpage.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/config/networkpage.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -32,7 +32,7 @@
#include <networksettings.h>
#include <vmessagebox.h>
#include <vidalia.h>
-#include <util/string.h>
+#include <stringutil.h>
#include "networkpage.h"
#include "domainvalidator.h"
Modified: trunk/src/gui/config/nicknamevalidator.cpp
===================================================================
--- trunk/src/gui/config/nicknamevalidator.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/config/nicknamevalidator.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -25,7 +25,7 @@
* \brief Validates that a server nickname contains only valid characters
*/
-#include <util/string.h>
+#include <stringutil.h>
#include "nicknamevalidator.h"
/** Set of characters that are valid in a server's nickname. */
Modified: trunk/src/gui/log/logfile.cpp
===================================================================
--- trunk/src/gui/log/logfile.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/log/logfile.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -26,7 +26,7 @@
*/
#include <QDir>
-#include <util/string.h>
+#include <stringutil.h>
#include "logfile.h"
Modified: trunk/src/gui/log/logtreeitem.cpp
===================================================================
--- trunk/src/gui/log/logtreeitem.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/log/logtreeitem.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -25,7 +25,7 @@
* \brief Item representing a single message in the message log
*/
-#include <util/string.h>
+#include <stringutil.h>
#include "logtreeitem.h"
#include "logtreewidget.h"
Modified: trunk/src/gui/log/logtreeitem.h
===================================================================
--- trunk/src/gui/log/logtreeitem.h 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/log/logtreeitem.h 2007-12-01 01:48:30 UTC (rev 2144)
@@ -31,7 +31,7 @@
#include <QTreeWidgetItem>
#include <QDateTime>
#include <QString>
-#include <control/logevent.h>
+#include <logevent.h>
class LogTreeItem : public QTreeWidgetItem
Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/gui/mainwindow.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -34,7 +34,7 @@
#include <vidalia.h>
#include <util/file.h>
#include <util/html.h>
-#include <util/string.h>
+#include <util/stringutil.h>
#include <util/net.h>
#include <QSysInfo>
Added: trunk/src/util/stringutil.cpp
===================================================================
--- trunk/src/util/stringutil.cpp (rev 0)
+++ trunk/src/util/stringutil.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -0,0 +1,248 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file string.cpp
+ * \version $Id$
+ * \brief Common string manipulation functions
+ */
+
+#include "stringutil.h"
+
+
+/** Create a QStringList from the array of C-style strings. */
+QStringList
+char_array_to_stringlist(char **arr, int len)
+{
+ QStringList list;
+ for (int i = 0; i < len; i++) {
+ list << QString(arr[i]);
+ }
+ return list;
+}
+
+/** Conditionally assigns errmsg to str if str is not null and returns false.
+ * This is a seemingly pointless function, but it saves some messiness in
+ * methods whose QString *errmsg parameter is optional. */
+bool
+err(QString *str, const QString &errmsg)
+{
+ if (str) {
+ *str = errmsg;
+ }
+ return false;
+}
+
+/** 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(const QString &str, const QString &validChars)
+{
+ QString out = str;
+ for (int i = 0; i < str.length(); i++) {
+ QChar c = str.at(i);
+ if (validChars.indexOf(c) < 0) {
+ out.remove(c);
+ }
+ }
+ return out;
+}
+
+/** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
+QString
+scrub_email_addr(const QString &email)
+{
+ QString scrubbed = email;
+ scrubbed = scrubbed.replace("@", " at ");
+ scrubbed = scrubbed.replace(".", " dot ");
+ return scrubbed;
+}
+
+/** 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(const QString &str, int width,
+ const QString &sep, const QString &le)
+{
+ QString wrapped;
+ int pos, nextsep, wordlen, n;
+ int seplen = sep.length();
+
+ if (str.length() < width) {
+ return str;
+ }
+
+ pos = 0;
+ n = width;
+ while (pos < str.length()) {
+ /* Get the length of a "word" */
+ nextsep = str.indexOf(sep, pos);
+ if (nextsep < 0) {
+ nextsep = str.length();
+ }
+ wordlen = nextsep-pos;
+
+ /* Check if there is room for the word on this line */
+ if (wordlen > n) {
+ /* Create a new line */
+ wrapped.append(le);
+ n = width;
+ }
+
+ /* Add the word to the current line */
+ wrapped.append(str.mid(pos, wordlen+seplen));
+ n = n - wordlen - seplen;
+ pos += wordlen + seplen;
+ }
+ return wrapped.trimmed();
+}
+
+/** 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 hex;
+ for (int i = 0; i < buf.size(); i++) {
+ hex += "0123456789ABCDEF"[((quint8)buf[i]) >> 4];
+ hex += "0123456789ABCDEF"[((quint8)buf[i]) & 0xf];
+ }
+ return hex;
+}
+
+/** 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 out;
+ out.append('\"');
+ for (int i = 0; i < str.length(); i++) {
+ if (str[i] == '\"' || str[i] == '\\')
+ out.append('\\');
+ out.append(str[i]);
+ }
+ out.append('\"');
+ return out;
+}
+
+/** 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)
+{
+ QString out;
+
+ /* The string must start and end with an unescaped dquote */
+ if (str.length() < 2 || !str.startsWith("\"") || !str.endsWith("\"") ||
+ (str.endsWith("\\\"") && !str.endsWith("\\\\\""))) {
+ if (ok)
+ *ok = false;
+ return QString();
+ }
+ for (int i = 1; i < str.length()-1; i++) {
+ if (str[i] == '\\')
+ i++;
+ out.append(str[i]);
+ }
+ if (ok)
+ *ok = true;
+ return out;
+}
+
+/** 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)
+{
+ int i, len;
+ bool tmp_ok;
+ QHash<QString,QString> keyvals;
+
+ i = 0;
+ len = str.length();
+ while (i < len && str[i].isSpace())
+ i++; /* Skip initial whitespace */
+ while (i < len) {
+ QString key, val;
+
+ while (i < len && !str[i].isSpace() && str[i] != '=')
+ key.append(str[i++]);
+
+ if (i < len && str[i] == '=') {
+ if (++i < len && str[i] == '\"') {
+ /* The value is wrapped in quotes */
+ val.append(str[i]);
+ while (++i < len) {
+ val.append(str[i]);
+ if (str[i] == '\\') {
+ if (++i == len)
+ goto error;
+ val.append(str[i]);
+ } else if (str[i] == '\"') {
+ i++;
+ break;
+ }
+ }
+ val = string_unescape(val, &tmp_ok);
+ if (!tmp_ok)
+ goto error;
+ keyvals.insert(key, val);
+ } else {
+ /* The value was not wrapped in quotes */
+ while (i < len && !str[i].isSpace())
+ val.append(str[i++]);
+ keyvals.insert(key, val);
+ }
+ } else {
+ /* The key had no value */
+ keyvals.insert(key, QString(""));
+ }
+ while (i < len && str[i].isSpace())
+ i++;
+ }
+ if (ok)
+ *ok = true;
+ return keyvals;
+
+error:
+ if (ok)
+ *ok = false;
+ return QHash<QString,QString>();
+}
+
+/** Returns true if <b>str</b> is a valid hexademical string. Returns false
+ * otherwise. */
+bool
+string_is_hex(const QString &str)
+{
+ for (int i = 0; i < str.length(); i++) {
+ char c = str[i].toUpper().toAscii();
+ if ((c < 'A' || c > 'F') && (c < '0' || c > '9'))
+ return false;
+ }
+ return true;
+}
+
Property changes on: trunk/src/util/stringutil.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/src/util/stringutil.h
===================================================================
--- trunk/src/util/stringutil.h (rev 0)
+++ trunk/src/util/stringutil.h 2007-12-01 01:48:30 UTC (rev 2144)
@@ -0,0 +1,79 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file string.h
+ * \version $Id$
+ * \brief Common string manipulation functions
+ */
+
+#ifndef _STRINGUTIL_H
+#define _STRINGUTIL_H
+
+#include <QStringList>
+#include <QHash>
+
+
+/** Creates a QStringList from the array of C strings. */
+QStringList char_array_to_stringlist(char **arr, int len);
+
+/** 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(const QString &str, const QString &validChars);
+
+/** Scrubs an email address by replacing "@" with " at " and "." with " dot ". */
+QString scrub_email_addr(const QString &email);
+
+/** Conditionally assigns errmsg to string if str is not null and returns
+ * false. */
+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(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);
+
+/** 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);
+
+/** 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);
+
+/** 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);
+
+/** Returns true if <b>str</b> is a valid hexademical string. Returns false
+ * otherwise. */
+bool string_is_hex(const QString &str);
+
+#endif
+
Property changes on: trunk/src/util/stringutil.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: trunk/src/util/util.pri
===================================================================
--- trunk/src/util/util.pri 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/util/util.pri 2007-12-01 01:48:30 UTC (rev 2144)
@@ -21,8 +21,10 @@
# 02110-1301, USA.
#################################################################
+INCLUDEPATH += $$PWD
+
HEADERS += $$PWD/net.h \
- $$PWD/string.h \
+ $$PWD/stringutil.h \
$$PWD/torsocket.h \
$$PWD/html.h \
$$PWD/process.h \
@@ -32,7 +34,7 @@
$$PWD/crypto.h
SOURCES += $$PWD/net.cpp \
- $$PWD/string.cpp \
+ $$PWD/stringutil.cpp \
$$PWD/torsocket.cpp \
$$PWD/html.cpp \
$$PWD/process.cpp \
@@ -46,3 +48,4 @@
SOURCES += $$PWD/win32.cpp
}
+
Modified: trunk/src/vidalia.cpp
===================================================================
--- trunk/src/vidalia.cpp 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/vidalia.cpp 2007-12-01 01:48:30 UTC (rev 2144)
@@ -32,8 +32,8 @@
#include <QShortcut>
#include <languagesupport.h>
#include <vmessagebox.h>
-#include <util/string.h>
-#include <util/html.h>
+#include <stringutil.h>
+#include <html.h>
#include <stdlib.h>
#include "vidalia.h"
Modified: trunk/src/vidalia.h
===================================================================
--- trunk/src/vidalia.h 2007-11-30 16:28:52 UTC (rev 2143)
+++ trunk/src/vidalia.h 2007-12-01 01:48:30 UTC (rev 2144)
@@ -30,7 +30,7 @@
#if defined(Q_OS_WIN)
#include <windows.h>
-#include <util/win32.h>
+#include <win32.h>
#endif
#include <QApplication>
@@ -38,7 +38,7 @@
#include <QString>
#include <QKeySequence>
-#include <util/log.h>
+#include <log.h>
#include <helpbrowser.h>
#include <vidaliasettings.h>
#include <torcontrol.h>