本文整理汇总了C++中Checked::safeGet方法的典型用法代码示例。如果您正苦于以下问题:C++ Checked::safeGet方法的具体用法?C++ Checked::safeGet怎么用?C++ Checked::safeGet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Checked
的用法示例。
在下文中一共展示了Checked::safeGet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: join
JSValue JSStringJoiner::join(ExecState* exec)
{
if (!m_isValid)
return throwOutOfMemoryError(exec);
if (!m_strings.size())
return jsEmptyString(exec);
Checked<size_t, RecordOverflow> separatorLength = m_separator.length();
// FIXME: add special cases of joinStrings() for (separatorLength == 0) and (separatorLength == 1).
ASSERT(m_strings.size() > 0);
Checked<size_t, RecordOverflow> totalSeparactorsLength = separatorLength * (m_strings.size() - 1);
Checked<size_t, RecordOverflow> outputStringSize = totalSeparactorsLength + m_accumulatedStringsLength;
size_t finalSize;
if (outputStringSize.safeGet(finalSize) == CheckedState::DidOverflow)
return throwOutOfMemoryError(exec);
if (!outputStringSize)
return jsEmptyString(exec);
RefPtr<StringImpl> outputStringImpl;
if (m_is8Bits)
outputStringImpl = joinStrings<LChar>(m_strings, m_separator, finalSize);
else
outputStringImpl = joinStrings<UChar>(m_strings, m_separator, finalSize);
if (!outputStringImpl)
return throwOutOfMemoryError(exec);
return JSString::create(exec->vm(), outputStringImpl.release());
}