本文整理汇总了C++中NPT_String::Reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_String::Reserve方法的具体用法?C++ NPT_String::Reserve怎么用?C++ NPT_String::Reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_String
的用法示例。
在下文中一共展示了NPT_String::Reserve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToRequestString
/*----------------------------------------------------------------------
| NPT_Url::ToStringWithDefaultPort
+---------------------------------------------------------------------*/
NPT_String
NPT_Url::ToStringWithDefaultPort(NPT_UInt16 default_port, bool with_fragment) const
{
NPT_String result;
NPT_String request = ToRequestString(with_fragment);
NPT_Size length = m_Scheme.GetLength()+3+m_Host.GetLength()+6+request.GetLength();
result.Reserve(length);
result += m_Scheme;
result += "://";
result += m_Host;
if (m_Port != default_port) {
NPT_String port = NPT_String::FromInteger(m_Port);
result += ":";
result += port;
}
result += request;
return result;
}
示例2: while
/*----------------------------------------------------------------------
| NPT_Uri::PercentEncode
+---------------------------------------------------------------------*/
NPT_String
NPT_Uri::PercentEncode(const char* str, const char* chars, bool encode_percents)
{
NPT_String encoded;
// check args
if (str == NULL) return encoded;
// reserve at least the size of the current uri
encoded.Reserve(NPT_StringLength(str));
// process each character
char escaped[3];
escaped[0] = '%';
while (unsigned char c = *str++) {
bool encode = false;
if (encode_percents && c == '%') {
encode = true;
} else if (c < ' ' || c > '~') {
encode = true;
} else {
const char* match = chars;
while (*match) {
if (c == *match) {
encode = true;
break;
}
++match;
}
}
if (encode) {
// encode
NPT_ByteToHex(c, &escaped[1], true);
encoded.Append(escaped, 3);
} else {
// no encoding required
encoded += c;
}
}
return encoded;
}
示例3:
/*----------------------------------------------------------------------
| NPT_BufferedInputStream::ReadLine
+---------------------------------------------------------------------*/
NPT_Result
NPT_BufferedInputStream::ReadLine(NPT_String& line,
NPT_Size max_chars,
bool break_on_cr)
{
// clear the line
line.SetLength(0);
// reserve space for the chars
line.Reserve(max_chars);
// read the line
NPT_Size chars_read = 0;
NPT_CHECK_NOLOGTIMEOUT(ReadLine(line.UseChars(), max_chars, &chars_read, break_on_cr));
// adjust the length of the string object
line.SetLength(chars_read);
return NPT_SUCCESS;
}
示例4:
/*----------------------------------------------------------------------
| NPT_Url::ToRequestString
+---------------------------------------------------------------------*/
NPT_String
NPT_Url::ToRequestString(bool with_fragment) const
{
NPT_String result;
NPT_Size length = m_Path.GetLength()+1;
if (m_HasQuery) length += 1+m_Query.GetLength();
if (with_fragment) length += 1+m_Fragment.GetLength();
result.Reserve(length);
if (m_Path.IsEmpty()) {
result += "/";
} else {
result += m_Path;
}
if (m_HasQuery) {
result += "?";
result += m_Query;
}
if (with_fragment && m_HasFragment) {
result += "#";
result += m_Fragment;
}
return result;
}
示例5:
/*----------------------------------------------------------------------
| PLT_MediaContainer::ToDidl
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaContainer::ToDidl(NPT_UInt32 mask, NPT_String& didl)
{
NPT_String tmp;
// Allocate enough space for a big string we're going to concatenate in
tmp.Reserve(2048);
// container id property
tmp = "<container id=\"";
PLT_Didl::AppendXmlEscape(tmp, m_ObjectID);
// parent id property
tmp += "\" parentID=\"";
PLT_Didl::AppendXmlEscape(tmp, m_ParentID);
// ref id
if (!m_ReferenceID.IsEmpty()) {
tmp += "\" refID=\"";
PLT_Didl::AppendXmlEscape(tmp, m_ReferenceID);
}
// restricted property
tmp += "\" restricted=\"";
tmp += m_Restricted?"1\"":"0\"";
// searchable property
if (mask & PLT_FILTER_MASK_SEARCHABLE) {
tmp += " searchable=\"";
tmp += m_Searchable?"1\"":"0\"";
}
// childcount property
if (mask & PLT_FILTER_MASK_CHILDCOUNT && m_ChildrenCount != -1) {
tmp += " childCount=\"";
tmp += NPT_String::FromInteger(m_ChildrenCount);
tmp += "\"";
}
tmp += ">";
if (mask & PLT_FILTER_MASK_SEARCHCLASS && m_SearchClasses.GetItemCount()) {
NPT_List<PLT_SearchClass>::Iterator search_class = m_SearchClasses.GetFirstItem();
while (search_class) {
tmp += "<upnp:searchClass includeDerived=\"";
tmp += (*search_class).include_derived?"1\"":"0\"";
// frienly name is any
if (!(*search_class).friendly_name.IsEmpty()) {
tmp += " name=\"" + (*search_class).friendly_name + "\"";
}
tmp += ">";
tmp += (*search_class).type;
tmp += "</upnp:searchClass>";
++search_class;
}
}
NPT_CHECK_SEVERE(PLT_MediaObject::ToDidl(mask, tmp));
/* close tag */
tmp += "</container>";
didl += tmp;
return NPT_SUCCESS;
}