src/core/strings.h
00001 //------------------------------------------------------------------------------
00002 // strings.h
00003 //------------------------------------------------------------------------------
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018 // 02110-1301, USA.
00019 //
00020 //------------------------------------------------------------------------------
00021 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
00022 //------------------------------------------------------------------------------
00023 #ifndef __STRINGS_H_
00024 #define __STRINGS_H_
00025 
00026 #include "global.h"
00027 
00028 class QString;
00029 
00030 class MAIN_EXPORT Strings
00031 {
00032         public:
00050                 static QString                  combinePaths(QString pathFront, QString pathEnd);
00051 
00057                 static QString                  createRandomAlphaNumericString(unsigned numChars);
00058                 static QString                  createRandomAlphaNumericStringWithNewLines(unsigned numCharsPerLine, unsigned numLines);
00059 
00063                 static const QString    &escape(QString &str);
00064 
00071                 static QString                  formatDataAmount(qint64 bytes);
00072 
00082                 static QString                  formatDataSpeed(float speedInBytesPerSecond);
00083 
00095                 static QString                  formatTime(float seconds);
00096 
00097                 static bool                             isCharOnCharList(char c, const QString& charList);
00098 
00106                 static QString                  normalizePath(QString path);
00107 
00117                 static void                             translateServerAddress(const QString& addressString, QString& hostname, unsigned short& port, const QString& defaultAddress);
00118 
00119                 static const QString    &unescape(QString &str);
00120 
00128                 static bool                             isUrlSafe(const QString& url);
00129 
00130                 static QString                  timestamp(const QString& format);
00131                 static QString&                 trim(QString& str, const QString& charList) { return trimr(triml(str, charList), charList); }
00132                 static QString&                 trimr(QString& str, const QString& charList);
00133                 static QString&                 triml(QString& str, const QString& charList);
00134 
00142                 static QString                  wrapUrlsWithHtmlATags(const QString& str);
00143 
00144         protected:
00145                 enum DataUnit
00146                 {
00147                         Byte            = 0,
00148                         Kilobyte        = 1,
00149                         Megabyte        = 2,
00150                         Gigabyte        = 3
00151                 };
00152 
00153                 static const unsigned   RANDOM_CHAR_POOL_SIZE = 36;
00154                 static const char               RANDOM_CHAR_POOL[RANDOM_CHAR_POOL_SIZE];
00155 
00156 
00157                 static float                    scaleDataUnit(float bytes, DataUnit& outUnit);
00158 };
00159 
00160 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator