当前位置: 首页>>代码示例>>C++>>正文


C++ nsAString::BeginWriting方法代码示例

本文整理汇总了C++中nsAString::BeginWriting方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::BeginWriting方法的具体用法?C++ nsAString::BeginWriting怎么用?C++ nsAString::BeginWriting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nsAString的用法示例。


在下文中一共展示了nsAString::BeginWriting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PromiseFlatString

static bool
GetStringValue(HKEY aBaseKey, const nsAString& aStrSubKey,
               const nsAString& aValueName, nsAString& aOutput)
{
  const nsString& flatSubKey = PromiseFlatString(aStrSubKey);
  const nsString& flatValueName = PromiseFlatString(aValueName);
  LPCWSTR valueName = aValueName.IsEmpty() ? nullptr : flatValueName.get();

  DWORD type = 0;
  DWORD numBytes = 0;
  LONG result = RegGetValue(aBaseKey, flatSubKey.get(), valueName,
                            RRF_RT_ANY, &type, nullptr, &numBytes);
  if (result != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
    return false;
  }

  int numChars = (numBytes + 1) / sizeof(wchar_t);
  aOutput.SetLength(numChars);

  DWORD acceptFlag = type == REG_SZ ? RRF_RT_REG_SZ : RRF_RT_REG_EXPAND_SZ;

  result = RegGetValue(aBaseKey, flatSubKey.get(), valueName, acceptFlag,
                       nullptr, aOutput.BeginWriting(), &numBytes);
  if (result == ERROR_SUCCESS) {
    // Truncate null terminator
    aOutput.SetLength(((numBytes + 1) / sizeof(wchar_t)) - 1);
  }

  return result == ERROR_SUCCESS;
}
开发者ID:yrliou,项目名称:gecko-dev,代码行数:30,代码来源:InterfaceRegistrationAnnotator.cpp

示例2:

nsresult
nsDOMFileReader::ConvertStream(const char *aFileData,
                               PRUint32 aDataLen,
                               const char *aCharset,
                               nsAString &aResult)
{
  nsresult rv;
  nsCOMPtr<nsICharsetConverterManager> charsetConverter = 
    do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
  rv = charsetConverter->GetUnicodeDecoder(aCharset, getter_AddRefs(unicodeDecoder));
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 destLength;
  rv = unicodeDecoder->GetMaxLength(aFileData, aDataLen, &destLength);
  NS_ENSURE_SUCCESS(rv, rv);

  aResult.SetLength(destLength);  //Make sure we have enough space for the conversion
  destLength = aResult.Length();

  PRInt32 srcLength = aDataLen;
  rv = unicodeDecoder->Convert(aFileData, &srcLength, aResult.BeginWriting(), &destLength);
  aResult.SetLength(destLength); //Trim down to the correct size

  return rv;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:28,代码来源:nsDOMFileReader.cpp

示例3: wwc

nsresult
NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
{
  uint32_t inputLen = aInput.Length();

  nsACString::const_iterator iter;
  aInput.BeginReading(iter);

  const char* buf = iter.get();

  // determine length of result
  uint32_t resultLen = 0;
  int n = ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, nullptr, 0);
  if (n > 0) {
    resultLen += n;
  }

  // allocate sufficient space
  if (!aOutput.SetLength(resultLen, fallible)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  if (resultLen > 0) {
    nsAString::iterator out_iter;
    aOutput.BeginWriting(out_iter);

    char16_t* result = out_iter.get();

    ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, wwc(result), resultLen);
  }
  return NS_OK;
}
开发者ID:ppbao,项目名称:mozilla-os2,代码行数:31,代码来源:nsNativeCharsetUtils.cpp

示例4: copy

static void
RemoveControlCharactersFrom(nsAString& aStr, TextRangeArray* aRanges)
{
  size_t firstControlCharOffset = FindFirstControlCharacter(aStr);
  if (firstControlCharOffset == (size_t)-1) {
    return;
  }

  nsAutoString copy(aStr);
  const char16_t* sourceBegin = copy.BeginReading();
  const char16_t* sourceEnd = copy.EndReading();

  char16_t* dest = aStr.BeginWriting();
  if (NS_WARN_IF(!dest)) {
    return;
  }

  char16_t* curDest = dest + firstControlCharOffset;
  size_t i = firstControlCharOffset;
  for (const char16_t* source = sourceBegin + firstControlCharOffset;
       source < sourceEnd; ++source) {
    if (*source == '\t' || *source == '\n' || !IsControlChar(*source)) {
      *curDest = *source;
      ++curDest;
      ++i;
    } else if (aRanges) {
      aRanges->RemoveCharacter(i);
    }
  }

  aStr.SetLength(curDest - dest);
}
开发者ID:artines1,项目名称:gecko-dev,代码行数:32,代码来源:TextComposition.cpp

