port from perforce
This commit is contained in:
57
aiwaz/Aiwaz/Common/StringHelper.h
Normal file
57
aiwaz/Aiwaz/Common/StringHelper.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline bool equal_nocase(const std::string &argStringA, const std::string &argStringB)
|
||||
{
|
||||
return 0 == stricmp (argStringA.c_str(), argStringB.c_str());
|
||||
}
|
||||
|
||||
inline bool equal_nocase(const std::wstring &argStringA, const std::wstring &argStringB)
|
||||
{
|
||||
return 0 == wcsicmp(argStringA.c_str(), argStringB.c_str());
|
||||
}
|
||||
|
||||
inline std::string to_string8(const std::wstring& argString)
|
||||
{
|
||||
if (argString.empty())
|
||||
return std::string();
|
||||
|
||||
const std::ctype<wchar_t>* cType = &std::use_facet<std::ctype<wchar_t> >(std::locale());
|
||||
|
||||
std::wstring::size_type srcLen = argString.length();
|
||||
const wchar_t* srcBegin = argString.c_str();
|
||||
std::vector<char> tmp(srcLen);
|
||||
|
||||
cType->narrow(srcBegin, srcBegin + srcLen, '\0', &tmp[0]);
|
||||
return std::string(&tmp[0], srcLen);
|
||||
}
|
||||
|
||||
inline std::wstring to_string16(const std::string& argString)
|
||||
{
|
||||
if (argString.empty())
|
||||
return std::wstring();
|
||||
|
||||
const std::ctype<wchar_t>* cType = &std::use_facet<std::ctype<wchar_t> >(std::locale());
|
||||
|
||||
std::wstring::size_type srcLen = argString.length();
|
||||
const char* srcBegin = argString.c_str();
|
||||
std::vector<wchar_t> tmp(srcLen);
|
||||
|
||||
cType->widen(srcBegin, srcBegin + srcLen, &tmp[0]);
|
||||
return std::wstring(&tmp[0], srcLen);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning(default:4996)
|
||||
Reference in New Issue
Block a user