本文整理汇总了C++中wstring::length方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::length方法的具体用法?C++ wstring::length怎么用?C++ wstring::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: callback
void CALLBACK callback(MethodID methodID, int callID, wstring& address, Cause cause, wstring* callInfo) {
static HANDLE hMutex = CreateMutex(NULL, FALSE, "callbackMutex");
DWORD dwWaitResult = WaitForSingleObject(hMutex, 5000L);
logger->debug("Entering callback method %d: callID=%d, address=%S...", methodID, callID, address.c_str());
if(dwWaitResult == WAIT_OBJECT_0) {
try{
JNIEnv *localEnv = NULL;
g_javaVM->AttachCurrentThread((void**)&localEnv, NULL);
jclass cls = localEnv->GetObjectClass(g_thisObj);
jmethodID callbackID = NULL;
for (int retry = 0; callbackID == NULL && retry < 5; retry++) {
callbackID = localEnv->GetMethodID(cls, "callback", "(IILjava/lang/String;I[Ljava/lang/String;)V");
// if we have to try again, delay for 250 ms
if (callbackID == NULL && retry < 5) {
Sleep(250);
}
logger->debug("callback methodID: %p, retry=%d", callbackID, retry);
}
if (callbackID == NULL) {
logger->fatal("Callback method not available.");
} else {
jint jMethodID = methodID;
jint jCallID = callID;
jstring jAddress = localEnv->NewString(((jchar *)address.c_str()), (jsize)address.length());
jint jCause = cause;
jobjectArray objCallInfo = NULL;
if(callInfo != NULL) {
logger->debug("Setting callInfo...");
jclass oCls = localEnv->FindClass("java/lang/String");
objCallInfo = localEnv->NewObjectArray(4, oCls, NULL);
for (int i=0; i<4; i++) {
jstring jInfo = localEnv->NewString(((jchar *)callInfo[i].c_str()), (jsize)callInfo[i].length());
localEnv->SetObjectArrayElement(objCallInfo, i, jInfo);
}
} else {
logger->debug("No callInfo for this callback.");
}
localEnv->CallVoidMethod(g_thisObj, callbackID, jMethodID, jCallID, jAddress, jCause, objCallInfo);
g_javaVM->DetachCurrentThread();
logger->debug("Java callback successfully called.");
}
} catch(...){
logger->fatal("Callback failed.");
}
ReleaseMutex(hMutex);
} else {
logger->fatal("Cannot obtain callback mutex: dwWaitResult=%08X.", dwWaitResult);
}
}
示例2:
XercesString::XercesString(const wstring& in)
: basic_string<XMLCh>()
{
for(unsigned int i=0; i<in.length(); ++i) {
wchar_t utf32 = in[i];
if (utf32 >= 0x10000UL) {
push_back(0xD800 - 0x40 + (utf32 >> 10));
push_back(0xDC00 + (utf32 & 0x3FF));
}
else
示例3: WideCharToMultiByte
std::string W2Ansi( const wstring& wszIn )
{
string szRet;
if (wszIn.length() <= 0)
{
return szRet;
}
LPCWSTR pwszSrc = wszIn.c_str();
int nWLen = wszIn.length();
int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
char* pszDst = new char[nLen+1];
assert(NULL != pszDst);
WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
pszDst[nLen] = '\0';
szRet =pszDst;
delete [] pszDst;
return szRet;
}
示例4: Tidy
wstring Tidy(wstring filename) { //Changes uppercase to lowercase and removes trailing spaces to do what Windows filesystem does to filenames.
size_t endpos = filename.find_last_not_of(L" \t");
if (filename.npos == endpos) return (L""); //sanity check for empty string
else {
filename = filename.substr(0, endpos+1);
for (unsigned int i = 0; i < filename.length(); i++) filename[i] = tolower(filename[i]);
return (filename);
}
}
示例5:
/**
* predict MorphologicalInfo by suffix
*/
vector<MorphologicalInfo> SuffixModelTrie::getMorphologicalPredictionBySuffix(wstring _word)
{
vector<MorphologicalInfo> result = vector<MorphologicalInfo>();
SuffixModelNode* currentNode = root;
int suffixLength = 0;
for (int i = (int) _word.length() - 1; i >= 0; --i)
{
SuffixModelNode* tmpNode = currentNode->findChildNode(_word.at(i));
if (tmpNode == NULL)
{
break;
}
currentNode = tmpNode;
suffixLength++;
//wcout << _word.at(i) << " : " << currentNode->getFeatureFrequencyMap().size() << endl;
}
if (suffixLength == 0)
{
return result;
}
//wcout << "Suffix length = " << suffixLength << endl;
map<int, int> _featureFrequencyMap = currentNode->getFeatureFrequencyMap();
//wcout << "_featureFrequencyMap's size = " << _featureFrequencyMap.size() << endl;
map<int, int>::iterator iter;
//@TODO : \u043f\u0435\u0440\u0440\u0441\u0441\u043e\u043d//here was cyrrilic symbols: перрссон
for (iter = _featureFrequencyMap.begin(); iter != _featureFrequencyMap.end(); ++iter)
{
int _featureId = iter->first;
int _frequency = iter->second;
int _basicFeatureListId = _featureId / 1000;
int _featureListId = _featureId % 1000;
wstring _initial_form = suffixLength < (int) _word.length() ? L"-" + _word.substr(_word.length() - suffixLength) : _word;
MorphologicalInfo _morphologicalInfo;
_morphologicalInfo.basicFeatureListId = _basicFeatureListId;
_morphologicalInfo.featureListId = _featureListId;
_morphologicalInfo.frequency = _frequency;
_morphologicalInfo.initial_form = _initial_form;
_morphologicalInfo.lemmaId = 0;
_morphologicalInfo.suffix_length = suffixLength;
result.push_back(_morphologicalInfo);
}
return result;
}
示例6:
void sbuf_stream::getUTF16(wstring &utf16_string) {
sbuf.getUTF16(offset, utf16_string);
size_t num_bytes = utf16_string.length() * 2;
if (num_bytes > 0) {
// if anything was read then also skip \U0000
num_bytes += 2;
}
offset += num_bytes;
return;
}
示例7: IsDigitalW
BOOL base_string::IsDigitalW(wstring wstrSrc)
{
int nIndex = 0;
size_t nPos = wstrSrc.find('.');
if (wstrSrc.empty())
{
return FALSE;
}
else if (nPos == wstring::npos)
{
for (nIndex = 0; nIndex < wstrSrc.length(); nIndex++)
{
if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
{
return FALSE;
}
}
}
else if (nPos == wstrSrc.length() - 1)
{
return FALSE;
}
else if (nPos != wstring::npos)
{
for (nIndex = 0; nIndex < nPos; nIndex++)
{
if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
{
return FALSE;
}
}
for (nIndex = nPos + 1; nIndex < wstrSrc.length(); nIndex++)
{
if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
{
return FALSE;
}
}
}
return TRUE;
}
示例8: HexToARGB
COLORREF HexToARGB(const wstring& text) {
int i = text.length() - 6;
if (i < 0) return 0;
unsigned int r, g, b;
r = wcstoul(text.substr(i + 0, 2).c_str(), NULL, 16);
g = wcstoul(text.substr(i + 2, 2).c_str(), NULL, 16);
b = wcstoul(text.substr(i + 4, 2).c_str(), NULL, 16);
return RGB(r, g, b);
}
示例9:
WinRegKeyExeption::WinRegKeyExeption(LONG errorcode, HKEY rootkey, wstring subkey, wstring label=L"")
:m_errorcode(errorcode),m_key(towstring<HKEY>(rootkey))
{
m_key.append(L"\\");
m_key.append(subkey);
if(label.length()>0)
{
m_key.append(L"\\");
m_key.append(label);
}
}
示例10: disconnectFileName
wstring ConnectedShortcut::disconnectFileName(const wstring& shortcutName)
{
const wstring suffix = L" + " SHORT_APP_NAME L".lnk";
if (PathMatchSpec(shortcutName.data(), (L"*" + suffix).data()) == FALSE)
return shortcutName;
wstring newName = shortcutName;
newName.erase(newName.length() - suffix.length());
newName.append(L".lnk");
return newName;
}
示例11: Trim
void Trim(wstring& str, const wchar_t trim_chars[],
bool trim_left, bool trim_right) {
if (str.empty())
return;
const size_t index_begin =
trim_left ? str.find_first_not_of(trim_chars) : 0;
const size_t index_end =
trim_right ? str.find_last_not_of(trim_chars) : str.length() - 1;
if (index_begin == wstring::npos || index_end == wstring::npos) {
str.clear();
return;
}
if (trim_right)
str.erase(index_end + 1, str.length() - index_end + 1);
if (trim_left)
str.erase(0, index_begin);
}
示例12: stringToNumber
double stringToNumber( wstring& text )
{
wstring::size_type endptr;
double number = std::stod( text, &endptr );
// the conversion is successful only when no text remains after the number
if( endptr != text.length() )
{
throw new std::invalid_argument( "stringToNumber called on a text that contains characters after the number" );
}
return( number );
}
示例13:
wstring
TransferRule::category_name(const wstring& lemma, const wstring& tags) {
wstring catname=L"";
if (lemma.length()>0)//TODO: codificar bien el caracter extraño
catname+=StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(lemma,L"#",L"_"),L"\u2019",L"_"),L"'",L"QUOT")+L"_";
catname+=StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(tags,L".",L""),L"*",L"_"),L"+",L"plus"),L"@",L"arroba");
return catname;
}
示例14: OnException
void qtDLGDetailInfo::OnException(wstring functionName, wstring moduleName, quint64 exceptionOffset, quint64 exceptionCode, DWORD processID, DWORD threadID)
{
qtDLGNanomite *pMainWindow = qtDLGNanomite::GetInstance();
pMainWindow->lExceptionCount++;
tblExceptions->insertRow(tblExceptions->rowCount());
tblExceptions->setItem(tblExceptions->rowCount() - 1,0,
new QTableWidgetItem(QString("%1").arg(exceptionOffset,16,16,QChar('0'))));
tblExceptions->setItem(tblExceptions->rowCount() - 1,1,
new QTableWidgetItem(QString("%1").arg(exceptionCode,8,16,QChar('0'))));
tblExceptions->setItem(tblExceptions->rowCount() - 1,2,
new QTableWidgetItem(QString().sprintf("%08X / %08X",processID,threadID)));
if(functionName.length() > 0 )
tblExceptions->setItem(tblExceptions->rowCount() - 1,3,
new QTableWidgetItem(QString::fromStdWString(moduleName).append(".").append(QString::fromStdWString(functionName))));
QString logMessage;
if(functionName.length() > 0 && moduleName.length() > 0)
logMessage = QString("[!] Exception - PID: %1 TID: %2 - ExceptionCode: %3 - ExceptionOffset: %4 - %[email protected]%6")
.arg(processID,6,16,QChar('0'))
.arg(threadID,6,16,QChar('0'))
.arg(exceptionCode,8,16,QChar('0'))
.arg(exceptionOffset,16,16,QChar('0'))
.arg(QString::fromStdWString(functionName))
.arg(QString::fromStdWString(moduleName));
else
logMessage = QString("[!] Exception - PID: %1 TID: %2 - ExceptionCode: %3 - ExceptionOffset: %4")
.arg(processID,6,16,QChar('0'))
.arg(threadID,6,16,QChar('0'))
.arg(exceptionCode,8,16,QChar('0'))
.arg(exceptionOffset,16,16,QChar('0'));
pMainWindow->logView->OnLog(logMessage);
pMainWindow->UpdateStateBar(1);
}
示例15: getWeightedFrequency
word_frequency_t getWeightedFrequency(wstring const &text)
{
word_frequency_t freq;
for(int i = 0; i < text.length() - WORD_MAXIMUM; i++) {
wstring candidate = L"";
for(int j = WORD_MINIMUM; j <= WORD_MAXIMUM; j++) {
assert(i + j <= text.length() && "access violation");
candidate.push_back(text[i + j - 1]);
auto it = freq.find(candidate);
if(it != freq.end())
it->second += 1.0;
else
freq[candidate] = 1.0;
}
}
for(auto &it : freq) {
int len = it.first.length();
it.second = it.second * len * len - 0.3;
}
return freq;
}