Consistently use TGIT_UNIFIEDDIFF instead of TSVN_UNIFIEDDIFF
[TortoiseGit.git] / src / Utils / StringUtils.h
blob993e90ffeb2bcaa1c937613108c7471c3d675cdc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2010 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
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.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #ifdef UNICODE
22 #define _tcswildcmp wcswildcmp
23 #else
24 #define _tcswildcmp strwildcmp
25 #endif
27 /**
28 * \ingroup Utils
29 * Performs a wild card compare of two strings.
30 * \param wild the wild card string
31 * \param string the string to compare the wild card to
32 * \return TRUE if the wild card matches the string, 0 otherwise
33 * \par example
34 * \code
35 * if (strwildcmp("bl?hblah.*", "bliblah.jpeg"))
36 * printf("success\n");
37 * else
38 * printf("not found\n");
39 * if (strwildcmp("bl?hblah.*", "blabblah.jpeg"))
40 * printf("success\n");
41 * else
42 * printf("not found\n");
43 * \endcode
44 * The output of the above code would be:
45 * \code
46 * success
47 * not found
48 * \endcode
50 int strwildcmp(const char * wild, const char * string);
51 int wcswildcmp(const wchar_t * wild, const wchar_t * string);
54 /**
55 * \ingroup Utils
56 * string helper functions
58 class CStringUtils
60 public:
61 #ifdef _MFC_VER
63 /**
64 * Removes all '&' chars from a string.
66 static void RemoveAccelerators(CString& text);
68 /**
69 * Writes an ASCII CString to the clipboard in CF_TEXT format
71 static bool WriteAsciiStringToClipboard(const CStringA& sClipdata, LCID lcid, HWND hOwningWnd = NULL);
72 /**
73 * Writes a String to the clipboard in both CF_UNICODETEXT and CF_TEXT format
75 static bool WriteAsciiStringToClipboard(const CStringW& sClipdata, HWND hOwningWnd = NULL);
77 /**
78 * Writes an ASCII CString to the clipboard in TGIT_UNIFIEDDIFF format, which is basically the patch file
79 * as a ASCII string.
81 static bool WriteDiffToClipboard(const CStringA& sClipdata, HWND hOwningWnd = NULL);
83 /**
84 * Reads the string \text from the file \path in utf8 encoding.
86 static bool ReadStringFromTextFile(const CString& path, CString& text);
88 #endif
89 #if defined(CSTRING_AVAILABLE) || defined(_MFC_VER)
90 static BOOL WildCardMatch(const CString& wildcard, const CString& string);
91 static CString LinesWrap(const CString& longstring, int limit = 80, bool bCompactPaths = false);
92 static CString WordWrap(const CString& longstring, int limit, bool bCompactPaths, bool bForceWrap, int tabSize);
93 /**
94 * Find and return the number n of starting characters equal between
95 * \ref lhs and \ref rhs. (max n: lhs.Left(n) == rhs.Left(n))
97 static int GetMatchingLength (const CString& lhs, const CString& rhs);
99 /**
100 * Optimizing wrapper around CompareNoCase.
102 static int FastCompareNoCase (const CStringW& lhs, const CStringW& rhs);
103 #endif
105 * Writes the string \text to the file \path, either in utf16 or utf8 encoding,
106 * depending on the \c bUTF8 param.
108 static bool WriteStringToTextFile(const std::wstring& path, const std::wstring& text, bool bUTF8 = true);
111 * Replace all pipe (|) character in the string with a NULL character. Used
112 * for passing into Win32 functions that require such representation
114 static void PipesToNulls(TCHAR* buffer, size_t length);
115 static void PipesToNulls(TCHAR* buffer);