示例5:

nsresult
nsDOMFileReader::ConvertStream(const char *aFileData,
                               uint32_t aDataLen,
                               const char *aCharset,
                               nsAString &aResult)
{
  nsresult rv;
  nsCOMPtr<nsICharsetConverterManager> charsetConverter = 
    do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
  rv = charsetConverter->GetUnicodeDecoder(aCharset, getter_AddRefs(unicodeDecoder));
  NS_ENSURE_SUCCESS(rv, rv);

  int32_t destLength;
  rv = unicodeDecoder->GetMaxLength(aFileData, aDataLen, &destLength);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!aResult.SetLength(destLength, fallible_t()))
    return NS_ERROR_OUT_OF_MEMORY;

  int32_t srcLength = aDataLen;
  rv = unicodeDecoder->Convert(aFileData, &srcLength, aResult.BeginWriting(), &destLength);
  aResult.SetLength(destLength); //Trim down to the correct size

  return rv;
}
开发者ID:KWierso,项目名称:releases-mozilla-central,代码行数:28,代码来源:nsDOMFileReader.cpp

示例6:

nsresult
NS_CopyNativeToUnicode(const nsACString &input, nsAString &output)
{
    PRUint32 inputLen = input.Length();

    nsACString::const_iterator iter;
    input.BeginReading(iter);

    const char *buf = iter.get();

    // determine length of result
    PRUint32 resultLen = 0;
    int n = ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, NULL, 0);
    if (n > 0)
        resultLen += n;

    // allocate sufficient space
    if (!EnsureStringLength(output, resultLen))
        return NS_ERROR_OUT_OF_MEMORY;
    if (resultLen > 0) {
        nsAString::iterator out_iter;
        output.BeginWriting(out_iter);

        PRUnichar *result = out_iter.get();

        ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, result, resultLen);
    }
    return NS_OK;
}
开发者ID:moussa1,项目名称:mozilla-central,代码行数:29,代码来源:nsNativeCharsetUtils.cpp

示例7: ReadCOMRegDefaultString

static bool ReadCOMRegDefaultString(const nsString& aRegPath,
                                    nsAString& aOutBuf) {
  aOutBuf.Truncate();

  nsAutoString fullyQualifiedRegPath;
  fullyQualifiedRegPath.AppendLiteral(u"SOFTWARE\\Classes\\");
  fullyQualifiedRegPath.Append(aRegPath);

  // Get the required size and type of the registry value.
  // We expect either REG_SZ or REG_EXPAND_SZ.
  DWORD type;
  DWORD bufLen = 0;
  LONG result = ::RegGetValue(HKEY_LOCAL_MACHINE, fullyQualifiedRegPath.get(),
                              nullptr, RRF_RT_ANY, &type, nullptr, &bufLen);
  if (result != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
    return false;
  }

  // Now obtain the value
  DWORD flags = type == REG_SZ ? RRF_RT_REG_SZ : RRF_RT_REG_EXPAND_SZ;

  aOutBuf.SetLength((bufLen + 1) / sizeof(char16_t));

  result =
      ::RegGetValue(HKEY_LOCAL_MACHINE, fullyQualifiedRegPath.get(), nullptr,
                    flags, nullptr, aOutBuf.BeginWriting(), &bufLen);
  if (result != ERROR_SUCCESS) {
    aOutBuf.Truncate();
    return false;
  }

  // Truncate terminator
  aOutBuf.Truncate((bufLen + 1) / sizeof(char16_t) - 1);
  return true;
}
开发者ID:djg,项目名称:gecko-dev,代码行数:35,代码来源:Compatibility.cpp

示例8: TX_ToLowerCase

void TX_ToLowerCase(nsAString& aString)
{
  nsAString::iterator fromBegin, fromEnd;
  ConvertToLowerCase converter;
  copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd),
              converter);
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:7,代码来源:txStringUtils.cpp

示例9: ToUpperCase

