OSDN Git Service

Merge branch 'master' of git://repo.or.cz/TortoiseGit
[tortoisegit/TortoiseGitJp.git] / src / ResText / Utils.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006 - Stefan Kueng\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 #include "StdAfx.h"\r
19 #include ".\utils.h"\r
20 \r
21 CUtils::CUtils(void)\r
22 {\r
23 }\r
24 \r
25 CUtils::~CUtils(void)\r
26 {\r
27 }\r
28 \r
29 void CUtils::StringExtend(LPTSTR str)\r
30 {\r
31         TCHAR * cPos = str;\r
32         do\r
33         {\r
34                 cPos = _tcschr(cPos, '\\');\r
35                 if (cPos)\r
36                 {\r
37                         memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));\r
38                         *cPos = '\\';\r
39                         *(cPos+1) = '\\';\r
40                         cPos++;\r
41                         cPos++;\r
42                 }\r
43         } while (cPos != NULL);\r
44         cPos = str;\r
45         do\r
46         {\r
47                 cPos = _tcschr(cPos, '\n');\r
48                 if (cPos)\r
49                 {\r
50                         memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));\r
51                         *cPos = '\\';\r
52                         *(cPos+1) = 'n';\r
53                 }\r
54         } while (cPos != NULL);\r
55         cPos = str;\r
56         do\r
57         {\r
58                 cPos = _tcschr(cPos, '\r');\r
59                 if (cPos)\r
60                 {\r
61                         memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));\r
62                         *cPos = '\\';\r
63                         *(cPos+1) = 'r';\r
64                 }\r
65         } while (cPos != NULL);\r
66         cPos = str;\r
67         do\r
68         {\r
69                 cPos = _tcschr(cPos, '\t');\r
70                 if (cPos)\r
71                 {\r
72                         memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));\r
73                         *cPos = '\\';\r
74                         *(cPos+1) = 't';\r
75                 }\r
76         } while (cPos != NULL);\r
77         cPos = str;\r
78         do\r
79         {\r
80                 cPos = _tcschr(cPos, '"');\r
81                 if (cPos)\r
82                 {\r
83                         memmove(cPos+1, cPos, _tcslen(cPos)*sizeof(TCHAR));\r
84                         *cPos = '\\';\r
85                         *(cPos+1) = '"';\r
86                         cPos++;\r
87                         cPos++;\r
88                 }\r
89         } while (cPos != NULL);\r
90 }\r
91 \r
92 void CUtils::StringCollapse(LPTSTR str)\r
93 {\r
94         TCHAR * cPos = str;\r
95         do\r
96         {\r
97                 cPos = _tcschr(cPos, '\\');\r
98                 if (cPos)\r
99                 {\r
100                         if (*(cPos+1) == 'n')\r
101                         {\r
102                                 *cPos = '\n';\r
103                                 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));\r
104                         }\r
105                         else if (*(cPos+1) == 'r')\r
106                         {\r
107                                 *cPos = '\r';\r
108                                 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));\r
109                         }\r
110                         else if (*(cPos+1) == 't')\r
111                         {\r
112                                 *cPos = '\t';\r
113                                 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));\r
114                         }\r
115                         else if (*(cPos+1) == '"')\r
116                         {\r
117                                 *cPos = '"';\r
118                                 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));\r
119                         }\r
120                         else if (*(cPos+1) == '\\')\r
121                         {\r
122                                 *cPos = '\\';\r
123                                 memmove(cPos+1, cPos+2, (_tcslen(cPos+2)+1)*sizeof(TCHAR));\r
124                         }\r
125                         cPos++;\r
126                 }\r
127         } while (cPos != NULL);\r
128 }\r
129 \r
130 void CUtils::Error()\r
131 {\r
132         LPVOID lpMsgBuf;\r
133         if (!FormatMessage( \r
134                 FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
135                 FORMAT_MESSAGE_FROM_SYSTEM | \r
136                 FORMAT_MESSAGE_IGNORE_INSERTS,\r
137                 NULL,\r
138                 GetLastError(),\r
139                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\r
140                 (LPTSTR) &lpMsgBuf,\r
141                 0,\r
142                 NULL ))\r
143         {\r
144                 return;\r
145         }\r
146 \r
147         // Display the string.\r
148         _ftprintf(stderr, _T("%s\n"), (LPCTSTR)lpMsgBuf);\r
149 \r
150         // Free the buffer.\r
151         LocalFree( lpMsgBuf );\r
152 }