aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg_Strings.cpp
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:52:29 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:52:29 -0700
commitd5705e87c42784607bf462159bebe14044a88eca (patch)
treeaded4a5806480ad3e6980b8c5f4dacd61a004614 /toolsrc/src/vcpkg_Strings.cpp
parentc167c70c272a417779e601fffcbdb72278da1848 (diff)
parent3838d5880470fdc884f035ed3d1c67d3bdd1e16e (diff)
downloadvcpkg-d5705e87c42784607bf462159bebe14044a88eca.tar.gz
vcpkg-d5705e87c42784607bf462159bebe14044a88eca.zip
Merge branch 'master' into martin-s-patch-vs2013
Diffstat (limited to 'toolsrc/src/vcpkg_Strings.cpp')
-rw-r--r--toolsrc/src/vcpkg_Strings.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp
index 15851829d..21df2c309 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());
@@ -137,6 +148,12 @@ namespace vcpkg::Strings
{
std::vector<std::string> output;
+ if (delimiter.empty())
+ {
+ output.push_back(s);
+ return output;
+ }
+
size_t i = 0;
for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos))
{