1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2010 - TortoiseSVN
4 // Copyright (C) 2015-2016 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define wcswildcmp wcswildcmp
25 #define wcswildcmp strwildcmp
30 * Performs a wild card compare of two strings.
31 * \param wild the wild card string
32 * \param string the string to compare the wild card to
33 * \return TRUE if the wild card matches the string, 0 otherwise
36 * if (strwildcmp("bl?hblah.*", "bliblah.jpeg"))
37 * printf("success\n");
39 * printf("not found\n");
40 * if (strwildcmp("bl?hblah.*", "blabblah.jpeg"))
41 * printf("success\n");
43 * printf("not found\n");
45 * The output of the above code would be:
51 int strwildcmp(const char * wild
, const char * string
);
52 int wcswildcmp(const wchar_t * wild
, const wchar_t * string
);
57 * string helper functions
62 CStringUtils() = delete;
66 * Removes all '&' chars from a string.
68 static void RemoveAccelerators(CString
& text
);
71 * Returns the accellerator used in the string or \0
73 static TCHAR
GetAccellerator(const CString
& text
);
76 * Writes an ASCII CString to the clipboard in CF_TEXT format
78 static bool WriteAsciiStringToClipboard(const CStringA
& sClipdata
, LCID lcid
, HWND hOwningWnd
= nullptr);
80 * Writes a String to the clipboard in both CF_UNICODETEXT and CF_TEXT format
82 static bool WriteAsciiStringToClipboard(const CStringW
& sClipdata
, HWND hOwningWnd
= nullptr);
85 * Writes an ASCII CString to the clipboard in TGIT_UNIFIEDDIFF format, which is basically the patch file
88 static bool WriteDiffToClipboard(const CStringA
& sClipdata
, HWND hOwningWnd
= nullptr);
91 * Reads the string \text from the file \path in utf8 encoding.
93 static bool ReadStringFromTextFile(const CString
& path
, CString
& text
);
96 #if defined(CSTRING_AVAILABLE) || defined(_MFC_VER)
97 static BOOL
WildCardMatch(const CString
& wildcard
, const CString
& string
);
98 static CString
LinesWrap(const CString
& longstring
, int limit
= 80, bool bCompactPaths
= false);
99 static CString
WordWrap(const CString
& longstring
, int limit
, bool bCompactPaths
, bool bForceWrap
, int tabSize
);
101 * Find and return the number n of starting characters equal between
102 * \ref lhs and \ref rhs. (max n: lhs.Left(n) == rhs.Left(n))
104 static int GetMatchingLength (const CString
& lhs
, const CString
& rhs
);
107 * Optimizing wrapper around CompareNoCase.
109 static int FastCompareNoCase (const CStringW
& lhs
, const CStringW
& rhs
);
111 static void ParseEmailAddress(CString mailaddress
, CString
& parsedAddress
, CString
* parsedName
= nullptr);
113 static bool IsPlainReadableASCII(const CString
& text
);
115 static bool StartsWith(const wchar_t* heystack
, const CString
& needle
);
116 static bool StartsWithI(const wchar_t* heystack
, const CString
& needle
);
117 static bool WriteStringToTextFile(LPCTSTR path
, LPCTSTR text
, bool bUTF8
= true);
118 static bool EndsWith(const CString
& heystack
, const wchar_t* needle
);
119 static bool EndsWith(const CString
& heystack
, const wchar_t needle
);
120 static bool EndsWithI(const CString
& heystack
, const wchar_t* needle
);
122 static bool StartsWith(const wchar_t* heystack
, const wchar_t* needle
);
123 static bool StartsWith(const char* heystack
, const char* needle
);
126 * Writes the string \text to the file \path, either in utf16 or utf8 encoding,
127 * depending on the \c bUTF8 param.
129 static bool WriteStringToTextFile(const std::wstring
& path
, const std::wstring
& text
, bool bUTF8
= true);
132 * Replace all pipe (|) character in the string with a nullptr character. Used
133 * for passing into Win32 functions that require such representation
135 static void PipesToNulls(TCHAR
* buffer
, size_t length
);
136 static void PipesToNulls(TCHAR
* buffer
);