本文整理汇总了C++中TBStr::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ TBStr::Set方法的具体用法?C++ TBStr::Set怎么用?C++ TBStr::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBStr
的用法示例。
在下文中一共展示了TBStr::Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetText
bool TBClipboard::GetText(TBStr &text)
{
if (GLFWwindow *window = glfwGetCurrentContext())
{
if (const char *str = glfwGetClipboardString(window))
return text.Set(str);
}
return false;
}
示例2: SetFromStringAuto
void TBValue::SetFromStringAuto(const char *str, SET set)
{
if (!str)
SetNull();
else if (is_number_only(str))
{
if (is_number_float(str))
SetFloat((float)atof(str));
else
SetInt(atoi(str));
}
else if (is_start_of_number(str) && contains_non_trailing_space(str))
{
// If the number has nontrailing space, we'll assume a list of numbers (example: "10 -4 3.5")
SetNull();
if (TBValueArray *arr = new TBValueArray)
{
TBStr tmpstr;
char *s3;
if (tmpstr.Set(str))
{
char * pch = strtok_r(tmpstr, ", ", &s3);
while (pch)
{
if (TBValue *new_val = arr->AddValue())
new_val->SetFromStringAuto(pch, SET_NEW_COPY);
pch = strtok_r(NULL, ", ", &s3);
}
}
SetArray(arr, SET_TAKE_OWNERSHIP);
}
}
else if (*str == '[')
{
SetNull();
if (TBValueArray *arr = new TBValueArray)
{
assert(!"not implemented! Split out the tokenizer code above!");
SetArray(arr, SET_TAKE_OWNERSHIP);
}
}
else
{
SetString(str, set);
return;
}
// We didn't set as string, so we might need to deal with the passed in string data.
if (set == SET_TAKE_OWNERSHIP)
{
// Delete the passed in data
TBValue tmp;
tmp.SetString(str, SET_TAKE_OWNERSHIP);
}
}
示例3: GetText
bool TBClipboard::GetText(TBStr &text)
{
bool success = false;
if (HasText() && OpenClipboard(NULL))
{
if (HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT))
{
wchar_t *pchData = (wchar_t*) GlobalLock(hClipboardData);
int len = WideCharToMultiByte(CP_UTF8, 0, pchData, -1, NULL, 0, NULL, NULL);
if (char *utf8 = new char[len])
{
WideCharToMultiByte(CP_UTF8, 0, pchData, -1, utf8, len, NULL, NULL);
success = text.Set(utf8);
delete [] utf8;
}
GlobalUnlock(hClipboardData);
}
CloseClipboard();
}
return success;
}