本文整理汇总了C++中PromiseFlatString函数的典型用法代码示例。如果您正苦于以下问题:C++ PromiseFlatString函数的具体用法?C++ PromiseFlatString怎么用?C++ PromiseFlatString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PromiseFlatString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __android_log_print
void
MessageManagerGlobal::Dump(const nsAString& aStr)
{
if (!DOMPrefs::DumpEnabled()) {
return;
}
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", NS_ConvertUTF16toUTF8(aStr).get());
#endif
#ifdef XP_WIN
if (IsDebuggerPresent()) {
OutputDebugStringW(PromiseFlatString(aStr).get());
}
#endif
fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout);
fflush(stdout);
}
示例2: NS_ENSURE_TRUE
NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsAString& stringIn,
uint8_t** key, uint32_t* outLen)
{
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_ARG_POINTER(key);
NS_ENSURE_ARG_POINTER(outLen);
nsresult res = EnsureCollator(strength);
NS_ENSURE_SUCCESS(res, res);
uint32_t stringInLen = stringIn.Length();
uint32_t maxKeyLen = (1 + stringInLen) * kCollationValueSizeFactor * sizeof(UCCollationValue);
if (maxKeyLen > mBufferLen) {
uint32_t newBufferLen = mBufferLen;
do {
newBufferLen *= 2;
} while (newBufferLen < maxKeyLen);
void *newBuffer = PR_Malloc(newBufferLen);
if (!newBuffer)
return NS_ERROR_OUT_OF_MEMORY;
PR_FREEIF(mBuffer);
mBuffer = newBuffer;
mBufferLen = newBufferLen;
}
ItemCount actual;
OSStatus err = ::UCGetCollationKey(mCollator, (const UniChar*) PromiseFlatString(stringIn).get(),
(UniCharCount) stringInLen,
(ItemCount) (mBufferLen / sizeof(UCCollationValue)),
&actual, (UCCollationValue *)mBuffer);
NS_ENSURE_TRUE((err == noErr), NS_ERROR_FAILURE);
uint32_t keyLength = actual * sizeof(UCCollationValue);
void *newKey = PR_Malloc(keyLength);
if (!newKey)
return NS_ERROR_OUT_OF_MEMORY;
memcpy(newKey, mBuffer, keyLength);
*key = (uint8_t *)newKey;
*outLen = keyLength;
return NS_OK;
}
示例3: NS_ASSERTION
PRInt32
nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName)
{
NS_ASSERTION(mNameArray, "not inited");
NS_ASSERTION(mNameTable.ops, "not inited");
const nsAFlatString& str = PromiseFlatString(aName);
NameTableKey key(&str);
NameTableEntry *entry =
static_cast<NameTableEntry*>
(PL_DHashTableOperate(&mNameTable, &key,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_FREE(entry))
return nsStaticCaseInsensitiveNameTable::NOT_FOUND;
return entry->mIndex;
}
示例4: CheckTlbPath
static void
CheckTlbPath(JSONWriter& aJson, const nsAString& aTypelibPath)
{
const nsString& flatPath = PromiseFlatString(aTypelibPath);
DWORD bufCharLen = ExpandEnvironmentStrings(flatPath.get(), nullptr, 0);
auto buf = MakeUnique<WCHAR[]>(bufCharLen);
if (!ExpandEnvironmentStrings(flatPath.get(), buf.get(), bufCharLen)) {
return;
}
// See whether this tlb can actually be loaded
RefPtr<ITypeLib> typeLib;
HRESULT hr = LoadTypeLibEx(buf.get(), REGKIND_NONE, getter_AddRefs(typeLib));
nsPrintfCString loadResult("0x%08X", hr);
aJson.StringProperty("LoadResult", loadResult.get());
}
示例5: ParseInteger
static bool ParseInteger(nsDependentSubstring& aString,
int32_t& aResult)
{
uint32_t index = FirstNonDigit(aString, 0);
if (index == 0) {
return false;
}
nsDependentSubstring n(aString, 0, index);
nsresult ec;
int32_t s = PromiseFlatString(n).ToInteger(&ec);
if (NS_FAILED(ec)) {
return false;
}
aString.Rebind(aString, index);
aResult = s;
return true;
}
示例6: serv
NS_IMETHODIMP
mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary)
{
if(!mSpellCheckingEngine)
return NS_ERROR_NULL_POINTER;
nsresult res;
res = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get());
if(NS_FAILED(res)){
NS_WARNING("Dictionary load failed");
return res;
}
nsXPIDLString language;
nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &res));
if(serv && NS_SUCCEEDED(res)){
res = serv->GetUtil(language.get(),getter_AddRefs(mConverter));
}
return res;
}
示例7: RegOpenKeyExW
NS_IMETHODIMP
nsWindowsRegKey::HasChild(const nsAString& aName, bool* aResult)
{
if (NS_WARN_IF(!mKey)) {
return NS_ERROR_NOT_INITIALIZED;
}
// Check for the existence of a child key by opening the key with minimal
// rights. Perhaps there is a more efficient way to do this?
HKEY key;
LONG rv = RegOpenKeyExW(mKey, PromiseFlatString(aName).get(), 0,
STANDARD_RIGHTS_READ, &key);
if ((*aResult = (rv == ERROR_SUCCESS && key))) {
RegCloseKey(key);
}
return NS_OK;
}
示例8: NS_ENSURE_TRUE
NS_IMETHODIMP
nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
{
NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED);
DWORD type, size;
const nsString &flatName = PromiseFlatString(name);
LONG rv = RegQueryValueExW(mKey, flatName.get(), 0, &type, NULL, &size);
if (rv != ERROR_SUCCESS)
return NS_ERROR_FAILURE;
// This must be a string type in order to fetch the value as a string.
// We're being a bit forgiving here by allowing types other than REG_SZ.
NS_ENSURE_STATE(type == REG_SZ ||
type == REG_EXPAND_SZ ||
type == REG_MULTI_SZ);
// The buffer size must be a multiple of 2.
NS_ENSURE_STATE(size % 2 == 0);
if (size == 0) {
result.Truncate();
return NS_OK;
}
// |size| includes room for the terminating null character
DWORD resultLen = size / 2 - 1;
result.SetLength(resultLen);
nsAString::iterator begin;
result.BeginWriting(begin);
if (begin.size_forward() != resultLen)
return NS_ERROR_OUT_OF_MEMORY;
rv = RegQueryValueExW(mKey, flatName.get(), 0, NULL, (LPBYTE) begin.get(),
&size);
return (rv == ERROR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
}
示例9: GetFileSystemCharset
//-------------------------------------------------------------------------
char * nsFilePicker::ConvertToFileSystemCharset(const nsAString& inString)
{
char *outString = nsnull;
nsresult rv = NS_OK;
// get file system charset and create a unicode encoder
if (nsnull == mUnicodeEncoder) {
nsCAutoString fileSystemCharset;
GetFileSystemCharset(fileSystemCharset);
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = ccm->GetUnicodeEncoderRaw(fileSystemCharset.get(), &mUnicodeEncoder);
}
}
// converts from unicode to the file system charset
if (NS_SUCCEEDED(rv)) {
PRInt32 inLength = inString.Length();
const nsAFlatString& flatInString = PromiseFlatString(inString);
PRInt32 outLength;
rv = mUnicodeEncoder->GetMaxLength(flatInString.get(), inLength,
&outLength);
if (NS_SUCCEEDED(rv)) {
outString = static_cast<char*>(nsMemory::Alloc( outLength+1 ));
if (nsnull == outString) {
return nsnull;
}
rv = mUnicodeEncoder->Convert(flatInString.get(), &inLength, outString,
&outLength);
if (NS_SUCCEEDED(rv)) {
outString[outLength] = '\0';
}
}
}
return NS_SUCCEEDED(rv) ? outString : nsnull;
}
示例10: GetEngineList
NS_IMETHODIMP
mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary)
{
// Calls to mozISpellCheckingEngine::SetDictionary might destroy us
nsRefPtr<mozSpellChecker> kungFuDeathGrip = this;
mSpellCheckingEngine = nullptr;
if (aDictionary.IsEmpty()) {
return NS_OK;
}
nsresult rv;
nsCOMArray<mozISpellCheckingEngine> spellCheckingEngines;
rv = GetEngineList(&spellCheckingEngines);
NS_ENSURE_SUCCESS(rv, rv);
for (int32_t i = 0; i < spellCheckingEngines.Count(); i++) {
// We must set mSpellCheckingEngine before we call SetDictionary, since
// SetDictionary calls back to this spell checker to check if the
// dictionary was set
mSpellCheckingEngine = spellCheckingEngines[i];
rv = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get());
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<mozIPersonalDictionary> personalDictionary = do_GetService("@mozilla.org/spellchecker/personaldictionary;1");
mSpellCheckingEngine->SetPersonalDictionary(personalDictionary.get());
nsXPIDLString language;
nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
return serv->GetUtil(language.get(),getter_AddRefs(mConverter));
}
}
mSpellCheckingEngine = nullptr;
// We could not find any engine with the requested dictionary
return NS_ERROR_NOT_AVAILABLE;
}
示例11: FirstNonDigit
bool nsMediaFragmentURIParser::ParseNPTFraction(nsDependentSubstring& aString, double& aFraction)
{
double fraction = 0.0;
if (aString.Length() > 0 && aString[0] == '.') {
PRUint32 index = FirstNonDigit(aString, 1);
if (index > 1) {
nsDependentSubstring number(aString, 0, index);
PRInt32 ec;
fraction = PromiseFlatString(number).ToDouble(&ec);
if (NS_FAILED(ec)) {
return PR_FALSE;
}
}
aString.Rebind(aString, index);
}
aFraction = fraction;
return PR_TRUE;
}
示例12: ResetIfSet
PRBool nsAttrValue::ParseDoubleValue(const nsAString& aString)
{
ResetIfSet();
PRInt32 ec;
double val = PromiseFlatString(aString).ToDouble(&ec);
if (NS_FAILED(ec)) {
return PR_FALSE;
}
if (EnsureEmptyMiscContainer()) {
MiscContainer* cont = GetMiscContainer();
cont->mDoubleValue = val;
cont->mType = eDoubleValue;
nsAutoString serializedFloat;
serializedFloat.AppendFloat(val);
SetMiscAtomOrString(serializedFloat.Equals(aString) ? nsnull : &aString);
return PR_TRUE;
}
return PR_FALSE;
}
示例13: CSP_IsQuotelessKeyword
bool
CSP_IsQuotelessKeyword(const nsAString& aKey)
{
nsString lowerKey = PromiseFlatString(aKey);
ToLowerCase(lowerKey);
static_assert(CSP_LAST_KEYWORD_VALUE ==
(sizeof(CSPStrKeywords) / sizeof(CSPStrKeywords[0])),
"CSP_LAST_KEYWORD_VALUE does not match length of CSPStrKeywords");
nsAutoString keyword;
for (uint32_t i = 0; i < CSP_LAST_KEYWORD_VALUE; i++) {
// skipping the leading ' and trimming the trailing '
keyword.AssignASCII(CSPStrKeywords[i] + 1);
keyword.Trim("'", false, true);
if (lowerKey.Equals(keyword)) {
return true;
}
}
return false;
}
示例14: NS_ENSURE_TRUE
NS_IMETHODIMP
XPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsIDOMXPathExpression **aResult)
{
nsresult rv;
if (!mRecycler) {
nsRefPtr<txResultRecycler> recycler = new txResultRecycler;
NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY);
rv = recycler->init();
NS_ENSURE_SUCCESS(rv, rv);
mRecycler = recycler;
}
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
XPathEvaluatorParseContext pContext(aResolver, !(doc && doc->IsHTML()));
nsAutoPtr<Expr> expression;
rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
getter_Transfers(expression));
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_DOM_NAMESPACE_ERR) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
}
nsCOMPtr<nsIDOMDocument> document = do_QueryReferent(mDocument);
*aResult = new nsXPathExpression(expression, mRecycler, document);
if (!*aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult);
return NS_OK;
}
示例15: PromiseFlatCString
NS_IMETHODIMP
nsPersistentProperties::SetStringProperty(const nsACString& aKey,
const nsAString& aNewValue,
nsAString& aOldValue)
{
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
PropertyTableEntry* entry = static_cast<PropertyTableEntry*>(
PL_DHashTableAdd(&mTable, flatKey.get()));
if (entry->mKey) {
aOldValue = entry->mValue;
NS_WARNING(nsPrintfCString("the property %s already exists\n",
flatKey.get()).get());
} else {
aOldValue.Truncate();
}
entry->mKey = ArenaStrdup(flatKey, &mArena);
entry->mValue = ArenaStrdup(PromiseFlatString(aNewValue), &mArena);
return NS_OK;
}