本文整理汇总了C++中nsACString::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::SetLength方法的具体用法?C++ nsACString::SetLength怎么用?C++ nsACString::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::SetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAddress
/* readonly attribute AUTF8String address; */
NS_IMETHODIMP nsNetAddr::GetAddress(nsACString & aAddress)
{
switch(mAddr.raw.family) {
/* PR_NetAddrToString can handle INET and INET6, but not LOCAL. */
case AF_INET:
aAddress.SetCapacity(kIPv4CStrBufSize);
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv4CStrBufSize);
aAddress.SetLength(strlen(aAddress.BeginReading()));
break;
case AF_INET6:
aAddress.SetCapacity(kIPv6CStrBufSize);
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv6CStrBufSize);
aAddress.SetLength(strlen(aAddress.BeginReading()));
break;
#if defined(XP_UNIX) || defined(XP_OS2)
case AF_LOCAL:
aAddress.Assign(mAddr.local.path);
break;
#endif
// PR_AF_LOCAL falls through to default when not XP_UNIX || XP_OS2
default:
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
示例2: converter
bool
AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest,
const mozilla::fallible_t& )
{
nsAString::const_iterator source_start, source_end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
uint32_t count = calculator.Size();
if (count)
{
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
return false;
}
// All ready? Time to convert
ConvertUTF16toUTF8 converter(aDest.BeginWriting() + old_dest_length);
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), converter);
NS_ASSERTION(converter.Size() == count,
"Unexpected disparity between CalculateUTF8Size and "
"ConvertUTF16toUTF8");
}
return true;
}
示例3: while
void
nsUrlClassifierUtils::CleanupHostname(const nsACString & hostname,
nsACString & _retval)
{
_retval.Truncate();
const char* curChar = hostname.BeginReading();
const char* end = hostname.EndReading();
char lastChar = '\0';
while (curChar != end) {
unsigned char c = static_cast<unsigned char>(*curChar);
if (c == '.' && (lastChar == '\0' || lastChar == '.')) {
// skip
} else {
_retval.Append(*curChar);
}
lastChar = c;
++curChar;
}
// cut off trailing dots
while (_retval.Length() > 0 && _retval[_retval.Length() - 1] == '.') {
_retval.SetLength(_retval.Length() - 1);
}
}
示例4: SplitLastSquareBracket
/** Takes an ASCII string like "foo[i]", turns it into "foo" and returns "[i]" in bracketPart
*
* \param string input/output: the string to split, becomes the string without the bracket part
* \param bracketPart output: gets the bracket part.
*
* Notice that if there are multiple brackets like "foo[i].bar[j]", only the last bracket is split.
*/
static bool SplitLastSquareBracket(nsACString& string, nsCString& bracketPart)
{
MOZ_ASSERT(bracketPart.IsEmpty(), "SplitLastSquareBracket must be called with empty bracketPart string");
if (string.IsEmpty())
return false;
char *string_start = string.BeginWriting();
char *s = string_start + string.Length() - 1;
if (*s != ']')
return false;
while (*s != '[' && s != string_start)
s--;
if (*s != '[')
return false;
bracketPart.Assign(s);
*s = 0;
string.EndWriting();
string.SetLength(s - string_start);
return true;
}
示例5: RegQueryValueExW
NS_IMETHODIMP
nsWindowsRegKey::ReadBinaryValue(const nsAString& aName, nsACString& aResult)
{
if (NS_WARN_IF(!mKey)) {
return NS_ERROR_NOT_INITIALIZED;
}
DWORD size;
LONG rv = RegQueryValueExW(mKey, PromiseFlatString(aName).get(), 0,
nullptr, nullptr, &size);
if (rv != ERROR_SUCCESS) {
return NS_ERROR_FAILURE;
}
if (!size) {
aResult.Truncate();
return NS_OK;
}
if (!aResult.SetLength(size, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsACString::iterator begin;
aResult.BeginWriting(begin);
rv = RegQueryValueExW(mKey, PromiseFlatString(aName).get(), 0, nullptr,
(LPBYTE)begin.get(), &size);
return (rv == ERROR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
}
示例6:
static bool
ReadSuffixAndSpec(JSStructuredCloneReader* aReader,
PrincipalOriginAttributes& aAttrs,
nsACString& aSpec)
{
uint32_t suffixLength, specLength;
if (!JS_ReadUint32Pair(aReader, &suffixLength, &specLength)) {
return false;
}
nsAutoCString suffix;
suffix.SetLength(suffixLength);
if (!JS_ReadBytes(aReader, suffix.BeginWriting(), suffixLength)) {
return false;
}
if (!aAttrs.PopulateFromSuffix(suffix)) {
return false;
}
aSpec.SetLength(specLength);
if (!JS_ReadBytes(aReader, aSpec.BeginWriting(), specLength)) {
return false;
}
return true;
}
示例7: ReadPrincipalInfo
static bool ReadPrincipalInfo(JSStructuredCloneReader* aReader,
OriginAttributes& aAttrs, nsACString& aSpec,
nsACString& aOriginNoSuffix) {
uint32_t suffixLength, specLength;
if (!JS_ReadUint32Pair(aReader, &suffixLength, &specLength)) {
return false;
}
nsAutoCString suffix;
if (!suffix.SetLength(suffixLength, fallible)) {
return false;
}
if (!JS_ReadBytes(aReader, suffix.BeginWriting(), suffixLength)) {
return false;
}
if (!aAttrs.PopulateFromSuffix(suffix)) {
return false;
}
if (!aSpec.SetLength(specLength, fallible)) {
return false;
}
if (!JS_ReadBytes(aReader, aSpec.BeginWriting(), specLength)) {
return false;
}
uint32_t originNoSuffixLength, dummy;
if (!JS_ReadUint32Pair(aReader, &originNoSuffixLength, &dummy)) {
return false;
}
MOZ_ASSERT(dummy == 0);
if (!aOriginNoSuffix.SetLength(originNoSuffixLength, fallible)) {
return false;
}
if (!JS_ReadBytes(aReader, aOriginNoSuffix.BeginWriting(),
originNoSuffixLength)) {
return false;
}
return true;
}
示例8:
NS_IMETHODIMP
HttpBaseChannel::GetRemoteAddress(nsACString& addr)
{
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(64);
PR_NetAddrToString(&mPeerAddr, addr.BeginWriting(), 64);
addr.SetLength(strlen(addr.BeginReading()));
return NS_OK;
}
示例9: NetAddrToString
NS_IMETHODIMP
HttpBaseChannel::GetLocalAddress(nsACString& addr)
{
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(kIPv6CStrBufSize);
NetAddrToString(&mSelfAddr, addr.BeginWriting(), kIPv6CStrBufSize);
addr.SetLength(strlen(addr.BeginReading()));
return NS_OK;
}
示例10:
NS_CStringGetMutableData(nsACString& aStr, uint32_t aDataLength, char** aData)
{
if (aDataLength != UINT32_MAX) {
aStr.SetLength(aDataLength);
if (aStr.Length() != aDataLength) {
*aData = nullptr;
return 0;
}
}
*aData = aStr.BeginWriting();
return aStr.Length();
}
示例11: ReverseString
void ReverseString(const nsACString& aSource, nsACString& aResult) {
nsACString::const_iterator sourceBegin, sourceEnd;
aSource.BeginReading(sourceBegin);
aSource.EndReading(sourceEnd);
aResult.SetLength(aSource.Length());
auto destEnd = aResult.EndWriting();
while (sourceBegin != sourceEnd) {
*(--destEnd) = *sourceBegin;
++sourceBegin;
}
}
示例12: while
/* from xpcom/io/nsStreamUtils.cpp
* (it's hidden in libxul, so we need a copy :( )
*/
nsresult
sbConsumeStream(nsIInputStream *stream, PRUint32 maxCount, nsACString &result)
{
nsresult rv = NS_OK;
result.Truncate();
while (maxCount) {
PRUint32 avail;
rv = stream->Available(&avail);
if (NS_FAILED(rv)) {
if (rv == NS_BASE_STREAM_CLOSED)
rv = NS_OK;
break;
}
if (avail == 0)
break;
if (avail > maxCount)
avail = maxCount;
// resize result buffer
PRUint32 length = result.Length();
result.SetLength(length + avail);
if (result.Length() != (length + avail))
return NS_ERROR_OUT_OF_MEMORY;
char *buf = result.BeginWriting() + length;
PRUint32 n;
rv = stream->Read(buf, avail, &n);
if (NS_FAILED(rv))
break;
if (n != avail)
result.SetLength(length + n);
if (n == 0)
break;
maxCount -= n;
}
return rv;
}
示例13:
NS_CStringGetMutableData(nsACString &aStr, PRUint32 aDataLength, char **aData)
{
if (aDataLength != PR_UINT32_MAX) {
aStr.SetLength(aDataLength);
if (aStr.Length() != aDataLength) {
*aData = nsnull;
return 0;
}
}
nsACString::iterator begin;
aStr.BeginWriting(begin);
*aData = begin.get();
return begin.size_forward();
}
示例14: RowCellColumnToCharPtr
nsresult nsMsgFolderCache::RowCellColumnToCharPtr(nsIMdbRow *hdrRow, mdb_token columnToken, nsACString& resultStr)
{
nsresult err = NS_OK;
nsIMdbCell *hdrCell;
if (hdrRow) // ### probably should be an error if hdrRow is NULL...
{
err = hdrRow->GetCell(GetEnv(), columnToken, &hdrCell);
if (NS_SUCCEEDED(err) && hdrCell)
{
struct mdbYarn yarn;
hdrCell->AliasYarn(GetEnv(), &yarn);
resultStr.Assign((const char *)yarn.mYarn_Buf, yarn.mYarn_Fill);
resultStr.SetLength(yarn.mYarn_Fill); // ensure the string is null terminated.
hdrCell->Release(); // always release ref
}
}
return err;
}
示例15: ReadHelper
NS_IMETHODIMP
nsScriptableInputStream::ReadBytes(uint32_t aCount, nsACString& aResult)
{
if (!mInputStream) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!aResult.SetLength(aCount, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
MOZ_ASSERT(aResult.Length() == aCount);
char* ptr = aResult.BeginWriting();
nsresult rv = ReadHelper(ptr, aCount);
if (NS_FAILED(rv)) {
aResult.Truncate();
}
return rv;
}