[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1840: Add a base16_encode() function to encode a QByteArray as a h (in trunk: . src/util)
Author: edmanm
Date: 2007-08-21 00:33:23 -0400 (Tue, 21 Aug 2007)
New Revision: 1840
Modified:
trunk/
trunk/src/util/string.cpp
trunk/src/util/string.h
Log:
r2001@adrastea: edmanm | 2007-08-20 16:36:00 -0400
Add a base16_encode() function to encode a QByteArray as a hexidecimal string.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r2001] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/util/string.cpp
===================================================================
--- trunk/src/util/string.cpp 2007-08-21 04:33:14 UTC (rev 1839)
+++ trunk/src/util/string.cpp 2007-08-21 04:33:23 UTC (rev 1840)
@@ -116,3 +116,17 @@
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;
+}
+
Modified: trunk/src/util/string.h
===================================================================
--- trunk/src/util/string.h 2007-08-21 04:33:14 UTC (rev 1839)
+++ trunk/src/util/string.h 2007-08-21 04:33:23 UTC (rev 1840)
@@ -50,5 +50,10 @@
* the end of each line, except the last.*/
QString string_wrap(QString str, int width, QString sep, 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);
+
#endif