Vidalia 0.2.12
Functions

stringutil.cpp File Reference

#include "stringutil.h"
#include <QCoreApplication>
#include <QApplication>

Go to the source code of this file.

Functions

QStringList char_array_to_stringlist (char **arr, int len)
bool err (QString *str, const QString &errmsg)
QString ensure_valid_chars (const QString &str, const QString &validChars)
QString scrub_email_addr (const QString &email)
QString string_wrap (const QString &str, int width, const QString &sep, const QString &le)
QString base16_encode (const QByteArray &buf)
QString string_escape (const QString &str)
QString string_unescape (const QString &str, bool *ok)
QHash< QString, QString > string_parse_keyvals (const QString &str, bool *ok)
QStringList string_parse_arguments (const QString &str, bool *ok)
QString string_format_arguments (const QStringList &args)
bool string_is_hex (const QString &str)
QString string_format_uptime (quint64 seconds)
QString string_format_datetime (const QDateTime &date)
QString string_format_bandwidth (quint64 bytes)

Function Documentation

QString base16_encode ( const QByteArray &  buf)

Encodes the bytes in buf 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.

Definition at line 115 of file stringutil.cpp.

References i().

Referenced by TorControl::authenticate(), TorSettings::hashPassword(), and RouterStatus::RouterStatus().

QStringList char_array_to_stringlist ( char **  arr,
int  len 
)

Create a QStringList from the array of C-style strings.

Definition at line 24 of file stringutil.cpp.

References i().

Referenced by main().

QString ensure_valid_chars ( const QString &  str,
const QString &  validChars 
)

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.

Definition at line 49 of file stringutil.cpp.

References i().

Referenced by ServerSettings::getNickname(), and NicknameValidator::validate().

bool err ( QString *  str,
const QString &  errmsg 
)
QString scrub_email_addr ( const QString &  email)

Scrubs an email address by replacing "@" with " at " and "." with " dot ".

Definition at line 63 of file stringutil.cpp.

Referenced by ServerSettings::confValues().

QString string_escape ( const QString &  str)

Given an ASCII string str, this function returns a quoted string with all escaped characters unescaped. Non-ASCII characters in the string will be converted to the local 8-bit character encoding and encoded using an escaped octal sequence. The returned string will thus contain only printable ASCII characters.

Definition at line 131 of file stringutil.cpp.

References i().

Referenced by TorControl::authenticate(), TorProcess::formatArguments(), TorControl::setConf(), ServicePage::startServicesInTor(), and string_format_arguments().

QString string_format_arguments ( const QStringList &  args)

Formats the list of command line arguments in args as a string. Arguments that contain ' ', '\', or '"' tokens will be escaped and wrapped in double quotes.

Definition at line 360 of file stringutil.cpp.

References string_escape().

Referenced by CrashReporter::set_restart_options(), and HelperProcess::start().

QString string_format_bandwidth ( quint64  bytes)

Returns a string representation of bytes with the appropriate suffix of either "B/s", "KB/s", "MB/s" or "GB/s".

Definition at line 419 of file stringutil.cpp.

Referenced by RouterDescriptorView::display(), and RouterInfoDialog::setRouterInfo().

QString string_format_datetime ( const QDateTime &  date)

Returns a string representation of date formatted according to "yyyy-MM-dd HH:mm:ss".

Definition at line 411 of file stringutil.cpp.

Referenced by RouterDescriptorView::display(), and RouterInfoDialog::setRouterInfo().

QString string_format_uptime ( quint64  seconds)

Returns a human-readable description of the time elapsed given by seconds, broken down into days, hours, minutes and seconds.

Definition at line 388 of file stringutil.cpp.

Referenced by RouterDescriptorView::display(), and RouterInfoDialog::setRouterInfo().

bool string_is_hex ( const QString &  str)

Returns true if str is a valid hexademical string. Returns false otherwise.

Definition at line 375 of file stringutil.cpp.

References i().

Referenced by NetworkPage::validateBridge().

QStringList string_parse_arguments ( const QString &  str,
bool *  ok 
)

Parses a series of command line arguments from str. If str was unable to be parsed, ok is set to false.

Definition at line 305 of file stringutil.cpp.

References tc::error(), i(), and string_unescape().

Referenced by CrashReportDialog::accept().

QHash<QString,QString> string_parse_keyvals ( const QString &  str,
bool *  ok 
)

Parses a series of space-separated key[=value|="value"] tokens from str and returns the mappings in a QHash. If str was unable to be parsed, ok is set to false.

Definition at line 244 of file stringutil.cpp.

References tc::error(), i(), and string_unescape().

Referenced by TorControl::bootstrapStatus(), ServerPage::displayBridgeUsage(), TorEvents::handleStatusEvent(), TorControl::protocolInfo(), and UpdateProcess::readStandardError().

QString string_unescape ( const QString &  str,
bool *  ok 
)

Given a quoted string str, this function returns an unquoted, unescaped string. str must start and end with an unescaped DQUOTE, The input string must contain only ASCII characters; however, non-ASCII characters can be included by encoding their byte sequences in either escaped hexadecimal (e.g., "\xFF") or octal (e.g., "\301"). The result will be converted to a QString using the local 8-bit encoding.

Definition at line 177 of file stringutil.cpp.

References err(), and i().

Referenced by TorControl::getConf(), TorControl::getInfo(), string_parse_arguments(), and string_parse_keyvals().

QString string_wrap ( const QString &  str,
int  width,
const QString &  sep,
const QString &  le 
)

Wraps str at width characters wide, using sep as the word separator (" ", for example), and placing the line ending le at the end of each line, except the last.

Definition at line 75 of file stringutil.cpp.

Referenced by StatusEventWidget::addNotification(), and LogTreeItem::setMessage().