1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2012 - 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.
20 #include "FormatMessageWrapper.h"
30 void CUtils::StringExtend(LPTSTR str
)
35 cPos
= _tcschr(cPos
, '\\');
38 memmove(cPos
+1, cPos
, _tcslen(cPos
)*sizeof(TCHAR
));
44 } while (cPos
!= NULL
);
48 cPos
= _tcschr(cPos
, '\n');
51 memmove(cPos
+1, cPos
, _tcslen(cPos
)*sizeof(TCHAR
));
55 } while (cPos
!= NULL
);
59 cPos
= _tcschr(cPos
, '\r');
62 memmove(cPos
+1, cPos
, _tcslen(cPos
)*sizeof(TCHAR
));
66 } while (cPos
!= NULL
);
70 cPos
= _tcschr(cPos
, '\t');
73 memmove(cPos
+1, cPos
, _tcslen(cPos
)*sizeof(TCHAR
));
77 } while (cPos
!= NULL
);
81 cPos
= _tcschr(cPos
, '"');
84 memmove(cPos
+1, cPos
, _tcslen(cPos
)*sizeof(TCHAR
));
90 } while (cPos
!= NULL
);
93 void CUtils::StringCollapse(LPTSTR str
)
98 cPos
= _tcschr(cPos
, '\\');
101 if (*(cPos
+1) == 'n')
104 memmove(cPos
+1, cPos
+2, (_tcslen(cPos
+2)+1)*sizeof(TCHAR
));
106 else if (*(cPos
+1) == 'r')
109 memmove(cPos
+1, cPos
+2, (_tcslen(cPos
+2)+1)*sizeof(TCHAR
));
111 else if (*(cPos
+1) == 't')
114 memmove(cPos
+1, cPos
+2, (_tcslen(cPos
+2)+1)*sizeof(TCHAR
));
116 else if (*(cPos
+1) == '"')
119 memmove(cPos
+1, cPos
+2, (_tcslen(cPos
+2)+1)*sizeof(TCHAR
));
121 else if (*(cPos
+1) == '\\')
124 memmove(cPos
+1, cPos
+2, (_tcslen(cPos
+2)+1)*sizeof(TCHAR
));
128 } while (cPos
!= NULL
);
133 CFormatMessageWrapper errorDetails
;
135 _ftprintf (stderr
, _T("%s\n"), (LPCTSTR
)errorDetails
);
138 void CUtils::SearchReplace(std::wstring
& str
, const std::wstring
& toreplace
, const std::wstring
& replacewith
)
141 std::wstring::size_type pos
= 0;
142 for ( ; ; ) // while (true)
144 std::wstring::size_type next
= str
.find(toreplace
, pos
);
145 result
.append(str
, pos
, next
-pos
);
146 if( next
!= std::string::npos
)
148 result
.append(replacewith
);
149 pos
= next
+ toreplace
.size();