本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例8: TX_ToLowerCase
void TX_ToLowerCase(nsAString& aString)
{
nsAString::iterator fromBegin, fromEnd;
ConvertToLowerCase converter;
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd),
converter);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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();
}