Add some const correctness to Network
[quassel.git] / src / common / util.cpp
index 817790f..14435bd 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-09 by the Quassel Project                          *
+ *   Copyright (C) 2005-2010 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -60,6 +60,22 @@ QString stripFormatCodes(QString str) {
   return str;
 }
 
+QString stripAcceleratorMarkers(const QString &label_) {
+  QString label = label_;
+  int p = 0;
+  forever {
+    p = label.indexOf('&', p);
+    if(p < 0 || p + 1 >= label.length())
+      break;
+
+    if(label.at(p + 1).isLetterOrNumber() || label.at(p + 1) == '&')
+      label.remove(p, 1);
+
+    ++p;
+  }
+  return label;
+}
+
 QString decodeString(const QByteArray &input, QTextCodec *codec) {
   // First, we check if it's utf8. It is very improbable to encounter a string that looks like
   // valid utf8, but in fact is not. This means that if the input string passes as valid utf8, it
@@ -108,14 +124,14 @@ uint editingDistance(const QString &s1, const QString &s2) {
       uint insertChar = matrix[i][j-1] + 1;
 
       if(deleteChar < insertChar)
-       min = deleteChar;
+        min = deleteChar;
       else
-       min = insertChar;
+        min = insertChar;
 
       if(s1[i-1] == s2[j-1]) {
-       uint inheritChar = matrix[i-1][j-1];
-       if(inheritChar < min)
-         min = inheritChar;
+        uint inheritChar = matrix[i-1][j-1];
+        if(inheritChar < min)
+          min = inheritChar;
       }
 
       matrix[i][j] = min;
@@ -144,7 +160,7 @@ QString secondsToString(int timeInSeconds) {
 }
 
 QByteArray prettyDigest(const QByteArray &digest) {
-  QByteArray hexDigest = digest.toHex();
+  QByteArray hexDigest = digest.toHex().toUpper();
   QByteArray prettyDigest;
   prettyDigest.fill(':', hexDigest.count() + (hexDigest.count() / 2) - 1);