本文整理汇总了C++中std::wstring::length方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::length方法的具体用法?C++ wstring::length怎么用?C++ wstring::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deleteForward
void deleteForward()
{
if (selectionStart != caretPos) {
unsigned min = std::min(caretPos, selectionStart);
unsigned max = std::max(caretPos, selectionStart);
text.erase(text.begin() + min, text.begin() + max);
selectionStart = caretPos = min;
}
else if (caretPos < text.length()) {
unsigned oldCaret = caretPos;
caretPos += 1;
text.erase(text.begin() + oldCaret, text.begin() + caretPos);
selectionStart = caretPos = oldCaret;
}
}
示例2:
/** I'm not sure what this does really --mxcl */
std::wstring
Moose::fixStr(const std::wstring& str)
{
std::wstring ret;
if (str.length() == 0) return str;
// Mac strings store the length in the first char of the string:
size_t len = (size_t)str[0];
ret = str.substr(1);
if(len > 0 && len < ret.length())
{
ret = ret.substr(0,len);
}
return ret;
}
示例3:
WgCharSeqLiteral::WgCharSeqLiteral( const std::wstring& str, int ofs, int len )
{
const wchar_t * p = str.c_str();
int strlen = str.length();
if( ofs + len > strlen )
{
if( ofs > strlen )
ofs = strlen;
len = strlen - ofs;
}
m_type = UTF16;
m_pChar = p + ofs;
m_nbChars = len;
}
示例4: mglFindArg
//-----------------------------------------------------------------------------
int MGL_LOCAL_PURE mglFindArg(const std::wstring &str)
{
register long l=0,k=0,i;
for(i=0;i<long(str.length());i++)
{
if(str[i]=='\'') l++;
if(str[i]=='{') k++;
if(str[i]=='}') k--;
if(l%2==0 && k==0)
{
if(str[i]=='#' || str[i]==';') return -i;
if(str[i]<=' ') return i;
}
}
return 0;
}
示例5: file
std::vector<std::wstring> html_extract(const std::wstring& filename, const std::wstring& path_str) {
if (!path_str.length()) return std::vector<std::wstring>();
std::vector<std::wstring> re;
boost::property_tree::wptree pt;
std::wstringstream ss;
std::wifstream file(filename);
if (!file) throw std::runtime_error("cannot open file");
static_assert(sizeof(wchar_t) == 2, "In function html_extract, wchar_t is not UTF16.");
file.imbue(std::locale(std::locale(), new std::codecvt_utf8_utf16<wchar_t>()));//UTF-8 -> UTF16(wchar_t in Windows.)
convert_html_to_xml(file, ss);
read_xml(ss, pt, boost::property_tree::xml_parser::no_comments);
const auto path = detail::parse_path(path_str);
auto& body = pt.get_child(L"html.body");//HTML has body tag. if not exist, exception will be thrown.
detail::html_extract_impl(re, body, path);//analyse
return re;
}
示例6: InvokeCallback
void InvokeCallback(JNIEnv *env, jobject obj, jobject callback, std::wstring filename)
{
jstring j_filename = env->NewString((const jchar *)filename.c_str(), filename.length());
jclass fileClass = env->FindClass("java/io/File");
jmethodID fileConstructor = env->GetMethodID(fileClass, "<init>", "(Ljava/lang/String;)V");
jobject fileObj = env->NewObject(fileClass, fileConstructor, j_filename);
jclass resultClass = env->FindClass("org/eclipse/mylyn/sandbox/search/ui/SearchResult");
jmethodID resultConstructor = env->GetMethodID(resultClass, "<init>", "(Ljava/io/File;)V");
jobject resultObj = env->NewObject(resultClass, resultConstructor, fileObj);
jclass jc = env->GetObjectClass(callback);
jmethodID mid = env->GetMethodID(jc, "searchResult","(Lorg/eclipse/mylyn/sandbox/search/ui/SearchResult;)V");
env->CallObjectMethod(callback, mid, resultObj);
}
示例7: c
std::string WStringToUTF8(const std::wstring& s)
{
std::string os;
for (size_t i = 0; i < s.length(); ++i)
{
const wchar_t c(s[i]);
if (c < 0x80)
{
os += static_cast<uint8_t>(c);
}
else if (c < 0x800)
{
os += static_cast<uint8_t>(((c>>6)&0x1F)|0xC0);
os += static_cast<uint8_t>((c&0x3F)|0x80);
}
else if (c < 0xd800)
示例8: DrawLine
//--------------------------------------------------------------------------------
void TextActor::DrawLine( const std::wstring& text )
{
// Check the length of the string, and use the line justification to advance
// the cursor an appropriate amount before actually drawing the line of text.
float fWidth = m_pSpriteFont->GetStringWidth( text ) * m_fPhysicalScale;
switch( m_LineJustification )
{
case LineJustification::LEFT:
// No change needed - just draw the text from teh current cursor position
break;
case LineJustification::CENTER:
// Advance cursor to the 'left' by half the string width
AdvanceCursor( -fWidth * 0.5f );
break;
case LineJustification::RIGHT:
// Advance the cursor by the full size of the string.
AdvanceCursor( -fWidth );
}
for ( UINT i = 0; i < text.length(); i++ )
{
wchar_t character = text[i];
if ( character == ' ' ) {
// For a space, we simply move over one space's width for the next
// character.
Space();
} else if ( character == '\n' ) {
// Go back to the original location on xdir, and advance along ydir.
NewLine();
} else {
// If this is an actual character, then draw it!
DrawCharacter( character );
}
}
//NewLine();
}
示例9: tokenize
std::vector<std::wstring> StringUtil::tokenize(const std::wstring& str, const std::wstring& delimiters, bool allowEmptyTokenString)
{
std::vector<std::wstring> tokens;
std::wstring::size_type delimPos = 0, tokenPos = 0, pos = 0;
if (str.length() < 1)
return tokens;
while (true)
{
delimPos = str.find_first_of(delimiters, pos);
tokenPos = str.find_first_not_of(delimiters, pos);
if (std::wstring::npos != delimPos)
{
if (std::wstring::npos != tokenPos)
{
if (tokenPos < delimPos)
{
tokens.push_back(str.substr(pos, delimPos - pos));
}
else
{
if (allowEmptyTokenString) tokens.push_back(L"");
}
}
else
{
if (allowEmptyTokenString) tokens.push_back(L"");
}
pos = delimPos + 1;
}
else
{
if (std::wstring::npos != tokenPos)
{
tokens.push_back(str.substr(pos));
}
else
{
if (allowEmptyTokenString) tokens.push_back(L"");
}
break;
}
}
return tokens;
}// tokenize(wstring)
示例10: SetRegValue
LSTATUS SetRegValue(HKEY rootKey, std::wstring wsSubKey, std::wstring wsData) {
HKEY key;
LSTATUS retValue = RegOpenKeyEx(rootKey, _T(""), 0, KEY_WRITE | KEY_READ, &key);
if (retValue != ERROR_SUCCESS) {
std::cout << "打开注册表失败" << std::endl;
return retValue;
}
//依次创建wsSubKey路径中的子键
std::vector<std::wstring> subKeyVec;
int newPos = 0;
int oldPos = 0;
while (true) {
newPos = wsSubKey.find(_T("\\"), oldPos);
if (newPos != std::string::npos) {
subKeyVec.push_back(wsSubKey.substr(oldPos, newPos - oldPos));
oldPos = newPos + 1;
}
else {
break;
}
}
if (subKeyVec.size() == 0) {
return ERROR_INVALID_FUNCTION;
}
HKEY fatherKey = key;
HKEY subKey = 0;
for (size_t i = 0; i < subKeyVec.size(); ++i) {
DWORD dw;
RegCreateKeyEx(fatherKey,
subKeyVec[i].c_str(),
NULL,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ, NULL,
&subKey,
&dw);
RegCloseKey(fatherKey);
fatherKey = subKey;
}
retValue = RegSetValue(subKey, _T(""), REG_SZ, wsData.c_str(), wsData.length());
RegCloseKey(subKey);
return retValue;
}
示例11: ELStripLeadingSpaces
std::wstring ELStripLeadingSpaces(std::wstring input)
{
size_t i = 0;
//< Search input for the first non-space character
while (i < input.length())
{
if (input.at(i) != ' ')
{
break;
}
i++;
}
return input.substr(i, std::wstring::npos);
}
示例12: WideToNarrow
std::string WideToNarrow(const std::wstring& ws)
{
const std::locale locale(""); // WARNING: This only needs to be done one time.
typedef std::codecvt<wchar_t, char, std::mbstate_t> converter_type;
const converter_type& converter = std::use_facet<converter_type>(locale);
std::vector<char> to(ws.length() * converter.max_length());
std::mbstate_t state;
const wchar_t* from_next;
char* to_next;
const converter_type::result result = converter.out(state, ws.data(), ws.data() + ws.length(), from_next, &to[0], &to[0] + to.size(), to_next);
if (result == converter_type::ok || result == converter_type::noconv)
{
const std::string s(&to[0], to_next);
return s;
}
return "";
}
示例13: GetVideoPic
//获取视频第5秒的截图
bool CCommonInterface::GetVideoPic(std::wstring lsVideoPath, std::wstring &lsPicPath, int iTimes, std::wstring strCachePath)
{
//ffmpeg -ss 5 -i test.mp4 -f image2 -y -s 350x240 test1.jpg
//如果没有指定本地路径,先要获取一个临时路径用于存储生成的图片
if (lsPicPath.length() <= 0)
{
wstring strFilePath = strCachePath;
strFilePath += _T("\\TempPic\\");
if (!PathFileExists(strFilePath.c_str()))
{
CCommonInterface comter;
comter.CreateDir(strFilePath);
}
SYSTEMTIME stime = { 0 };
GetLocalTime(&stime);
TCHAR szCurrentTime[MAX_PATH] = { 0 };
_stprintf(szCurrentTime, _T("%s%02d%02d%02d%02d%02d%04d.jpg"),
_T("Pic"), stime.wMonth, stime.wDay, stime.wHour, stime.wMinute, stime.wSecond, stime.wMilliseconds);
strFilePath += szCurrentTime;
lsPicPath = strFilePath;
}
CCommonInterface ComInterface;
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = _T("open");
sei.nShow = SW_NORMAL;
TCHAR szCacheUpdateTempPath[MAX_PATH] = { 0 };
wstring strFfmpegPath = strCachePath;
strFfmpegPath += _T("\\Ffmpeg\\ffmpeg.exe");
TCHAR szParames[MAX_PATH * 2] = { 0 };
StringCchPrintf(szParames, MAX_PATH * 2, _T("-ss %d -i \"%s\" -f image2 -y -s 854x480 \"%s\""),
iTimes,
lsVideoPath.c_str(),
lsPicPath.c_str());
sei.lpFile = strFfmpegPath.c_str();
sei.lpParameters = szParames;
sei.nShow = SW_HIDE;
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
//GetLogFun(Info)(_T("....ffmpeg的参数%s"), sei.lpParameters);
if (ShellExecuteEx(&sei))
{
//等待进程结束
WaitForSingleObject(sei.hProcess, INFINITE);
return true;
}
return false;
}
示例14: rv
std::string w2mb(const std::wstring& v)
{
if (v.empty())
return{};
size_t wideLen = v.length();
int iLen = WideCharToMultiByte(CP_ACP, 0, v.c_str(), wideLen, nullptr, 0, NULL, NULL);
if (iLen <= 0)
return{};
std::string rv(iLen, '\0');
iLen = WideCharToMultiByte(CP_ACP, 0, v.c_str(), wideLen, &rv[0], iLen, NULL, NULL);
if (iLen)
return rv;
return{};
}
示例15: directoryCheck
unsigned int RvFindRegex::directoryCheck(const std::wstring& directory, const std::wstring& pathRoot) const
{
if (pathRoot.empty())
return DIRECTORY_DONTCARE;
size_t dirLength = directory.length();
if (dirLength > pathRoot.size())
{
if (boost::algorithm::istarts_with(directory,pathRoot))
return DIRECTORY_INCLUDE;
else
return DIRECTORY_EXCLUDE;
}
if (boost::algorithm::istarts_with(pathRoot,directory))
return DIRECTORY_INCLUDE;
else
return DIRECTORY_EXCLUDE;
}