本文整理汇总了C++中StringData::copyTo方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::copyTo方法的具体用法?C++ StringData::copyTo怎么用?C++ StringData::copyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::copyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
void FieldRef::parse(const StringData& dottedField) {
if (dottedField.size() == 0) {
return;
}
if (_size != 0) {
clear();
}
// We guarantee that accesses through getPart() will be valid while 'this' is. So we
// take a copy. We're going to be "chopping" up the copy into c-strings.
_fieldBase.reset(new char[dottedField.size()+1]);
dottedField.copyTo( _fieldBase.get(), true );
// Separate the field parts using '.' as a delimiter.
char* beg = _fieldBase.get();
char* cur = beg;
char* end = beg + dottedField.size();
while (true) {
if (cur != end && *cur != '.') {
cur++;
continue;
}
appendPart(StringData(beg, cur - beg));
if (cur != end) {
*cur = '\0';
beg = ++cur;
continue;
}
break;
}
}
示例2: sizeof
intrusive_ptr<const RCString> RCString::create(StringData s) {
const size_t sizeWithNUL = s.size() + 1;
const size_t bytesNeeded = sizeof(RCString) + sizeWithNUL;
uassert(16493, str::stream() << "Tried to create string longer than "
<< (BSONObjMaxUserSize/1024/1024) << "MB",
bytesNeeded < static_cast<size_t>(BSONObjMaxUserSize));
intrusive_ptr<RCString> ptr = new (bytesNeeded) RCString(); // uses custom operator new
ptr->_size = s.size();
char* stringStart = reinterpret_cast<char*>(ptr.get()) + sizeof(RCString);
s.copyTo( stringStart, true );
return ptr;
}