Fixed issue 923: Code spelling fix: function ReadTreeRecurive should be ReadTreeRecursive
[TortoiseGit.git] / src / ResText / Utils.cpp
blob5d27a4045f38554c486ac31ab7203cb411a0b438
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006 - Stefan Kueng
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.
18 #include "StdAfx.h"
19 #include ".\utils.h"
21 CUtils::CUtils(void)
25 CUtils::~CUtils(void)
29 void CUtils::StringExtend(LPTSTR str)
31 TCHAR * cPos = str;
34 cPos = _tcschr(cPos, '\\');
35 if (cPos)
37 memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));
38 *cPos = '\\';
39 *(cPos+1) = '\\';
40 cPos++;
41 cPos++;
43 } while (cPos != NULL);
44 cPos = str;
47 cPos = _tcschr(cPos, '\n');
48 if (cPos)
50 memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));
51 *cPos = '\\';
52 *(cPos+1) = 'n';
54 } while (cPos != NULL);
55 cPos = str;
58 cPos = _tcschr(cPos, '\r');
59 if (cPos)
61 memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));
62 *cPos = '\\';
63 *(cPos+1) = 'r';
65 } while (cPos != NULL);
66 cPos = str;
69 cPos = _tcschr(cPos, '\t');
70 if (cPos)
72 memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));
73 *cPos = '\\';
74 *(cPos+1) = 't';
76 } while (cPos != NULL);
77 cPos = str;
80 cPos = _tcschr(cPos, '"');
81 if (cPos)
83 memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));
84 *cPos = '\\';
85 *(cPos+1) = '"';
86 cPos++;
87 cPos++;
89 } while (cPos != NULL);
92 void CUtils::StringCollapse(LPTSTR str)
94 TCHAR * cPos = str;
97 cPos = _tcschr(cPos, '\\');
98 if (cPos)
100 if (*(cPos+1) == 'n')
102 *cPos = '\n';
103 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));
105 else if (*(cPos+1) == 'r')
107 *cPos = '\r';
108 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));
110 else if (*(cPos+1) == 't')
112 *cPos = '\t';
113 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));
115 else if (*(cPos+1) == '"')
117 *cPos = '"';
118 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));
120 else if (*(cPos+1) == '\\')
122 *cPos = '\\';
123 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));
125 cPos++;
127 } while (cPos != NULL);
130 void CUtils::Error()
132 LPVOID lpMsgBuf;
133 if (!FormatMessage(
134 FORMAT_MESSAGE_ALLOCATE_BUFFER |
135 FORMAT_MESSAGE_FROM_SYSTEM |
136 FORMAT_MESSAGE_IGNORE_INSERTS,
137 NULL,
138 GetLastError(),
139 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
140 (LPTSTR) &lpMsgBuf,
142 NULL ))
144 return;
147 // Display the string.
148 _ftprintf(stderr, _T("%s\n"), (LPCTSTR)lpMsgBuf);
150 // Free the buffer.
151 LocalFree( lpMsgBuf );