aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg_Strings.cpp
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-10-12 11:22:25 -0700
committerGitHub <noreply@github.com>2017-10-12 11:22:25 -0700
commit85e6b1b36e734c0db50464b07b77589d63c3c875 (patch)
tree095289838517a64f06298b1a05ded47a7139d7d9 /toolsrc/src/vcpkg_Strings.cpp
parentd7a313c5c356e1641f18cd14ad0ac0c3901bc0bf (diff)
parent9c3f9582fb4541a59e4282269e4f6c9c7debcc3e (diff)
downloadvcpkg-85e6b1b36e734c0db50464b07b77589d63c3c875.tar.gz
vcpkg-85e6b1b36e734c0db50464b07b77589d63c3c875.zip
Merge branch 'master' into vtk-components
Diffstat (limited to 'toolsrc/src/vcpkg_Strings.cpp')
-rw-r--r--toolsrc/src/vcpkg_Strings.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp
index 0c1c1f9f9..bbe6b29cd 100644
--- a/toolsrc/src/vcpkg_Strings.cpp
+++ b/toolsrc/src/vcpkg_Strings.cpp
@@ -73,14 +73,20 @@ namespace vcpkg::Strings
{
std::wstring to_utf16(const CStringView s)
{
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
- return conversion.from_bytes(s);
+ const int size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
+ std::wstring output;
+ output.resize(size - 1);
+ MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), size - 1);
+ return output;
}
std::string to_utf8(const CWStringView w)
{
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
- return conversion.to_bytes(w);
+ const int size = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr);
+ std::string output;
+ output.resize(size - 1);
+ WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, output.data(), size - 1, nullptr, nullptr);
+ return output;
}
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern)
@@ -100,7 +106,7 @@ namespace vcpkg::Strings
int case_insensitive_ascii_compare(const CStringView left, const CStringView right)
{
- return _stricmp(left, right);
+ return _stricmp(left.c_str(), right.c_str());
}
std::string ascii_to_lowercase(const std::string& input)
@@ -110,6 +116,11 @@ namespace vcpkg::Strings
return output;
}
+ bool case_insensitive_ascii_starts_with(const std::string& s, const std::string& pattern)
+ {
+ return _strnicmp(s.c_str(), pattern.c_str(), pattern.size()) == 0;
+ }
+
void trim(std::string* s)
{
s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end());
@@ -130,18 +141,26 @@ namespace vcpkg::Strings
trim(&s);
}
- Util::erase_remove_if(*strings, [](const std::string& s) { return s == ""; });
+ Util::erase_remove_if(*strings, [](const std::string& s) { return s.empty(); });
}
std::vector<std::string> split(const std::string& s, const std::string& delimiter)
{
std::vector<std::string> output;
+ if (delimiter.empty())
+ {
+ output.push_back(s);
+ return output;
+ }
+
+ const size_t delimiter_length = delimiter.length();
size_t i = 0;
for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos))
{
output.push_back(s.substr(i, pos - i));
- i = ++pos;
+ pos += delimiter_length;
+ i = pos;
}
// Add the rest of the string after the last delimiter, unless there is nothing after it