1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2019 - TortoiseGit
4 // Copyright (C) 2003-2006, 2012-2014 - TortoiseSVN
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.
21 #include "FormatMessageWrapper.h"
31 void CUtils::StringExtend(LPWSTR str
)
36 cPos
= wcschr(cPos
, '\\');
39 memmove(cPos
+ 1, cPos
, (wcslen(cPos
) + 1) * sizeof(wchar_t));
49 cPos
= wcschr(cPos
, '\n');
52 memmove(cPos
+ 1, cPos
, (wcslen(cPos
) + 1) * sizeof(wchar_t));
60 cPos
= wcschr(cPos
, '\r');
63 memmove(cPos
+ 1, cPos
, (wcslen(cPos
) + 1) * sizeof(wchar_t));
71 cPos
= wcschr(cPos
, '\t');
74 memmove(cPos
+ 1, cPos
, (wcslen(cPos
) + 1) * sizeof(wchar_t));
82 cPos
= wcschr(cPos
, '"');
85 memmove(cPos
+ 1, cPos
, (wcslen(cPos
) + 1) * sizeof(wchar_t));
94 void CUtils::StringCollapse(LPWSTR str
)
99 cPos
= wcschr(cPos
, '\\');
102 if (*(cPos
+1) == 'n')
105 memmove(cPos
+1, cPos
+ 2, (wcslen(cPos
+ 2) + 1) * sizeof(wchar_t));
107 else if (*(cPos
+1) == 'r')
110 memmove(cPos
+1, cPos
+ 2, (wcslen(cPos
+ 2) +1 ) * sizeof(wchar_t));
112 else if (*(cPos
+1) == 't')
115 memmove(cPos
+1, cPos
+ 2, (wcslen(cPos
+ 2) +1 ) * sizeof(wchar_t));
117 else if (*(cPos
+1) == '"')
120 memmove(cPos
+1, cPos
+ 2, (wcslen(cPos
+ 2) +1 ) * sizeof(wchar_t));
122 else if (*(cPos
+1) == '\\')
125 memmove(cPos
+1, cPos
+ 2, (wcslen(cPos
+ 2) +1 ) * sizeof(wchar_t));
134 CFormatMessageWrapper errorDetails
;
136 fwprintf(stderr
, L
"%s\n", static_cast<LPCWSTR
>(errorDetails
));
139 void CUtils::SearchReplace(std::wstring
& str
, const std::wstring
& toreplace
, const std::wstring
& replacewith
)
142 std::wstring::size_type pos
= 0;
143 for ( ; ; ) // while (true)
145 std::wstring::size_type next
= str
.find(toreplace
, pos
);
146 result
.append(str
, pos
, next
-pos
);
147 if( next
!= std::string::npos
)
149 result
.append(replacewith
);
150 pos
= next
+ toreplace
.size();