本文整理汇总了C++中nsACString::BeginWriting方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::BeginWriting方法的具体用法?C++ nsACString::BeginWriting怎么用?C++ nsACString::BeginWriting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::BeginWriting方法的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: 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;
}
示例4: 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;
}
示例5:
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;
}
示例6:
nsresult
NS_CopyUnicodeToNative(const nsAString &input, nsACString &output)
{
PRUint32 inputLen = input.Length();
nsAString::const_iterator iter;
input.BeginReading(iter);
const PRUnichar *buf = iter.get();
// determine length of result
PRUint32 resultLen = 0;
int n = ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, NULL, 0, NULL, NULL);
if (n > 0)
resultLen += n;
// allocate sufficient space
if (!EnsureStringLength(output, resultLen))
return NS_ERROR_OUT_OF_MEMORY;
if (resultLen > 0) {
nsACString::iterator out_iter;
output.BeginWriting(out_iter);
// default "defaultChar" is '?', which is an illegal character on windows
// file system. That will cause file uncreatable. Change it to '_'
const char defaultChar = '_';
char *result = out_iter.get();
::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, result, resultLen,
&defaultChar, NULL);
}
return NS_OK;
}
示例7: converter
void
AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest )
{
nsAString::const_iterator source_start, source_end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
PRUint32 count = calculator.Size();
if (count)
{
PRUint32 old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if(!SetLengthForWritingC(aDest, old_dest_length + count))
return;
// 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");
}
}
示例8: 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;
}
示例9:
PRUint32
ToLowerCase(nsACString& aStr)
{
char *begin, *end;
PRUint32 len = aStr.BeginWriting(&begin, &end);
for (; begin < end; ++begin) {
*begin = NS_ToLower(*begin);
}
return len;
}
示例10:
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;
}
示例11:
uint32_t
ToUpperCase(nsACString& aStr)
{
char *begin, *end;
uint32_t len = aStr.BeginWriting(&begin, &end);
for (; begin < end; ++begin) {
*begin = NS_ToUpper(*begin);
}
return len;
}
示例12: 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;
}
示例13:
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();
}
示例14:
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();
}
示例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;
}