void ToSentenceCase(std::wstring& str) { if (!str.empty()) { ToLowerCase(str); bool isCapped = false; for (size_t i = 0; i < str.length(); ++i) { if (IsEOSPunct(str[i])) isCapped = false; if (!isCapped && iswalpha(str[i]) != 0) { WCHAR* srcAndDest = &str[i]; LCMapString(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, srcAndDest, 1, srcAndDest, 1); isCapped = true; } } } }
void InternalHeaders::Get(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const { nsAutoCString lowerName; ToLowerCase(aName, lowerName); if (IsInvalidName(lowerName, aRv)) { return; } for (uint32_t i = 0; i < mList.Length(); ++i) { if (lowerName == mList[i].mName) { aValue = mList[i].mValue; return; } } // No value found, so return null to content aValue.SetIsVoid(true); }
void ToSentenceCase(std::wstring& str) { auto to_upper = [](wchar_t& ch) { ch = std::use_facet<std::ctype<wchar_t>>(std::locale()).toupper(ch); }; if (!str.empty()) { ToLowerCase(str); bool isCapped = false; for (size_t i = 0; i < str.length(); ++i) { if (IsEOSPunct(str[i])) isCapped = false; if (!isCapped && iswalpha(str[i]) != 0) { to_upper(str[i]); isCapped = true; } } } }
void nsColorNames::AddRefTable(void) { NS_ASSERTION(!gColorTable, "pre existing array!"); if (!gColorTable) { gColorTable = new nsStaticCaseInsensitiveNameTable(); if (gColorTable) { #ifdef DEBUG { // let's verify the table... for (PRUint32 index = 0; index < eColorName_COUNT; ++index) { nsCAutoString temp1(kColorNames[index]); nsCAutoString temp2(kColorNames[index]); ToLowerCase(temp1); NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); } } #endif gColorTable->Init(kColorNames, eColorName_COUNT); } } }
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; }
nsresult HttpBaseChannel::ApplyContentConversions() { if (!mResponseHead) return NS_OK; LOG(("HttpBaseChannel::ApplyContentConversions [this=%p]\n", this)); if (!mApplyConversion) { LOG(("not applying conversion per mApplyConversion\n")); return NS_OK; } const char *val = mResponseHead->PeekHeader(nsHttp::Content_Encoding); if (gHttpHandler->IsAcceptableEncoding(val)) { nsCOMPtr<nsIStreamConverterService> serv; nsresult rv = gHttpHandler-> GetStreamConverterService(getter_AddRefs(serv)); // we won't fail to load the page just because we couldn't load the // stream converter service.. carry on.. if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIStreamListener> converter; nsCAutoString from(val); ToLowerCase(from); rv = serv->AsyncConvertData(from.get(), "uncompressed", mListener, mListenerContext, getter_AddRefs(converter)); if (NS_SUCCEEDED(rv)) { LOG(("converter installed from \'%s\' to \'uncompressed\'\n", val)); mListener = converter; } } } else if (val != nsnull) { LOG(("Unknown content encoding '%s', ignoring\n", val)); } return NS_OK; }
void CISpellAffix::Strip ( char * szText ) { char * szIterator1 = szText; char * szIterator2 = szText; while ( *szIterator1 ) { if ( !isspace ( (unsigned char) *szIterator1 ) && *szIterator1!='-' ) { *szIterator2 = *szIterator1; ++szIterator2; } ++szIterator1; } *szIterator2 = '\0'; while ( *szText ) { *szText = ToLowerCase ( *szText ); ++szText; } }
/** * Sets a new search, if there's already a search taking place, it's reset. * @param schTree Vdf tree to look into. * @param search Search string. * @param flags Default search is for key case sensitive, * might be changed by setting:<br><code> * VDF_MATCH_VALUE </code><br>and<code> * VDF_IGNORE_CASE</code> * @param level Level in which search will be valid. When -1 (default) * all levels match. */ void VDFSearch::SetSearch(VDFTree *schTree, char *search, UINT flags, int level) { Reset(); searchLevel = level; searchFlags = flags; searchTree = schTree; const UINT startAnchors = 6; searchStr = new char[strlen(search) + 1]; if(flags & VDF_IGNORE_CASE) ToLowerCase(search, searchStr); else strcpy(searchStr, search); // start with 6 levels to avoid unnecessary grows levelCount = startAnchors; levelAnchor = new VDFNode*[startAnchors]; memset(levelAnchor, 0, startAnchors * sizeof(VDFNode*)); }
NS_IMETHODIMP nsCollation::AllocateRawSortKey(int32_t strength, const nsAString& stringIn, uint8_t** key, uint32_t* outLen) { NS_ENSURE_ARG_POINTER(key); NS_ENSURE_ARG_POINTER(outLen); nsAutoString stringNormalized(stringIn); if (strength != kCollationCaseSensitive) { ToLowerCase(stringNormalized); } NS_ConvertUTF16toUTF8 str(stringNormalized); size_t len = str.Length() + 1; void *buffer = PR_Malloc(len); memcpy(buffer, str.get(), len); *key = (uint8_t *)buffer; *outLen = len; return NS_OK; }
bool nsChannelClassifier::IsHostnameWhitelisted(nsIURI *aUri, const nsACString &aWhitelisted) { nsAutoCString host; nsresult rv = aUri->GetHost(host); if (NS_FAILED(rv) || host.IsEmpty()) { return false; } ToLowerCase(host); nsCCharSeparatedTokenizer tokenizer(aWhitelisted, ','); while (tokenizer.hasMoreTokens()) { const nsCSubstring& token = tokenizer.nextToken(); if (token.Equals(host)) { LOG(("nsChannelClassifier[%p]:StartInternal skipping %s (whitelisted)", this, host.get())); return true; } } return false; }
mozEnglishWordUtils::myspCapitalization mozEnglishWordUtils::captype(const nsString &word) { char16_t* lword=ToNewUnicode(word); ToUpperCase(lword,lword,word.Length()); if(word.Equals(lword)){ free(lword); return AllCap; } ToLowerCase(lword,lword,word.Length()); if(word.Equals(lword)){ free(lword); return NoCap; } int32_t length=word.Length(); if(Substring(word,1,length-1).Equals(lword+1)){ free(lword); return InitCap; } free(lword); return HuhCap; }
/******************************* * Constructors and Destructors ******************************/ TimedKey::TimedKey( std::string &keyString, bool repeat, float delay ) :m_activated( false ), m_noRepeatActiv( false ), m_pressed( false ), m_repeat( repeat ), m_delay( delay ) { std::string lwrKey = ToLowerCase( keyString ); // Single character keys can easily be casted if ( lwrKey.size() == 1 ) { m_kCode = static_cast<sf::Key::Code>( keyString[0] ); } else { keyMap_type::iterator keyPair = m_extraKeys.find( lwrKey ); if ( keyPair != m_extraKeys.end() ) { m_kCode = keyPair->second; } else { // No key found so associate with Count, which doesn't match any key m_kCode = sf::Key::Count; } } }
nsIAtom* nsLanguageAtomService::GetLocaleLanguage(nsresult *aError) { nsresult res = NS_OK; do { if (!mLocaleLanguage) { nsCOMPtr<nsILocaleService> localeService; localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID); if (!localeService) { res = NS_ERROR_FAILURE; break; } nsCOMPtr<nsILocale> locale; res = localeService->GetApplicationLocale(getter_AddRefs(locale)); if (NS_FAILED(res)) break; nsAutoString category; category.AssignWithConversion(NSILOCALE_MESSAGE); nsAutoString loc; res = locale->GetCategory(category, loc); if (NS_FAILED(res)) break; ToLowerCase(loc); // use lowercase for all language atoms mLocaleLanguage = do_GetAtom(loc); } } while (0); if (aError) *aError = res; return mLocaleLanguage; }
bool GMPInfoFileParser::Init(nsIFile* aInfoFile) { nsTArray<nsCString> lines; static const size_t MAX_GMP_INFO_FILE_LENGTH = 5 * 1024; nsAutoCString info; if (!ReadIntoString(aInfoFile, info, MAX_GMP_INFO_FILE_LENGTH)) { NS_WARNING("Failed to read info file in GMP process."); return false; } // Note: we pass "\r\n" to SplitAt so that we'll split lines delimited // by \n (Unix), \r\n (Windows) and \r (old MacOSX). SplitAt("\r\n", info, lines); for (nsCString line : lines) { // Field name is the string up to but not including the first ':' // character on the line. int32_t colon = line.FindChar(':'); if (colon <= 0) { // Not allowed to be the first character. // Info field name must be at least one character. continue; } nsAutoCString key(Substring(line, 0, colon)); ToLowerCase(key); key.Trim(" "); nsCString* value = new nsCString(Substring(line, colon + 1)); value->Trim(" "); mValues.Put(key, value); // Hashtable assumes ownership of value. } return true; }
// Helper routine used in tracking app lists. Converts path // entries to lower case and stores them in the trackList array. void nsMIMEInfoWin::ProcessPath(nsCOMPtr<nsIMutableArray>& appList, nsTArray<nsString>& trackList, const nsAString& appFilesystemCommand) { nsAutoString lower(appFilesystemCommand); ToLowerCase(lower); // Don't include firefox.exe in the list WCHAR exe[MAX_PATH+1]; PRUint32 len = GetModuleFileNameW(NULL, exe, MAX_PATH); if (len < MAX_PATH && len != 0) { PRUint32 index = lower.Find(exe); if (index != -1) return; } nsCOMPtr<nsILocalHandlerApp> aApp; if (!GetLocalHandlerApp(appFilesystemCommand, aApp)) return; // Save in our main tracking arrays appList->AppendElement(aApp, false); trackList.AppendElement(lower); }
AliasRecord* GetAliasRecordFromString(char* str) { char* buffer; int len; len = strlen(str); buffer = (char*)malloc(len + 1); memcpy(buffer, str, len); buffer[len] = 0; ToLowerCase(buffer); AliasRecord* ar = first_alias_record; while(ar != NULL) { if(strcmp(buffer, ar->alias) == 0) { break; } ar = ar->next; } free(buffer); return ar; }
nsresult gfxQtPlatform::UpdateFontList() { FcPattern *pat = NULL; FcObjectSet *os = NULL; FcFontSet *fs = NULL; PRInt32 result = -1; pat = FcPatternCreate(); os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_INDEX, FC_WEIGHT, FC_SLANT, FC_WIDTH, NULL); fs = FcFontList(NULL, pat, os); for (int i = 0; i < fs->nfont; i++) { char *str; if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; printf("Family: %s\n", str); nsAutoString name(NS_ConvertUTF8toUTF16(nsDependentCString(str)).get()); nsAutoString key(name); ToLowerCase(key); nsRefPtr<FontFamily> ff; if (!gPlatformFonts->Get(key, &ff)) { ff = new FontFamily(name); gPlatformFonts->Put(key, ff); } FontEntry *fe = new FontEntry(ff->Name()); ff->AddFontEntry(fe); if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, (FcChar8 **) &str) == FcResultMatch) { fe->mFilename = nsDependentCString(str); printf(" - file: %s\n", str); } int x; if (FcPatternGetInteger(fs->fonts[i], FC_INDEX, 0, &x) == FcResultMatch) { printf(" - index: %d\n", x); fe->mFTFontIndex = x; } else { fe->mFTFontIndex = 0; } if (FcPatternGetInteger(fs->fonts[i], FC_WEIGHT, 0, &x) == FcResultMatch) { switch(x) { case 0: fe->mWeight = 100; break; case 40: fe->mWeight = 200; break; case 50: fe->mWeight = 300; break; case 75: case 80: fe->mWeight = 400; break; case 100: fe->mWeight = 500; break; case 180: fe->mWeight = 600; break; case 200: fe->mWeight = 700; break; case 205: fe->mWeight = 800; break; case 210: fe->mWeight = 900; break; default: // rough estimate fe->mWeight = (((x * 4) + 100) / 100) * 100; break; } printf(" - weight: %d\n", fe->mWeight); } fe->mItalic = PR_FALSE; if (FcPatternGetInteger(fs->fonts[i], FC_SLANT, 0, &x) == FcResultMatch) { switch (x) { case FC_SLANT_ITALIC: case FC_SLANT_OBLIQUE: fe->mItalic = PR_TRUE; } printf(" - slant: %d\n", x); } if (FcPatternGetInteger(fs->fonts[i], FC_WIDTH, 0, &x) == FcResultMatch) printf(" - width: %d\n", x); // XXX deal with font-stretch stuff later } if (pat) FcPatternDestroy(pat); if (os) FcObjectSetDestroy(os); if (fs) FcFontSetDestroy(fs); return sFontconfigUtils->UpdateFontList(); }
void nsCSPHostSrc::setFileAndArguments(const nsAString& aFile) { mFileAndArguments = aFile; ToLowerCase(mFileAndArguments); }
void nsCSPHostSrc::appendPath(const nsAString& aPath) { mPath.Append(aPath); ToLowerCase(mPath); }
void nsCSPHostSrc::setPort(const nsAString& aPort) { mPort = aPort; ToLowerCase(mPort); }
nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, const nsACString* aProfileName, const nsACString* aAppName, const nsACString* aVendorName, bool aLocal) { NS_ASSERTION(aFile, "Null pointer!"); if (!gAppData) { return NS_ERROR_FAILURE; } nsAutoCString profile; nsAutoCString appName; nsAutoCString vendor; if (aProfileName && !aProfileName->IsEmpty()) { profile = *aProfileName; } else if (aAppName) { appName = *aAppName; if (aVendorName) { vendor = *aVendorName; } } else if (gAppData->profile) { profile = gAppData->profile; } else { appName = gAppData->name; vendor = gAppData->vendor; } nsresult rv; #if defined (XP_MACOSX) if (!profile.IsEmpty()) { rv = AppendProfileString(aFile, profile.get()); } else { // Note that MacOS ignores the vendor when creating the profile hierarchy - // all application preferences directories live alongside one another in // ~/Library/Application Support/ rv = aFile->AppendNative(appName); } NS_ENSURE_SUCCESS(rv, rv); #elif defined(XP_WIN) if (!profile.IsEmpty()) { rv = AppendProfileString(aFile, profile.get()); } else { if (!vendor.IsEmpty()) { rv = aFile->AppendNative(vendor); NS_ENSURE_SUCCESS(rv, rv); } rv = aFile->AppendNative(appName); } NS_ENSURE_SUCCESS(rv, rv); #elif defined(ANDROID) // The directory used for storing profiles // The parent of this directory is set in GetUserDataDirectoryHome // XXX: handle gAppData->profile properly // XXXsmaug ...and the rest of the profile creation! MOZ_ASSERT(!aAppName, "Profile creation for external applications is not implemented!"); rv = aFile->AppendNative(nsDependentCString("mozilla")); NS_ENSURE_SUCCESS(rv, rv); #elif defined(XP_UNIX) nsAutoCString folder; // Make it hidden (by starting with "."), except when local (the // profile is already under ~/.cache or XDG_CACHE_HOME). if (!aLocal) folder.Assign('.'); if (!profile.IsEmpty()) { // Skip any leading path characters const char* profileStart = profile.get(); while (*profileStart == '/' || *profileStart == '\\') profileStart++; // On the off chance that someone wanted their folder to be hidden don't // let it become ".." if (*profileStart == '.' && !aLocal) profileStart++; folder.Append(profileStart); ToLowerCase(folder); rv = AppendProfileString(aFile, folder.BeginReading()); } else { if (!vendor.IsEmpty()) { folder.Append(vendor); ToLowerCase(folder); rv = aFile->AppendNative(folder); NS_ENSURE_SUCCESS(rv, rv); folder.Truncate(); } folder.Append(appName); ToLowerCase(folder); rv = aFile->AppendNative(folder); } NS_ENSURE_SUCCESS(rv, rv); #else #error "Don't know how to get profile path on your platform" #endif return NS_OK; }
nsresult HttpBaseChannel::ApplyContentConversions() { if (!mResponseHead) return NS_OK; LOG(("HttpBaseChannel::ApplyContentConversions [this=%p]\n", this)); if (!mApplyConversion) { LOG(("not applying conversion per mApplyConversion\n")); return NS_OK; } nsCAutoString contentEncoding; char *cePtr, *val; nsresult rv; rv = mResponseHead->GetHeader(nsHttp::Content_Encoding, contentEncoding); if (NS_FAILED(rv) || contentEncoding.IsEmpty()) return NS_OK; // The encodings are listed in the order they were applied // (see rfc 2616 section 14.11), so they need to removed in reverse // order. This is accomplished because the converter chain ends up // being a stack with the last converter created being the first one // to accept the raw network data. cePtr = contentEncoding.BeginWriting(); PRUint32 count = 0; while ((val = nsCRT::strtok(cePtr, HTTP_LWS ",", &cePtr))) { if (++count > 16) { // That's ridiculous. We only understand 2 different ones :) // but for compatibility with old code, we will just carry on without // removing the encodings LOG(("Too many Content-Encodings. Ignoring remainder.\n")); break; } if (gHttpHandler->IsAcceptableEncoding(val)) { nsCOMPtr<nsIStreamConverterService> serv; rv = gHttpHandler->GetStreamConverterService(getter_AddRefs(serv)); // we won't fail to load the page just because we couldn't load the // stream converter service.. carry on.. if (NS_FAILED(rv)) { if (val) LOG(("Unknown content encoding '%s', ignoring\n", val)); continue; } nsCOMPtr<nsIStreamListener> converter; nsCAutoString from(val); ToLowerCase(from); rv = serv->AsyncConvertData(from.get(), "uncompressed", mListener, mListenerContext, getter_AddRefs(converter)); if (NS_FAILED(rv)) { LOG(("Unexpected failure of AsyncConvertData %s\n", val)); return rv; } LOG(("converter removed '%s' content-encoding\n", val)); mListener = converter; } else { if (val) LOG(("Unknown content encoding '%s', ignoring\n", val)); } } return NS_OK; }
nsresult nsMimeHtmlDisplayEmitter::BroadcastHeaders(nsIMsgHeaderSink * aHeaderSink, int32_t aHeaderMode, bool aFromNewsgroup) { // two string enumerators to pass out to the header sink nsRefPtr<nsMimeStringEnumerator> headerNameEnumerator = new nsMimeStringEnumerator(); NS_ENSURE_TRUE(headerNameEnumerator, NS_ERROR_OUT_OF_MEMORY); nsRefPtr<nsMimeStringEnumerator> headerValueEnumerator = new nsMimeStringEnumerator(); NS_ENSURE_TRUE(headerValueEnumerator, NS_ERROR_OUT_OF_MEMORY); nsCString extraExpandedHeaders; nsTArray<nsCString> extraExpandedHeadersArray; nsAutoCString convertedDateString; nsresult rv; nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (pPrefBranch) { pPrefBranch->GetCharPref("mailnews.headers.extraExpandedHeaders", getter_Copies(extraExpandedHeaders)); // todo - should make this upper case if (!extraExpandedHeaders.IsEmpty()) { ToLowerCase(extraExpandedHeaders); ParseString(extraExpandedHeaders, ' ', extraExpandedHeadersArray); } } for (int32_t i=0; i<mHeaderArray->Count(); i++) { headerInfoType * headerInfo = (headerInfoType *) mHeaderArray->ElementAt(i); if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) || (!headerInfo->value) || (!(*headerInfo->value))) continue; const char * headerValue = headerInfo->value; // optimization: if we aren't in view all header view mode, we only show a small set of the total # of headers. // don't waste time sending those out to the UI since the UI is going to ignore them anyway. if (aHeaderMode != VIEW_ALL_HEADERS && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer)) { nsDependentCString headerStr(headerInfo->name); if (PL_strcasecmp("to", headerInfo->name) && PL_strcasecmp("from", headerInfo->name) && PL_strcasecmp("cc", headerInfo->name) && PL_strcasecmp("newsgroups", headerInfo->name) && PL_strcasecmp("bcc", headerInfo->name) && PL_strcasecmp("followup-to", headerInfo->name) && PL_strcasecmp("reply-to", headerInfo->name) && PL_strcasecmp("subject", headerInfo->name) && PL_strcasecmp("organization", headerInfo->name) && PL_strcasecmp("user-agent", headerInfo->name) && PL_strcasecmp("content-base", headerInfo->name) && PL_strcasecmp("sender", headerInfo->name) && PL_strcasecmp("date", headerInfo->name) && PL_strcasecmp("x-mailer", headerInfo->name) && PL_strcasecmp("content-type", headerInfo->name) && PL_strcasecmp("message-id", headerInfo->name) && PL_strcasecmp("x-newsreader", headerInfo->name) && PL_strcasecmp("x-mimeole", headerInfo->name) && PL_strcasecmp("references", headerInfo->name) && PL_strcasecmp("in-reply-to", headerInfo->name) && PL_strcasecmp("list-post", headerInfo->name) && PL_strcasecmp("delivered-to", headerInfo->name) && // make headerStr lower case because IndexOf is case-sensitive (!extraExpandedHeadersArray.Length() || (ToLowerCase(headerStr), extraExpandedHeadersArray.IndexOf(headerStr) == extraExpandedHeadersArray.NoIndex))) continue; } headerNameEnumerator->Append(headerInfo->name); headerValueEnumerator->Append(headerValue); // Add a localized version of the date header if we encounter it. if (!PL_strcasecmp("Date", headerInfo->name)) { headerNameEnumerator->Append("X-Mozilla-LocalizedDate"); GenerateDateString(headerValue, convertedDateString, false); headerValueEnumerator->Append(convertedDateString); } } aHeaderSink->ProcessHeaders(headerNameEnumerator, headerValueEnumerator, aFromNewsgroup); return rv; }
nsresult gfxQtPlatform::ResolveFontName(const nsAString& aFontName, FontResolverCallback aCallback, void *aClosure, PRBool& aAborted) { nsAutoString name(aFontName); ToLowerCase(name); nsRefPtr<FontFamily> ff; if (gPlatformFonts->Get(name, &ff) || gPlatformFontAliases->Get(name, &ff)) { aAborted = !(*aCallback)(ff->Name(), aClosure); return NS_OK; } nsCAutoString utf8Name = NS_ConvertUTF16toUTF8(aFontName); FcPattern *npat = FcPatternCreate(); FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get()); FcObjectSet *nos = FcObjectSetBuild(FC_FAMILY, NULL); FcFontSet *nfs = FcFontList(NULL, npat, nos); for (int k = 0; k < nfs->nfont; k++) { FcChar8 *str; if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))); ToLowerCase(altName); if (gPlatformFonts->Get(altName, &ff)) { printf("Adding alias: %s -> %s\n", utf8Name.get(), str); gPlatformFontAliases->Put(name, ff); aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure); goto DONE; } } FcPatternDestroy(npat); FcObjectSetDestroy(nos); FcFontSetDestroy(nfs); { npat = FcPatternCreate(); FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get()); FcPatternDel(npat, FC_LANG); FcConfigSubstitute(NULL, npat, FcMatchPattern); FcDefaultSubstitute(npat); nos = FcObjectSetBuild(FC_FAMILY, NULL); nfs = FcFontList(NULL, npat, nos); FcResult fresult; FcPattern *match = FcFontMatch(NULL, npat, &fresult); if (match) FcFontSetAdd(nfs, match); for (int k = 0; k < nfs->nfont; k++) { FcChar8 *str; if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))); ToLowerCase(altName); if (gPlatformFonts->Get(altName, &ff)) { printf("Adding alias: %s -> %s\n", utf8Name.get(), str); gPlatformFontAliases->Put(name, ff); aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure); goto DONE; } } } DONE: FcPatternDestroy(npat); FcObjectSetDestroy(nos); FcFontSetDestroy(nfs); return NS_OK; }
void nsCaseTransformTextRunFactory::RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) { PRUint32 length = aTextRun->GetLength(); const PRUnichar* str = aTextRun->mString.BeginReading(); nsRefPtr<nsStyleContext>* styles = aTextRun->mStyles.Elements(); nsAutoString convertedString; nsAutoTArray<bool,50> charsToMergeArray; nsAutoTArray<nsStyleContext*,50> styleArray; nsAutoTArray<PRUint8,50> canBreakBeforeArray; PRUint32 extraCharsCount = 0; PRUint32 i; for (i = 0; i < length; ++i) { PRUnichar ch = str[i]; charsToMergeArray.AppendElement(false); styleArray.AppendElement(styles[i]); canBreakBeforeArray.AppendElement(aTextRun->CanBreakLineBefore(i)); PRUint8 style = mAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE : styles[i]->GetStyleText()->mTextTransform; bool extraChar = false; switch (style) { case NS_STYLE_TEXT_TRANSFORM_LOWERCASE: ch = ToLowerCase(ch); break; case NS_STYLE_TEXT_TRANSFORM_UPPERCASE: if (ch == SZLIG) { convertedString.Append('S'); extraChar = true; ch = 'S'; } else { ch = ToUpperCase(ch); } break; case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE: if (i < aTextRun->mCapitalize.Length() && aTextRun->mCapitalize[i]) { if (ch == SZLIG) { convertedString.Append('S'); extraChar = true; ch = 'S'; } else { ch = ToTitleCase(ch); } } break; default: break; } convertedString.Append(ch); if (extraChar) { ++extraCharsCount; charsToMergeArray.AppendElement(true); styleArray.AppendElement(styles[i]); canBreakBeforeArray.AppendElement(false); } } PRUint32 flags; gfxTextRunFactory::Parameters innerParams = GetParametersForInner(aTextRun, &flags, aRefContext); gfxFontGroup* fontGroup = aTextRun->GetFontGroup(); nsAutoPtr<nsTransformedTextRun> transformedChild; nsAutoPtr<gfxTextRun> cachedChild; gfxTextRun* child; if (mInnerTransformingTextRunFactory) { transformedChild = mInnerTransformingTextRunFactory->MakeTextRun( convertedString.BeginReading(), convertedString.Length(), &innerParams, fontGroup, flags, styleArray.Elements(), false); child = transformedChild.get(); } else { cachedChild = fontGroup->MakeTextRun( convertedString.BeginReading(), convertedString.Length(), &innerParams, flags); child = cachedChild.get(); } if (!child) return; // Copy potential linebreaks into child so they're preserved // (and also child will be shaped appropriately) NS_ASSERTION(convertedString.Length() == canBreakBeforeArray.Length(), "Dropped characters or break-before values somewhere!"); child->SetPotentialLineBreaks(0, canBreakBeforeArray.Length(), canBreakBeforeArray.Elements(), aRefContext); if (transformedChild) { transformedChild->FinishSettingProperties(aRefContext); } if (extraCharsCount > 0) { // Now merge multiple characters into one multi-glyph character as required MergeCharactersInTextRun(aTextRun, child, charsToMergeArray.Elements()); } else { // No merging to do, so just copy; this produces a more optimized textrun. // We can't steal the data because the child may be cached and stealing // the data would break the cache. aTextRun->ResetGlyphRuns(); aTextRun->CopyGlyphDataFrom(child, 0, child->GetLength(), 0); } }
nsCSPSchemeSrc::nsCSPSchemeSrc(const nsAString& aScheme) : mScheme(aScheme) { ToLowerCase(mScheme); }
bool nsCaseTransformTextRunFactory::TransformString( const nsAString& aString, nsString& aConvertedString, bool aAllUppercase, const nsIAtom* aLanguage, nsTArray<bool>& aCharsToMergeArray, nsTArray<bool>& aDeletedCharsArray, nsTransformedTextRun* aTextRun, nsTArray<uint8_t>* aCanBreakBeforeArray, nsTArray<nsStyleContext*>* aStyleArray) { NS_PRECONDITION(!aTextRun || (aCanBreakBeforeArray && aStyleArray), "either none or all three optional parameters required"); uint32_t length = aString.Length(); const char16_t* str = aString.BeginReading(); bool mergeNeeded = false; bool capitalizeDutchIJ = false; bool prevIsLetter = false; bool ntPrefix = false; // true immediately after a word-initial 'n' or 't' // when doing Irish lowercasing uint32_t sigmaIndex = uint32_t(-1); nsIUGenCategory::nsUGenCategory cat; uint8_t style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE : 0; const nsIAtom* lang = aLanguage; LanguageSpecificCasingBehavior languageSpecificCasing = GetCasingFor(lang); mozilla::GreekCasing::State greekState; mozilla::IrishCasing::State irishState; uint32_t irishMark = uint32_t(-1); // location of possible prefix letter(s) for (uint32_t i = 0; i < length; ++i) { uint32_t ch = str[i]; nsStyleContext* styleContext; if (aTextRun) { styleContext = aTextRun->mStyles[i]; style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE : styleContext->StyleText()->mTextTransform; if (lang != styleContext->StyleFont()->mLanguage) { lang = styleContext->StyleFont()->mLanguage; languageSpecificCasing = GetCasingFor(lang); greekState.Reset(); irishState.Reset(); irishMark = uint32_t(-1); } } int extraChars = 0; const mozilla::unicode::MultiCharMapping *mcm; bool inhibitBreakBefore = false; // have we just deleted preceding hyphen? if (NS_IS_HIGH_SURROGATE(ch) && i < length - 1 && NS_IS_LOW_SURROGATE(str[i + 1])) { ch = SURROGATE_TO_UCS4(ch, str[i + 1]); } switch (style) { case NS_STYLE_TEXT_TRANSFORM_LOWERCASE: if (languageSpecificCasing == eLSCB_Turkish) { if (ch == 'I') { ch = LATIN_SMALL_LETTER_DOTLESS_I; prevIsLetter = true; sigmaIndex = uint32_t(-1); break; } if (ch == LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE) { ch = 'i'; prevIsLetter = true; sigmaIndex = uint32_t(-1); break; } } cat = mozilla::unicode::GetGenCategory(ch); if (languageSpecificCasing == eLSCB_Irish && cat == nsIUGenCategory::kLetter) { // See bug 1018805 for Irish lowercasing requirements if (!prevIsLetter && (ch == 'n' || ch == 't')) { ntPrefix = true; } else { if (ntPrefix && mozilla::IrishCasing::IsUpperVowel(ch)) { aConvertedString.Append('-'); ++extraChars; } ntPrefix = false; } } else { ntPrefix = false; } // Special lowercasing behavior for Greek Sigma: note that this is listed // as context-sensitive in Unicode's SpecialCasing.txt, but is *not* a // language-specific mapping; it applies regardless of the language of // the element. // // The lowercase mapping for CAPITAL SIGMA should be to SMALL SIGMA (i.e. // the non-final form) whenever there is a following letter, or when the // CAPITAL SIGMA occurs in isolation (neither preceded nor followed by a // LETTER); and to FINAL SIGMA when it is preceded by another letter but // not followed by one. // // To implement the context-sensitive nature of this mapping, we keep // track of whether the previous character was a letter. If not, CAPITAL // SIGMA will map directly to SMALL SIGMA. If the previous character // was a letter, CAPITAL SIGMA maps to FINAL SIGMA and we record the // position in the converted string; if we then encounter another letter, // that FINAL SIGMA is replaced with a standard SMALL SIGMA. // If sigmaIndex is not -1, it marks where we have provisionally mapped // a CAPITAL SIGMA to FINAL SIGMA; if we now find another letter, we // need to change it to SMALL SIGMA. if (sigmaIndex != uint32_t(-1)) { if (cat == nsIUGenCategory::kLetter) { aConvertedString.SetCharAt(GREEK_SMALL_LETTER_SIGMA, sigmaIndex); } } if (ch == GREEK_CAPITAL_LETTER_SIGMA) { // If preceding char was a letter, map to FINAL instead of SMALL, // and note where it occurred by setting sigmaIndex; we'll change it // to standard SMALL SIGMA later if another letter follows if (prevIsLetter) { ch = GREEK_SMALL_LETTER_FINAL_SIGMA; sigmaIndex = aConvertedString.Length(); } else { // CAPITAL SIGMA not preceded by a letter is unconditionally mapped // to SMALL SIGMA ch = GREEK_SMALL_LETTER_SIGMA; sigmaIndex = uint32_t(-1); } prevIsLetter = true; break; } // ignore diacritics for the purpose of contextual sigma mapping; // otherwise, reset prevIsLetter appropriately and clear the // sigmaIndex marker if (cat != nsIUGenCategory::kMark) { prevIsLetter = (cat == nsIUGenCategory::kLetter); sigmaIndex = uint32_t(-1); } mcm = mozilla::unicode::SpecialLower(ch); if (mcm) { int j = 0; while (j < 2 && mcm->mMappedChars[j + 1]) { aConvertedString.Append(mcm->mMappedChars[j]); ++extraChars; ++j; } ch = mcm->mMappedChars[j]; break; } ch = ToLowerCase(ch); break; case NS_STYLE_TEXT_TRANSFORM_UPPERCASE: if (languageSpecificCasing == eLSCB_Turkish && ch == 'i') { ch = LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE; break; } if (languageSpecificCasing == eLSCB_Greek) { ch = mozilla::GreekCasing::UpperCase(ch, greekState); break; } if (languageSpecificCasing == eLSCB_Irish) { bool mark; uint8_t action; ch = mozilla::IrishCasing::UpperCase(ch, irishState, mark, action); if (mark) { irishMark = aConvertedString.Length(); break; } else if (action) { nsString& str = aConvertedString; // shorthand switch (action) { case 1: // lowercase a single prefix letter NS_ASSERTION(str.Length() > 0 && irishMark < str.Length(), "bad irishMark!"); str.SetCharAt(ToLowerCase(str[irishMark]), irishMark); irishMark = uint32_t(-1); break; case 2: // lowercase two prefix letters (immediately before current pos) NS_ASSERTION(str.Length() >= 2 && irishMark == str.Length() - 2, "bad irishMark!"); str.SetCharAt(ToLowerCase(str[irishMark]), irishMark); str.SetCharAt(ToLowerCase(str[irishMark + 1]), irishMark + 1); irishMark = uint32_t(-1); break; case 3: // lowercase one prefix letter, and delete following hyphen // (which must be the immediately-preceding char) NS_ASSERTION(str.Length() >= 2 && irishMark == str.Length() - 2, "bad irishMark!"); str.Replace(irishMark, 2, ToLowerCase(str[irishMark])); aDeletedCharsArray[irishMark + 1] = true; // Remove the trailing entries (corresponding to the deleted hyphen) // from the auxiliary arrays. aCharsToMergeArray.SetLength(aCharsToMergeArray.Length() - 1); if (aTextRun) { aStyleArray->SetLength(aStyleArray->Length() - 1); aCanBreakBeforeArray->SetLength(aCanBreakBeforeArray->Length() - 1); inhibitBreakBefore = true; } mergeNeeded = true; irishMark = uint32_t(-1); break; } // ch has been set to the uppercase for current char; // No need to check for SpecialUpper here as none of the characters // that could trigger an Irish casing action have special mappings. break; } // If we didn't have any special action to perform, fall through // to check for special uppercase (ß) } mcm = mozilla::unicode::SpecialUpper(ch); if (mcm) { int j = 0; while (j < 2 && mcm->mMappedChars[j + 1]) { aConvertedString.Append(mcm->mMappedChars[j]); ++extraChars; ++j; } ch = mcm->mMappedChars[j]; break; } ch = ToUpperCase(ch); break; case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE: if (aTextRun) { if (capitalizeDutchIJ && ch == 'j') { ch = 'J'; capitalizeDutchIJ = false; break; } capitalizeDutchIJ = false; if (i < aTextRun->mCapitalize.Length() && aTextRun->mCapitalize[i]) { if (languageSpecificCasing == eLSCB_Turkish && ch == 'i') { ch = LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE; break; } if (languageSpecificCasing == eLSCB_Dutch && ch == 'i') { ch = 'I'; capitalizeDutchIJ = true; break; } mcm = mozilla::unicode::SpecialTitle(ch); if (mcm) { int j = 0; while (j < 2 && mcm->mMappedChars[j + 1]) { aConvertedString.Append(mcm->mMappedChars[j]); ++extraChars; ++j; } ch = mcm->mMappedChars[j]; break; } ch = ToTitleCase(ch); } } break; case NS_STYLE_TEXT_TRANSFORM_FULLWIDTH: ch = mozilla::unicode::GetFullWidth(ch); break; default: break; } if (ch == uint32_t(-1)) { aDeletedCharsArray.AppendElement(true); mergeNeeded = true; } else { aDeletedCharsArray.AppendElement(false); aCharsToMergeArray.AppendElement(false); if (aTextRun) { aStyleArray->AppendElement(styleContext); aCanBreakBeforeArray->AppendElement(inhibitBreakBefore ? false : aTextRun->CanBreakLineBefore(i)); } if (IS_IN_BMP(ch)) { aConvertedString.Append(ch); } else { aConvertedString.Append(H_SURROGATE(ch)); aConvertedString.Append(L_SURROGATE(ch)); ++i; aDeletedCharsArray.AppendElement(true); // not exactly deleted, but the // trailing surrogate is skipped ++extraChars; } while (extraChars-- > 0) { mergeNeeded = true; aCharsToMergeArray.AppendElement(true); if (aTextRun) { aStyleArray->AppendElement(styleContext); aCanBreakBeforeArray->AppendElement(false); } } } } return mergeNeeded; }
nsCSPHostSrc::nsCSPHostSrc(const nsAString& aHost) : mHost(aHost) { ToLowerCase(mHost); }
nsresult nsMsgTagService::MigrateLabelsToTags() { nsCString prefString; int32_t prefVersion = 0; nsresult rv = m_tagPrefBranch->GetIntPref(TAG_PREF_VERSION, &prefVersion); if (NS_SUCCEEDED(rv) && prefVersion > 1) return rv; else if (prefVersion == 1) { gMigratingKeys = true; // need to convert the keys to lower case nsIMsgTag **tagArray; uint32_t numTags; GetAllTags(&numTags, &tagArray); for (uint32_t tagIndex = 0; tagIndex < numTags; tagIndex++) { nsCAutoString key, color, ordinal; nsAutoString tagStr; nsIMsgTag *tag = tagArray[tagIndex]; tag->GetKey(key); tag->GetTag(tagStr); tag->GetOrdinal(ordinal); tag->GetColor(color); DeleteKey(key); ToLowerCase(key); AddTagForKey(key, tagStr, color, ordinal); } NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numTags, tagArray); gMigratingKeys = false; } else { nsCOMPtr<nsIPrefBranch> prefRoot(do_GetService(NS_PREFSERVICE_CONTRACTID)); nsCOMPtr<nsIPrefLocalizedString> pls; nsString ucsval; nsCAutoString labelKey("$label1"); for(int32_t i = 0; i < PREF_LABELS_MAX; ) { prefString.Assign(PREF_LABELS_DESCRIPTION); prefString.AppendInt(i + 1); rv = prefRoot->GetComplexValue(prefString.get(), NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(pls)); NS_ENSURE_SUCCESS(rv, rv); pls->ToString(getter_Copies(ucsval)); prefString.Assign(PREF_LABELS_COLOR); prefString.AppendInt(i + 1); nsCString csval; rv = prefRoot->GetCharPref(prefString.get(), getter_Copies(csval)); NS_ENSURE_SUCCESS(rv, rv); rv = AddTagForKey(labelKey, ucsval, csval, EmptyCString()); NS_ENSURE_SUCCESS(rv, rv); labelKey.SetCharAt(++i + '1', 6); } } m_tagPrefBranch->SetIntPref(TAG_PREF_VERSION, 2); return rv; }
void nsCSPHostSrc::setScheme(const nsAString& aScheme) { mScheme = aScheme; ToLowerCase(mScheme); }