本文整理汇总了C++中tstring::length方法的典型用法代码示例。如果您正苦于以下问题:C++ tstring::length方法的具体用法?C++ tstring::length怎么用?C++ tstring::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tstring
的用法示例。
在下文中一共展示了tstring::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formatIntegerValue
static tstring formatIntegerValue(uint64 value)
{
typedef tstring::reverse_iterator rev_iter;
typedef tstring::const_reverse_iterator c_rev_iter;
const tstring rawResult = Core::format<uint64>(value);
const size_t numDigits = (rawResult[0] != TXT('-')) ? rawResult.length() : (rawResult.length()-1);
const tstring separator = getGroupSeparator();
const size_t numSeps = (numDigits-1) / 3;
const size_t total = rawResult.length() + (numSeps * separator.length());
tstring result = tstring(total, TXT(' '));
c_rev_iter it = rawResult.rbegin();
c_rev_iter end = rawResult.rend();
size_t digits = 0;
size_t seps = 0;
rev_iter output = result.rbegin();
while (it != end)
{
*output++ = *it++;
if ( ((++digits % 3) == 0) && (seps++ != numSeps) )
output = std::copy(separator.rbegin(), separator.rend(), output);
}
return result;
}
示例2: ParseLink
bool CDDELink::ParseLink(const tstring& link, tstring& service, tstring& topic, tstring& item)
{
size_t serviceBegin = 0;
size_t serviceEnd = link.find_first_of('|', serviceBegin);
if ( (serviceEnd == tstring::npos) || (serviceEnd == serviceBegin) )
return false;
size_t topicBegin = serviceEnd + 1;
size_t topicEnd = link.find_first_of('!', topicBegin);
if ( (topicEnd == tstring::npos) || (topicEnd == topicBegin) )
return false;
size_t itemBegin = topicEnd + 1;
size_t itemEnd = link.length();
if (itemEnd == itemBegin)
return false;
service = link.substr(serviceBegin, serviceEnd - serviceBegin);
topic = link.substr(topicBegin, topicEnd - topicBegin);
item = link.substr(itemBegin, itemEnd - itemBegin);
ASSERT(service.length() != 0);
ASSERT(topic.length() != 0);
ASSERT(item.length() != 0);
return true;
}
示例3: PaintHintText
void CGrottoHUD::PaintHintText(const tstring& sHint)
{
float flTextWidth = glgui::CLabel::GetTextWidth(sHint, sHint.length(), "sans-serif", 18);
float flFontHeight = glgui::CLabel::GetFontHeight("sans-serif", 18);
glgui::CBaseControl::PaintRect(GetWidth()/2+200 - 5, GetHeight()/2 - 5, flTextWidth + 10, flFontHeight + 10, Color(50, 50, 50, 150), 2);
glgui::CLabel::PaintText(sHint, sHint.length(), "sans-serif", 18, GetWidth()/2+200, GetHeight()/2);
}
示例4: WideCharToMultiByte
void tstring2string(const tstring& src, std::string& dst)
{
#ifdef UNICODE
{
char* newStr = "";
int _len = 0;
if (!src.empty()) {
_len = WideCharToMultiByte(CP_UTF8, 0, src.c_str(),
src.length(), NULL,
0, NULL, NULL);
newStr = new char[_len + 1];
WideCharToMultiByte(CP_UTF8, 0, src.c_str(),
src.length(), newStr,
_len, NULL, NULL);
newStr[_len] = 0; //Null terminator
}
dst = newStr;
delete newStr;
}
#else
dst = src;
#endif
}
示例5: ClearDevNames
//
/// Sets the values for the DEVNAMES structure.
//
void
TPrintDialog::TData::SetDevNames(const tstring& driver, const tstring& device, const tstring& output)
{
ClearDevNames();
// Calculate the required buffer size, as the number of characters incl. null-terminators,
// and the resulting total size, in bytes, of the DEVNAMES structure including trailing strings.
// Then allocate and lock the required amount of global memory.
//
const int n = driver.length() + 1 + device.length() + 1 + output.length() + 1;
const int size = sizeof(DEVNAMES) + (n * sizeof(tchar));
HDevNames = ::GlobalAlloc(GHND, size);
DevNames = static_cast<DEVNAMES*>(::GlobalLock(HDevNames));
DevNames->wDefault = false;
// Calculate the offsets to the strings within DEVNAMES.
// Then copy the given names into DEVNAMES (actually, behind the fixed part of DEVNAMES).
//
// NB! Offsets are in character counts. Here we assume the size of the fixed part of DEVNAMES is divisible
// by the character size. Otherwise the driver name will overwrite the last byte of the fixed part.
// But DEVNAMES is divisible and forever set in stone, so we don't need to consider an odd struct size.
//
CHECK(sizeof(DEVNAMES) % sizeof(tchar) == 0);
const LPTSTR base = reinterpret_cast<LPTSTR>(DevNames);
const LPTSTR pDriver = reinterpret_cast<LPTSTR>(DevNames + 1); // Jump past the the fixed part, assuming even struct size.
const LPTSTR pDevice = pDriver + driver.length() + 1; // Jump past the preceding string, including null-terminator.
const LPTSTR pOutput = pDevice + device.length() + 1;
DevNames->wDriverOffset = static_cast<WORD>(pDriver - base);
DevNames->wDeviceOffset = static_cast<WORD>(pDevice - base);
DevNames->wOutputOffset = static_cast<WORD>(pOutput - base);
_tcscpy(pDriver, driver.c_str());
_tcscpy(pDevice, device.c_str());
_tcscpy(pOutput, output.c_str());
}
示例6: PostProcessSummary
void XmlTreeView::PostProcessSummary(tstring& str)
{
// Replace empty strings.
if (str.empty())
{
str = TXT("(empty)");
return;
}
bool bWhitespaceOnly = true;
// Find if only whitespace characters.
for (tstring::const_iterator it = str.begin(); ((it != str.end()) && bWhitespaceOnly); ++it)
{
if (!tisspace(static_cast<utchar>(*it)))
bWhitespaceOnly = false;
}
// Replace "invisible" strings.
if (bWhitespaceOnly)
{
str = TXT("(whitespace)");
return;
}
// Trim string.
if (str.length() > App.m_nDefMaxItemLen)
{
str.erase(App.m_nDefMaxItemLen, str.length()-App.m_nDefMaxItemLen);
str += TXT("...");
}
}
示例7: OnSendCommand
void CFTPProtocolOutput::OnSendCommand(const tstring& strCommand)
{
if( strCommand.length()==0 )
return;
if( strCommand.length()>4 && strCommand.substr(5)==_T("PASS ") )
WriteLine(_T("< PASS **********\n"), RGB(0, 0, 255));
else
WriteLine(_T("> ") + CString(strCommand.c_str()) + _T("\n"), RGB(0, 0, 255));
}
示例8: clientDC
//
/// Sets the maximum horizontal extent for the list view window.
//
void
TListBoxView::SetExtent(const tstring& str)
{
if (str.length() == 0)
return;
TClientDC clientDC(*this);
TSize extent = clientDC.GetTextExtent(str, str.length());
extent.cx += 2; // room for focus rectangle
if (extent.cx > MaxWidth)
SetHorizontalExtent(MaxWidth = extent.cx);
}
示例9: FormatChatLine
void ChatCtrl::FormatChatLine(const tstring& sMyNick, tstring& sText, CHARFORMAT2& cf, bool isMyMessage, const tstring& sAuthor, LONG lSelBegin, bool bUseEmo) {
// Set text format
tstring sMsgLower(sText.length(), NULL);
std::transform(sText.begin(), sText.end(), sMsgLower.begin(), _totlower);
LONG lSelEnd = lSelBegin + sText.size();
SetSel(lSelBegin, lSelEnd);
SetSelectionCharFormat(isMyMessage ? WinUtil::m_ChatTextMyOwn : cf);
// highlight all occurences of my nick
long lMyNickStart = -1, lMyNickEnd = -1;
size_t lSearchFrom = 0;
tstring sNick(sMyNick.length(), NULL);
std::transform(sMyNick.begin(), sMyNick.end(), sNick.begin(), _totlower);
bool found = false;
while((lMyNickStart = sMsgLower.find(sNick, lSearchFrom)) != tstring::npos) {
lMyNickEnd = lMyNickStart + (long)sNick.size();
SetSel(lSelBegin + lMyNickStart, lSelBegin + lMyNickEnd);
SetSelectionCharFormat(WinUtil::m_TextStyleMyNick);
lSearchFrom = lMyNickEnd;
found = true;
}
if(found) {
if( !SETTING(CHATNAMEFILE).empty() && !BOOLSETTING(SOUNDS_DISABLED) &&
!sAuthor.empty() && (stricmp(sAuthor.c_str(), sNick) != 0)) {
::PlaySound(Text::toT(SETTING(CHATNAMEFILE)).c_str(), NULL, SND_FILENAME | SND_ASYNC);
}
}
// highlight all occurences of favourite users' nicks
FavoriteManager::FavoriteMap ul = FavoriteManager::getInstance()->getFavoriteUsers();
for(FavoriteManager::FavoriteMap::const_iterator i = ul.begin(); i != ul.end(); ++i) {
const FavoriteUser& pUser = i->second;
lSearchFrom = 0;
sNick = Text::toT(pUser.getNick());
std::transform(sNick.begin(), sNick.end(), sNick.begin(), _totlower);
while((lMyNickStart = sMsgLower.find(sNick, lSearchFrom)) != tstring::npos) {
lMyNickEnd = lMyNickStart + (long)sNick.size();
SetSel(lSelBegin + lMyNickStart, lSelBegin + lMyNickEnd);
SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
lSearchFrom = lMyNickEnd;
}
}
// Links and smilies
FormatEmoticonsAndLinks(sText, sMsgLower, lSelBegin, bUseEmo);
}
示例10: Execute
bool OdbcCommand::Execute(const tstring & szSQL)
{
if (!Open())
return false;
#ifdef USE_SQL_TRACE
TRACE((szSQL + _T("\n")).c_str());
#endif
if (!BindParameters())
return false;
SQLRETURN result = SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length());
if (!(result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO || result == SQL_NO_DATA))
{
if (m_odbcConnection != nullptr)
m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement."));
else
m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);
Close();
return false;
}
if (!MoveNext())
MoveNextSet();
return true;
}
示例11: Execute
bool OdbcCommand::Execute(const tstring & szSQL)
{
if (!Open())
return false;
#ifdef _DEBUG
OutputDebugString((szSQL + _T("\n")).c_str());
#endif
if (!BindParameters())
return false;
if (!SQL_SUCCEEDED(SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length())))
{
if (m_odbcConnection != NULL)
m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement."));
else
m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);
Close();
return false;
}
if (!MoveNext())
MoveNextSet();
return true;
}
示例12: RegisterMenu
bool CRegisterMenu::RegisterMenu(const tstring& strSubKey, const tstring& strValue)
{
HKEY hKey;
DWORD strValueSize = strValue.empty() ? 0 : (strValue.length() + 1) * sizeof(TCHAR);
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, strSubKey.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS )
{
if (!strValue.empty())
RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)strValue.c_str(), strValueSize);
RegCloseKey(hKey);
}
else
{
DWORD disp = REG_CREATED_NEW_KEY;
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, strSubKey.c_str(),
NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey, &disp) == ERROR_SUCCESS )
{
if (!strValue.empty())
RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)strValue.c_str(), strValueSize);
RegCloseKey(hKey);
}
}
return true;
}
示例13:
CTokenizer::CTokenizer(const tstring& p_Str, const tstring& p_Delimiters)
{
const tstring::size_type len = p_Str.length();
tstring::size_type i = 0;
while(i < len)
{
// eat leading whitespace
i = p_Str.find_first_not_of(p_Delimiters, i);
if(i == tstring::npos)
return; // nothing left but white space
// find the end of the token
tstring::size_type j = p_Str.find_first_of(p_Delimiters, i);
// push token
if(j == tstring::npos)
{
m_Tokens.push_back(p_Str.substr(i));
return;
} else
m_Tokens.push_back(p_Str.substr(i, j - i));
// set up for next loop
i = j + 1;
}
}
示例14: OpenEnv
HRESULT WINAPI GameEnv::OpenEnv(const tstring whichPath)
{
if (NULL != pInstance) //检查是否已经初始化
{
mainEnv = pInstance;
return E_HANDLE;
}
if (_T('\\') == whichPath[whichPath.length() - 1]) //检查结尾反斜杠符
{
ErrorHandler(ERROR_RES_Unknown, _T(__FUNCTION__));
return E_FAIL;
}
if (!IsFolderExist(whichPath)) //检查路径是否存在
{
ErrorHandler(ERROR_RES_MissingPath, _T(__FUNCTION__));
return E_FAIL;
}
PGameRes pRes = OpenResFiles(whichPath);
if (NULL != pRes) //检查资源文件完整性
{
pInstance = new GameEnv(pRes);
mainEnv = pInstance;
return S_OK;
}
return E_FAIL;
}
示例15: inputSlotTime
uint64_t UserInfoSimple::inputSlotTime()
{
static tstring deftext = _T("00:30");
LineDlg dlg;
dlg.description = TSTRING(EXTRA_SLOT_TIME_FORMAT);
dlg.title = TSTRING(EXTRA_SLOT_TIMEOUT);
dlg.line = deftext;
if (dlg.DoModal() == IDOK)
{
deftext = dlg.line;
unsigned int n = 0;
for (size_t i = 0; i < deftext.length(); i++) // TODO: cleanup.
{
if (deftext[i] == L':') n++;
}
unsigned int d, h, m;
switch (n)
{
case 1:
if (swscanf(deftext.c_str(), L"%u:%u", &h, &m) == 2)
return (h * 3600 + m * 60);
break;
case 2:
if (swscanf(deftext.c_str(), L"%u:%u:%u", &d, &h, &m) == 3)
return (d * 3600 * 24 + h * 3600 + m * 60);
break;
}
::MessageBox(GetForegroundWindow(), CTSTRING(INVALID_TIME_FORMAT), CTSTRING(ERRORS), MB_OK | MB_ICONERROR);
}
return 0;
}