Provide (experimental) clang-format file
[TortoiseGit.git] / src / ResText / Utils.h
blob4f446ae42ab9b24ba8e4975f3445cce10961683f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007, 2012, 2015 - 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.
18 #pragma once
19 #include <string>
20 #include <algorithm>
21 #include <functional>
23 /**
24 * \ingroup ResText
25 * static helper methods for ResText.
27 class CUtils
29 public:
30 CUtils(void);
31 ~CUtils(void);
32 static void StringExtend(LPTSTR str);
33 static void StringCollapse(LPTSTR str);
34 static void Error();
35 static void SearchReplace(std::wstring& str, const std::wstring& toreplace, const std::wstring& replacewith);
39 // trim from start
40 inline std::string &ltrim(std::string &s)
42 s.erase(s.cbegin(), std::find_if(s.cbegin(), s.cend(), [](const auto& c) { return !iswspace(c); }));
43 return s;
46 // trim from end
47 inline std::string &rtrim(std::string &s)
49 s.erase(std::find_if(s.crbegin(), s.crend(), [](const auto& c) { return !iswspace(c); }).base(), s.cend());
50 return s;
53 // trim from both ends
54 inline std::string &trim(std::string &s)
56 return ltrim(rtrim(s));
59 // trim from start
60 inline std::wstring &ltrim(std::wstring &s)
62 s.erase(s.cbegin(), std::find_if(s.cbegin(), s.cend(), [](const auto& c) { return !iswspace(c); }));
63 return s;
66 // trim from end
67 inline std::wstring &rtrim(std::wstring &s)
69 s.erase(std::find_if(s.crbegin(), s.crend(), [](const auto& c) { return !iswspace(c); }).base(), s.cend());
70 return s;
73 // trim from both ends
74 inline std::wstring &trim(std::wstring &s)
76 return ltrim(rtrim(s));