本文整理汇总了C++中NPT_String::Assign方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_String::Assign方法的具体用法?C++ NPT_String::Assign怎么用?C++ NPT_String::Assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_String
的用法示例。
在下文中一共展示了NPT_String::Assign方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
/*----------------------------------------------------------------------
| NPT_File::Load
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::Load(const char* path, NPT_String& data, NPT_FileInterface::OpenMode mode)
{
NPT_DataBuffer buffer;
// reset ouput params
data = "";
// create and open the file
NPT_File file(path);
NPT_Result result = file.Open(mode);
if (NPT_FAILED(result)) return result;
// load the file
result = file.Load(buffer);
if (NPT_SUCCEEDED(result) && buffer.GetDataSize() > 0) {
data.Assign((const char*)buffer.GetData(), buffer.GetDataSize());
data.SetLength(buffer.GetDataSize());
}
// close the file
file.Close();
return result;
}
示例2: while
/*----------------------------------------------------------------------
| NPT_LogManager::ParseConfig
+---------------------------------------------------------------------*/
NPT_Result
NPT_LogManager::ParseConfig(const char* config,
NPT_Size config_size)
{
const char* cursor = config;
const char* line = config;
const char* separator = NULL;
NPT_String key;
NPT_String value;
/* parse all entries */
while (cursor <= config+config_size) {
/* separators are newlines, ';' or end of buffer */
if ( cursor == config+config_size ||
*cursor == '\n' ||
*cursor == '\r' ||
*cursor == ';') {
/* newline or end of buffer */
if (separator && line[0] != '#') {
/* we have a property */
key.Assign(line, (NPT_Size)(separator-line));
value.Assign(line+(separator+1-line), (NPT_Size)(cursor-(separator+1)));
key.Trim(" \t");
value.Trim(" \t");
SetConfigValue((const char*)key, (const char*)value);
}
line = cursor+1;
separator = NULL;
} else if (*cursor == '=' && separator == NULL) {
separator = cursor;
}
cursor++;
}
return NPT_SUCCESS;
}
示例3: CHECK
/*----------------------------------------------------------------------
| TestSerializer
+---------------------------------------------------------------------*/
static void
TestSerializer()
{
NPT_XmlWriter writer;
NPT_MemoryStream output;
NPT_String check;
NPT_LargeSize size;
//
// test without namespaces
//
// simple element with no prefix and no namespace
NPT_XmlElementNode* top = new NPT_XmlElementNode("top");
writer.Serialize(*top, output);
output.GetSize(size);
check.Assign((const char*)output.GetData(), (NPT_Size)size);
CHECK(check == "<top/>");
// with one attribute
output.SetSize(0);
top->SetAttribute("attr1", "b&w");
writer.Serialize(*top, output);
output.GetSize(size);
check.Assign((const char*)output.GetData(), (NPT_Size)size);
CHECK(check == "<top attr1=\"b&w\"/>");
// add one child
output.SetSize(0);
delete top;
top = new NPT_XmlElementNode("top");
NPT_XmlElementNode* child1 = new NPT_XmlElementNode("child1");
top->AddChild(child1);
writer.Serialize(*top, output);
output.GetSize(size);
check.Assign((const char*)output.GetData(), (NPT_Size)size);
CHECK(check == "<top><child1/></top>");
//
// test with namespaces
//
// test default namespaces
output.SetSize(0);
delete top;
top = new NPT_XmlElementNode("top");
top->SetNamespaceUri("", "http://namespace.com");
writer.Serialize(*top, output);
output.GetSize(size);
check.Assign((const char*)output.GetData(), (NPT_Size)size);
CHECK(check == "<top xmlns=\"http://namespace.com\"/>");
// test attribute prefixes
output.SetSize(0);
delete top;
top = new NPT_XmlElementNode("top");
top->SetAttribute(NULL, "foo", "6");
top->SetAttribute("ns1", "foo", "3");
top->SetAttribute("ns2", "foo", "4");
top->SetAttribute("ns1", "foo", "5");
writer.Serialize(*top, output);
output.GetSize(size);
check.Assign((const char*)output.GetData(), (NPT_Size)size);
CHECK(check == "<top foo=\"6\" ns1:foo=\"5\" ns2:foo=\"4\"/>");
delete top;
}