本文整理汇总了C++中nsCString::SetCapacity方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCString::SetCapacity方法的具体用法?C++ nsCString::SetCapacity怎么用?C++ nsCString::SetCapacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCString
的用法示例。
在下文中一共展示了nsCString::SetCapacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static
nsresult
Base64urlEncode(const PRUint8* aBytes,
PRUint32 aNumBytes,
nsCString& _result)
{
// SetLength does not set aside space for NULL termination. PL_Base64Encode
// will not NULL terminate, however, nsCStrings must be NULL terminated. As a
// result, we set the capacity to be one greater than what we need, and the
// length to our desired length.
PRUint32 length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math.
NS_ENSURE_TRUE(_result.SetCapacity(length + 1), NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes,
_result.BeginWriting());
// base64url encoding is defined in RFC 4648. It replaces the last two
// alphabet characters of base64 encoding with '-' and '_' respectively.
_result.ReplaceChar('+', '-');
_result.ReplaceChar('/', '_');
return NS_OK;
}