void
ToUpperCase(const nsAString& aSource,
            nsAString& aDest)
{
  const char16_t *in = aSource.BeginReading();
  uint32_t len = aSource.Length();

  aDest.SetLength(len);
  char16_t *out = aDest.BeginWriting();

  ToUpperCase(in, out, len);
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:12,代码来源:nsUnicharUtils.cpp

示例10: fromBegin

void
CopyUnicodeTo(const nsAString::const_iterator& aSrcStart,
              const nsAString::const_iterator& aSrcEnd,
              nsAString& aDest)
{
  aDest.SetLength(Distance(aSrcStart, aSrcEnd));

  nsAString::char_iterator dest = aDest.BeginWriting();
  nsAString::const_iterator fromBegin(aSrcStart);

  copy_string(fromBegin, aSrcEnd, dest);
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:12,代码来源:nsReadableUtils.cpp

示例11: RegQueryValueExW

/**
 * Provides a fallback for getting the path to APPDATA or LOCALAPPDATA by
 * querying the registry when the call to SHGetSpecialFolderLocation or
 * SHGetPathFromIDListW is unable to provide these paths (Bug 513958).
 */
static nsresult
GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
{
  HKEY key;
  NS_NAMED_LITERAL_STRING(keyName,
  "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
  DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName.get(), 0, KEY_READ,
                              &key);
  if (res != ERROR_SUCCESS) {
    _retval.SetLength(0);
    return NS_ERROR_NOT_AVAILABLE;
  }

  DWORD type, size;
  res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"),
                         nullptr, &type, nullptr, &size);
  // The call to RegQueryValueExW must succeed, the type must be REG_SZ, the
  // buffer size must not equal 0, and the buffer size be a multiple of 2.
  if (res != ERROR_SUCCESS || type != REG_SZ || size == 0 || size % 2 != 0) {
    ::RegCloseKey(key);
    _retval.SetLength(0);
    return NS_ERROR_NOT_AVAILABLE;
  }

  // |size| may or may not include room for the terminating null character
  DWORD resultLen = size / 2;

  _retval.SetLength(resultLen);
  nsAString::iterator begin;
  _retval.BeginWriting(begin);
  if (begin.size_forward() != resultLen) {
    ::RegCloseKey(key);
    _retval.SetLength(0);
    return NS_ERROR_NOT_AVAILABLE;
  }

  res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"),
                         nullptr, nullptr, (LPBYTE) begin.get(), &size);
  ::RegCloseKey(key);
  if (res != ERROR_SUCCESS) {
    _retval.SetLength(0);
    return NS_ERROR_NOT_AVAILABLE;
  }

  if (!_retval.CharAt(resultLen - 1)) {
    // It was already null terminated.
    _retval.Truncate(resultLen - 1);
  }

  return NS_OK;
}
开发者ID:ChaOSChriS,项目名称:gecko-dev,代码行数:56,代码来源:nsXREDirProvider.cpp

示例12: wwc

void
GUIDToString(REFGUID aGuid, nsAString& aOutString)
{
  // This buffer length is long enough to hold a GUID string that is formatted
  // to include curly braces and dashes.
  const int kBufLenWithNul = 39;
  aOutString.SetLength(kBufLenWithNul);
  int result = StringFromGUID2(aGuid, wwc(aOutString.BeginWriting()), kBufLenWithNul);
  MOZ_ASSERT(result);
  if (result) {
    // Truncate the terminator
    aOutString.SetLength(result - 1);
  }
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:14,代码来源:Utils.cpp

示例13:

NS_StringGetMutableData(nsAString& aStr, uint32_t aDataLength,
                        char16_t** aData)
{
  if (aDataLength != UINT32_MAX) {
    aStr.SetLength(aDataLength);
    if (aStr.Length() != aDataLength) {
      *aData = nullptr;
      return 0;
    }
  }

  *aData = aStr.BeginWriting();
  return aStr.Length();
}
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:14,代码来源:nsXPCOMStrings.cpp

示例14: fromBegin

void
AppendUnicodeTo( const nsAString::const_iterator& aSrcStart,
                 const nsAString::const_iterator& aSrcEnd,
                 nsAString& aDest )
  {
    nsAString::iterator writer;
    PRUint32 oldLength = aDest.Length();
    if(!SetLengthForWriting(aDest, oldLength + Distance(aSrcStart, aSrcEnd)))
        return;

    aDest.BeginWriting(writer).advance(oldLength);
    nsAString::const_iterator fromBegin(aSrcStart);
    
    copy_string(fromBegin, aSrcEnd, writer);
  }
开发者ID:lofter2011,项目名称:Icefox,代码行数:15,代码来源:nsReadableUtils.cpp

示例15:

NS_StringGetMutableData(nsAString &aStr, PRUint32 aDataLength,
                        PRUnichar **aData)
{
  if (aDataLength != PR_UINT32_MAX) {
    aStr.SetLength(aDataLength);
    if (aStr.Length() != aDataLength) {
      *aData = nsnull;
      return 0;
    }
  }

  nsAString::iterator begin;
  aStr.BeginWriting(begin);
  *aData = begin.get();
  return begin.size_forward();
}
开发者ID:Anachid,项目名称:mozilla-central,代码行数:16,代码来源:nsXPCOMStrings.cpp


注:本文中的nsAString::BeginWriting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。