OSDN Git Service

Fix Issue 85: Installer: warns of downgrade when running 0.6.2.0 on top of 0.6.1.0
[tortoisegit/TortoiseGitJp.git] / src / Utils / StringUtils.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 \r
21 #ifdef UNICODE\r
22 #define _tcswildcmp     wcswildcmp\r
23 #else\r
24 #define _tcswildcmp strwildcmp\r
25 #endif\r
26 \r
27 /**\r
28  * \ingroup Utils\r
29  * Performs a wild card compare of two strings.\r
30  * \param wild the wild card string\r
31  * \param string the string to compare the wild card to\r
32  * \return TRUE if the wild card matches the string, 0 otherwise\r
33  * \par example\r
34  * \code \r
35  * if (strwildcmp("bl?hblah.*", "bliblah.jpeg"))\r
36  *  printf("success\n");\r
37  * else\r
38  *  printf("not found\n");\r
39  * if (strwildcmp("bl?hblah.*", "blabblah.jpeg"))\r
40  *  printf("success\n");\r
41  * else\r
42  *  printf("not found\n");\r
43  * \endcode\r
44  * The output of the above code would be:\r
45  * \code\r
46  * success\r
47  * not found\r
48  * \endcode\r
49  */\r
50 int strwildcmp(const char * wild, const char * string);\r
51 int wcswildcmp(const wchar_t * wild, const wchar_t * string);\r
52 \r
53 \r
54 /**\r
55  * \ingroup Utils\r
56  * string helper functions\r
57  */\r
58 class CStringUtils\r
59 {\r
60 public:\r
61 #ifdef _MFC_VER\r
62         static BOOL WildCardMatch(const CString& wildcard, const CString& string);\r
63         static CString LinesWrap(const CString& longstring, int limit = 80, bool bCompactPaths = false);\r
64         static CString WordWrap(const CString& longstring, int limit = 80, bool bCompactPaths = false);\r
65 \r
66         /**\r
67          * Removes all '&' chars from a string.\r
68          */\r
69         static void RemoveAccelerators(CString& text);\r
70 \r
71         /**\r
72          * Writes an ASCII CString to the clipboard in CF_TEXT format\r
73          */\r
74         static bool WriteAsciiStringToClipboard(const CStringA& sClipdata, LCID lcid, HWND hOwningWnd = NULL);\r
75         /**\r
76          * Writes a String to the clipboard in both CF_UNICODETEXT and CF_TEXT format\r
77          */\r
78         static bool WriteAsciiStringToClipboard(const CStringW& sClipdata, HWND hOwningWnd = NULL);\r
79 \r
80         /**\r
81         * Writes an ASCII CString to the clipboard in TSVN_UNIFIEDDIFF format, which is basically the patch file\r
82         * as a ASCII string.\r
83         */\r
84         static bool WriteDiffToClipboard(const CStringA& sClipdata, HWND hOwningWnd = NULL);\r
85 \r
86         /**\r
87          * Reads the string \text from the file \path in utf8 encoding.\r
88          */\r
89         static bool ReadStringFromTextFile(const CString& path, CString& text);\r
90 #endif\r
91 \r
92         /**\r
93          * Writes the string \text to the file \path, either in utf16 or utf8 encoding,\r
94          * depending on the \c bUTF8 param.\r
95          */\r
96         static bool WriteStringToTextFile(const std::wstring& path, const std::wstring& text, bool bUTF8 = true);\r
97 \r
98         /**\r
99          * Compares strings while trying to parse numbers in it too.\r
100          * This function can be used to sort numerically.\r
101          * For example, strings would be sorted like this:\r
102          * Version_1.0.3\r
103          * Version_2.0.4\r
104          * Version_10.0.2\r
105          * If a normal text like comparison is used for sorting, the Version_10.0.2\r
106          * would not be the last in the above example.\r
107          */\r
108         static int CompareNumerical(LPCTSTR str1, LPCTSTR str2);\r
109 \r
110 };\r
111 \r