Merge remote branch 'mine/ext-python'
[vuplus_xbmc] / xbmc / utils / StringUtils.h
1 /*
2  *      Copyright (C) 2005-2008 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 //-----------------------------------------------------------------------
22 //
23 //  File:      StringUtils.h
24 //
25 //  Purpose:   ATL split string utility
26 //  Author:    Paul J. Weiss
27 //
28 //  Modified to support J O'Leary's CStdString class by kraqh3d
29 //
30 //------------------------------------------------------------------------
31
32 #ifndef __STRINGUTILS_H_
33 #define __STRINGUTILS_H_
34
35 #include "XBDateTime.h"
36 #include "utils/StdString.h"
37 #include <vector>
38 #include <stdint.h>
39
40 class StringUtils
41 {
42 public:
43   static void JoinString(const CStdStringArray &strings, const CStdString& delimiter, CStdString& result);
44   static int SplitString(const CStdString& input, const CStdString& delimiter, CStdStringArray &results, unsigned int iMaxStrings = 0);
45   static int FindNumber(const CStdString& strInput, const CStdString &strFind);
46   static int64_t AlphaNumericCompare(const wchar_t *left, const wchar_t *right);
47   static long TimeStringToSeconds(const CStdString &timeString);
48   static void RemoveCRLF(CStdString& strLine);
49
50   /*! \brief convert a time in seconds to a string based on the given time format
51    \param seconds time in seconds
52    \param format the format we want the time in.
53    \return the formatted time
54    \sa TIME_FORMAT
55    */
56   static CStdString SecondsToTimeString(long seconds, TIME_FORMAT format = TIME_FORMAT_GUESS);
57
58   static bool IsNaturalNumber(const CStdString& str);
59   static CStdString SizeToString(int64_t size);
60   static const CStdString EmptyString;
61   static size_t FindWords(const char *str, const char *wordLowerCase);
62   static int FindEndBracket(const CStdString &str, char opener, char closer, int startPos = 0);
63   static int DateStringToYYYYMMDD(const CStdString &dateString);
64   static void WordToDigits(CStdString &word);
65   static CStdString CreateUUID();
66   static bool ValidateUUID(const CStdString &uuid); // NB only validates syntax
67   static double CompareFuzzy(const CStdString &left, const CStdString &right);
68   static int FindBestMatch(const CStdString &str, const CStdStringArray &strings, double &matchscore);
69 private:
70   static CStdString m_lastUUID;
71 };
72
73 #endif