void WifiProxyService::DispatchWifiEvent(const nsAString& aEvent, const nsACString& aInterface) { MOZ_ASSERT(NS_IsMainThread()); #if ANDROID_VERSION < 19 mListener->OnWaitEvent(aEvent, aInterface); #else // The interface might be embedded in the event string such as // "IFNAME=wlan0 CTRL-EVENT-BSS-ADDED 65 3c:94:d5:7c:11:8b". // Parse the interface name from the event string and use p2p0 // as the default interface if "IFNAME" is not found. nsAutoString event; nsAutoString embeddedInterface(NS_LITERAL_STRING("p2p0")); if (StringBeginsWith(aEvent, NS_LITERAL_STRING("IFNAME"))) { int32_t ifnameFrom = aEvent.FindChar('=') + 1; int32_t ifnameTo = aEvent.FindChar(' ') - 1; embeddedInterface = Substring(aEvent, ifnameFrom, ifnameTo - ifnameFrom + 1); event = Substring(aEvent, aEvent.FindChar(' ') + 1); } else { event = aEvent; } mListener->OnWaitEvent(event, NS_ConvertUTF16toUTF8(embeddedInterface)); #endif }
static void __ReplaceChar (nsAString &string, const PRUnichar replace, const PRUnichar with) { PRInt32 i = string.FindChar (replace); while (i >= 0) { string.Replace (i, 1, &with, 1); i = string.FindChar (replace); } }
NS_IMETHODIMP nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); if (!mUpdateDictionaryRunning) { nsDefaultStringComparator comparator; nsAutoString langCode; PRInt32 dashIdx = aDictionary.FindChar('-'); if (dashIdx != -1) { langCode.Assign(Substring(aDictionary, 0, dashIdx)); } else { langCode.Assign(aDictionary); } if (mPreferredLang.IsEmpty() || !nsStyleUtil::DashMatchCompare(mPreferredLang, langCode, comparator)) { // When user sets dictionary manually, we store this value associated // with editor url. gDictionaryStore->StoreCurrentDictionary(mEditor, aDictionary); } else { // If user sets a dictionary matching (even partially), lang defined by // document, we consider content pref has been canceled, and we clear it. gDictionaryStore->ClearCurrentDictionary(mEditor); } // Also store it in as a preference. It will be used as a default value // when everything else fails. Preferences::SetString("spellchecker.dictionary", aDictionary); } return mSpellChecker->SetCurrentDictionary(aDictionary); }
nsTemplateCondition::nsTemplateCondition(nsIAtom* aSourceVariable, const nsAString& aRelation, const nsAString& aTargets, bool aIgnoreCase, bool aNegate, bool aIsMultiple) : mSourceVariable(aSourceVariable), mIgnoreCase(aIgnoreCase), mNegate(aNegate), mNext(nullptr) { SetRelation(aRelation); if (aIsMultiple) { PRInt32 start = 0, end = 0; while ((end = aTargets.FindChar(',',start)) >= 0) { if (end > start) { mTargetList.AppendElement(Substring(aTargets, start, end - start)); } start = end + 1; } if (start < PRInt32(aTargets.Length())) { mTargetList.AppendElement(Substring(aTargets, start)); } } else { mTargetList.AppendElement(aTargets); } MOZ_COUNT_CTOR(nsTemplateCondition); }
static void RemoveCharsetFromFontSubstitute(nsAString &aName) { int32_t comma = aName.FindChar(PRUnichar(',')); if (comma >= 0) aName.Truncate(comma); }
/* static */ void PeerIdentity::GetUser(const nsAString& aPeerIdentity, nsAString& aUser) { int32_t at = aPeerIdentity.FindChar('@'); if (at >= 0) { aUser = Substring(aPeerIdentity, 0, at); } else { aUser.Truncate(); } }
/* static */ void PeerIdentity::GetHost(const nsAString& aPeerIdentity, nsAString& aHost) { int32_t at = aPeerIdentity.FindChar('@'); if (at >= 0) { aHost = Substring(aPeerIdentity, at + 1); } else { aHost = aPeerIdentity; } }
nsresult nsSOAPUtils::GetNamespaceURI(nsISOAPEncoding * aEncoding, nsIDOMElement * aScope, const nsAString & aQName, nsAString & aURI) { aURI.Truncate(); PRInt32 i = aQName.FindChar(':'); if (i < 0) { return NS_OK; } nsAutoString prefix; prefix = Substring(aQName, 0, i); nsAutoString result; if (prefix.Equals(gSOAPStrings->kXMLPrefix)) { result.Assign(gSOAPStrings->kXMLNamespaceURI); } else { nsresult rc; nsCOMPtr<nsIDOMNode> current = aScope; nsCOMPtr<nsIDOMNamedNodeMap> attrs; nsCOMPtr<nsIDOMNode> temp; nsAutoString value; while (current) { rc = current->GetAttributes(getter_AddRefs(attrs)); if (NS_FAILED(rc)) return rc; if (attrs) { rc = attrs->GetNamedItemNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix, getter_AddRefs(temp)); if (NS_FAILED(rc)) return rc; if (temp) { rc = temp->GetNodeValue(result); if (NS_FAILED(rc)) return rc; break; } } rc = current->GetParentNode(getter_AddRefs(temp)); if (NS_FAILED(rc)) return rc; current = temp; } if (!current) return SOAP_EXCEPTION(NS_ERROR_FAILURE,"SOAP_NAMESPACE", "Unable to resolve prefix in attribute value to namespace URI"); } if (aEncoding) { return aEncoding->GetInternalSchemaURI(result,aURI); } aURI.Assign(result); return NS_OK; }
const nsDependentSubstring XMLUtils::getLocalPart(const nsAString& src) { // Anything after ':' is the local part of the name PRInt32 idx = src.FindChar(':'); if (idx == kNotFound) { return Substring(src, 0, src.Length()); } NS_ASSERTION(idx > 0, "This QName looks invalid."); return Substring(src, idx + 1, src.Length() - (idx + 1)); }
nsresult nsSOAPUtils::GetLocalName(const nsAString & aQName, nsAString & aLocalName) { PRInt32 i = aQName.FindChar(':'); if (i < 0) aLocalName = aQName; else aLocalName = Substring(aQName, i+1, aQName.Length() - (i+1)); return NS_OK; }
static void ProcessLengthValue(const nsAString * aInputString, nsAString & aOutputString, const char * aDefaultValueString, const char * aPrependString, const char* aAppendString) { aOutputString.Truncate(); if (aInputString) { aOutputString.Append(*aInputString); if (-1 == aOutputString.FindChar(char16_t('%'))) { aOutputString.AppendLiteral("px"); } } }
nsresult txStylesheetCompilerState::init(const nsAString& aStylesheetURI, txStylesheet* aStylesheet, txListIterator* aInsertPosition) { NS_ASSERTION(!aStylesheet || aInsertPosition, "must provide insertposition if loading subsheet"); mStylesheetURI = aStylesheetURI; // Check for fragment identifier of an embedded stylesheet. int32_t fragment = aStylesheetURI.FindChar('#') + 1; if (fragment > 0) { int32_t fragmentLength = aStylesheetURI.Length() - fragment; if (fragmentLength > 0) { // This is really an embedded stylesheet, not just a // "url#". We may want to unescape the fragment. mTarget = Substring(aStylesheetURI, (uint32_t)fragment, fragmentLength); mEmbedStatus = eNeedEmbed; mHandlerTable = gTxEmbedHandler; } } nsresult rv = NS_OK; if (aStylesheet) { mStylesheet = aStylesheet; mToplevelIterator = *aInsertPosition; mIsTopCompiler = false; } else { mStylesheet = new txStylesheet; NS_ENSURE_TRUE(mStylesheet, NS_ERROR_OUT_OF_MEMORY); rv = mStylesheet->init(); NS_ENSURE_SUCCESS(rv, rv); mToplevelIterator = txListIterator(&mStylesheet->mRootFrame->mToplevelItems); mToplevelIterator.next(); // go to the end of the list mIsTopCompiler = true; } mElementContext = new txElementContext(aStylesheetURI); NS_ENSURE_TRUE(mElementContext && mElementContext->mMappings, NS_ERROR_OUT_OF_MEMORY); // Push the "old" txElementContext rv = pushObject(0); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
NS_IMETHODIMP nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); nsRefPtr<nsEditorSpellCheck> kungFuDeathGrip = this; // The purpose of mUpdateDictionaryRunning is to avoid doing all of this if // UpdateCurrentDictionary's helper method DictionaryFetched, which calls us, // is on the stack. if (!mUpdateDictionaryRunning) { // Ignore pending dictionary fetchers by increasing this number. mDictionaryFetcherGroup++; nsDefaultStringComparator comparator; nsAutoString langCode; int32_t dashIdx = aDictionary.FindChar('-'); if (dashIdx != -1) { langCode.Assign(Substring(aDictionary, 0, dashIdx)); } else { langCode.Assign(aDictionary); } uint32_t flags = 0; mEditor->GetFlags(&flags); if (!(flags & nsIPlaintextEditor::eEditorMailMask)) { if (mPreferredLang.IsEmpty() || !nsStyleUtil::DashMatchCompare(mPreferredLang, langCode, comparator)) { // When user sets dictionary manually, we store this value associated // with editor url. StoreCurrentDictionary(mEditor, aDictionary); } else { // If user sets a dictionary matching (even partially), lang defined by // document, we consider content pref has been canceled, and we clear it. ClearCurrentDictionary(mEditor); } // Also store it in as a preference. It will be used as a default value // when everything else fails but we don't want this for mail composer // because it has spellchecked dictionary settings in Preferences. Preferences::SetString("spellchecker.dictionary", aDictionary); } } return mSpellChecker->SetCurrentDictionary(aDictionary); }
PRBool nsHTMLContentSerializer::IsJavaScript(nsIAtom* aAttrNameAtom, const nsAString& aValueString) { if (aAttrNameAtom == nsGkAtoms::href || aAttrNameAtom == nsGkAtoms::src) { static const char kJavaScript[] = "javascript"; PRInt32 pos = aValueString.FindChar(':'); if (pos < (PRInt32)(sizeof kJavaScript - 1)) return PR_FALSE; nsAutoString scheme(Substring(aValueString, 0, pos)); scheme.StripWhitespace(); if ((scheme.Length() == (sizeof kJavaScript - 1)) && scheme.EqualsIgnoreCase(kJavaScript)) return PR_TRUE; else return PR_FALSE; } return nsContentUtils::IsEventAttributeName(aAttrNameAtom, EventNameType_HTML); }
nsresult nsSMILTimedElement::SetBeginOrEndSpec(const nsAString& aSpec, PRBool aIsBegin) { nsRefPtr<nsSMILTimeValueSpec> spec; SMILTimeValueSpecList& timeSpecsList = aIsBegin ? mBeginSpecs : mEndSpecs; nsTArray<nsSMILInstanceTime>& instancesList = aIsBegin ? mBeginInstances : mEndInstances; timeSpecsList.Clear(); instancesList.Clear(); HardReset(); // XXX Need to take care of time dependents here PRInt32 start; PRInt32 end = -1; PRInt32 length; do { start = end + 1; end = aSpec.FindChar(';', start); length = (end == -1) ? -1 : end - start; spec = NS_NewSMILTimeValueSpec(this, aIsBegin, Substring(aSpec, start, length)); if (spec) timeSpecsList.AppendElement(spec); } while (end != -1 && spec); if (!spec) { timeSpecsList.Clear(); instancesList.Clear(); HardReset(); return NS_ERROR_FAILURE; } UpdateCurrentInterval(); return NS_OK; }
PRBool nsHTMLContentSerializer::IsJavaScript(nsIAtom* aAttrNameAtom, const nsAString& aValueString) { if (aAttrNameAtom == nsHTMLAtoms::href || aAttrNameAtom == nsHTMLAtoms::src) { static const char kJavaScript[] = "javascript"; PRInt32 pos = aValueString.FindChar(':'); if (pos < (PRInt32)(sizeof kJavaScript - 1)) return PR_FALSE; nsAutoString scheme(Substring(aValueString, 0, pos)); scheme.StripWhitespace(); if ((scheme.Length() == (sizeof kJavaScript - 1)) && scheme.EqualsIgnoreCase(kJavaScript)) return PR_TRUE; else return PR_FALSE; } PRBool result = (aAttrNameAtom == nsLayoutAtoms::onblur) || (aAttrNameAtom == nsLayoutAtoms::onchange) || (aAttrNameAtom == nsLayoutAtoms::onclick) || (aAttrNameAtom == nsLayoutAtoms::ondblclick) || (aAttrNameAtom == nsLayoutAtoms::onfocus) || (aAttrNameAtom == nsLayoutAtoms::onkeydown) || (aAttrNameAtom == nsLayoutAtoms::onkeypress) || (aAttrNameAtom == nsLayoutAtoms::onkeyup) || (aAttrNameAtom == nsLayoutAtoms::onload) || (aAttrNameAtom == nsLayoutAtoms::onmousedown) || (aAttrNameAtom == nsLayoutAtoms::onpageshow) || (aAttrNameAtom == nsLayoutAtoms::onpagehide) || (aAttrNameAtom == nsLayoutAtoms::onmousemove) || (aAttrNameAtom == nsLayoutAtoms::onmouseout) || (aAttrNameAtom == nsLayoutAtoms::onmouseover) || (aAttrNameAtom == nsLayoutAtoms::onmouseup) || (aAttrNameAtom == nsLayoutAtoms::onreset) || (aAttrNameAtom == nsLayoutAtoms::onselect) || (aAttrNameAtom == nsLayoutAtoms::onsubmit) || (aAttrNameAtom == nsLayoutAtoms::onunload) || (aAttrNameAtom == nsLayoutAtoms::onabort) || (aAttrNameAtom == nsLayoutAtoms::onerror) || (aAttrNameAtom == nsLayoutAtoms::onpaint) || (aAttrNameAtom == nsLayoutAtoms::onresize) || (aAttrNameAtom == nsLayoutAtoms::onscroll) || (aAttrNameAtom == nsLayoutAtoms::onbroadcast) || (aAttrNameAtom == nsLayoutAtoms::onclose) || (aAttrNameAtom == nsLayoutAtoms::oncontextmenu) || (aAttrNameAtom == nsLayoutAtoms::oncommand) || (aAttrNameAtom == nsLayoutAtoms::oncommandupdate) || (aAttrNameAtom == nsLayoutAtoms::ondragdrop) || (aAttrNameAtom == nsLayoutAtoms::ondragenter) || (aAttrNameAtom == nsLayoutAtoms::ondragexit) || (aAttrNameAtom == nsLayoutAtoms::ondraggesture) || (aAttrNameAtom == nsLayoutAtoms::ondragover) || (aAttrNameAtom == nsLayoutAtoms::oninput); return result; }
/** --------------------------------------------------- * Helper function - Returns either the name or sets the length to zero */ static nsresult GetAdjustedPrinterName(nsIPrintSettings* aPS, bool aUsePNP, nsAString& aPrinterName) { NS_ENSURE_ARG_POINTER(aPS); aPrinterName.Truncate(); if (!aUsePNP) return NS_OK; // Get the Printer Name from the PrintSettings // to use as a prefix for Pref Names char16_t* prtName = nullptr; nsresult rv = aPS->GetPrinterName(&prtName); NS_ENSURE_SUCCESS(rv, rv); aPrinterName = nsDependentString(prtName); // Convert any whitespaces, carriage returns or newlines to _ // The below algorithm is supposedly faster than using iterators NS_NAMED_LITERAL_STRING(replSubstr, "_"); const char* replaceStr = " \n\r"; int32_t x; for (x=0; x < (int32_t)strlen(replaceStr); x++) { char16_t uChar = replaceStr[x]; int32_t i = 0; while ((i = aPrinterName.FindChar(uChar, i)) != kNotFound) { aPrinterName.Replace(i, 1, replSubstr); i++; } } return NS_OK; }
void nsHTMLContentSerializer::AppendToStringConvertLF(const nsAString& aStr, nsAString& aOutputStr) { // Convert line-endings to mLineBreak PRUint32 start = 0; PRUint32 theLen = aStr.Length(); while (start < theLen) { PRInt32 eol = aStr.FindChar('\n', start); if (eol == kNotFound) { nsDependentSubstring dataSubstring(aStr, start, theLen - start); AppendToString(dataSubstring, aOutputStr); start = theLen; } else { nsDependentSubstring dataSubstring(aStr, start, eol - start); AppendToString(dataSubstring, aOutputStr); AppendToString(mLineBreak, aOutputStr); start = eol + 1; if (start == theLen) mColPos = 0; } } }
nsresult txExprParser::resolveQName(const nsAString& aQName, nsIAtom** aPrefix, txIParseContext* aContext, nsIAtom** aLocalName, int32_t& aNamespace, bool aIsNameTest) { aNamespace = kNameSpaceID_None; int32_t idx = aQName.FindChar(':'); if (idx > 0) { *aPrefix = NS_NewAtom(StringHead(aQName, (uint32_t)idx)).get(); if (!*aPrefix) { return NS_ERROR_OUT_OF_MEMORY; } *aLocalName = NS_NewAtom(Substring(aQName, (uint32_t)idx + 1, aQName.Length() - (idx + 1))).get(); if (!*aLocalName) { NS_RELEASE(*aPrefix); return NS_ERROR_OUT_OF_MEMORY; } return aContext->resolveNamespacePrefix(*aPrefix, aNamespace); } // the lexer dealt with idx == 0 *aPrefix = 0; if (aIsNameTest && aContext->caseInsensitiveNameTests()) { nsAutoString lcname; nsContentUtils::ASCIIToLower(aQName, lcname); *aLocalName = NS_NewAtom(lcname).get(); } else { *aLocalName = NS_NewAtom(aQName).get(); } if (!*aLocalName) { return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; }
NS_IMETHODIMP nsInternetCiter::Rewrap(const nsAString& aInString, PRUint32 aWrapCol, PRUint32 aFirstLineOffset, PRBool aRespectNewlines, nsAString& aOutString) { // There shouldn't be returns in this string, only dom newlines. // Check to make sure: #ifdef DEBUG PRInt32 cr = aInString.FindChar(PRUnichar('\r')); NS_ASSERTION((cr < 0), "Rewrap: CR in string gotten from DOM!\n"); #endif /* DEBUG */ aOutString.Truncate(); nsCOMPtr<nsILineBreaker> lineBreaker; nsILineBreakerFactory *lf; nsresult rv; rv = CallGetService(NS_LWBRK_CONTRACTID, &lf); if (NS_SUCCEEDED(rv)) { nsAutoString lbarg; lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); NS_RELEASE(lf); } // Loop over lines in the input string, rewrapping each one. PRUint32 length; PRUint32 posInString = 0; PRUint32 outStringCol = 0; PRUint32 citeLevel = 0; const nsPromiseFlatString &tString = PromiseFlatString(aInString); length = tString.Length(); #ifdef DEBUG_wrapping int loopcount = 0; #endif while (posInString < length) { #ifdef DEBUG_wrapping printf("Outer loop: '%s'\n", NS_LossyConvertUCS2toASCII(Substring(tString, posInString, length-posInString)).get()); printf("out string is now: '%s'\n", NS_LossyConvertUCS2toASCII(aOutString).get()); #endif // Get the new cite level here since we're at the beginning of a line PRUint32 newCiteLevel = 0; while (posInString < length && tString[posInString] == gt) { ++newCiteLevel; ++posInString; while (posInString < length && tString[posInString] == space) ++posInString; } if (posInString >= length) break; // Special case: if this is a blank line, maintain a blank line // (retain the original paragraph breaks) if (tString[posInString] == nl && !aOutString.IsEmpty()) { if (aOutString.Last() != nl) aOutString.Append(nl); AddCite(aOutString, newCiteLevel); aOutString.Append(nl); ++posInString; outStringCol = 0; continue; } // If the cite level has changed, then start a new line with the // new cite level (but if we're at the beginning of the string, // don't bother). if (newCiteLevel != citeLevel && posInString > newCiteLevel+1 && outStringCol != 0) { BreakLine(aOutString, outStringCol, 0); } citeLevel = newCiteLevel; // Prepend the quote level to the out string if appropriate if (outStringCol == 0) { AddCite(aOutString, citeLevel); outStringCol = citeLevel + (citeLevel ? 1 : 0); } // If it's not a cite, and we're not at the beginning of a line in // the output string, add a space to separate new text from the // previous text. else if (outStringCol > citeLevel) { aOutString.Append(space); ++outStringCol; } // find the next newline -- don't want to go farther than that PRInt32 nextNewline = tString.FindChar(nl, posInString); if (nextNewline < 0) nextNewline = length; // For now, don't wrap unquoted lines at all. // This is because the plaintext edit window has already wrapped them // by the time we get them for rewrap, yet when we call the line // breaker, it will refuse to break backwards, and we'll end up // with a line that's too long and gets displayed as a lone word // on a line by itself. Need special logic to detect this case // and break it ourselves without resorting to the line breaker. if (citeLevel == 0) { aOutString.Append(Substring(tString, posInString, nextNewline-posInString)); outStringCol += nextNewline - posInString; if (nextNewline != (PRInt32)length) { aOutString.Append(nl); outStringCol = 0; } posInString = nextNewline+1; continue; } // Otherwise we have to use the line breaker and loop // over this line of the input string to get all of it: while ((PRInt32)posInString < nextNewline) { #ifdef DEBUG_wrapping if (++loopcount > 1000) NS_ASSERTION(PR_FALSE, "possible infinite loop in nsInternetCiter\n"); printf("Inner loop: '%s'\n", NS_LossyConvertUCS2toASCII(Substring(tString, posInString, nextNewline-posInString)).get()); #endif // Skip over initial spaces: while ((PRInt32)posInString < nextNewline && nsCRT::IsAsciiSpace(tString[posInString])) ++posInString; // If this is a short line, just append it and continue: if (outStringCol + nextNewline - posInString <= aWrapCol-citeLevel-1) { // If this short line is the final one in the in string, // then we need to include the final newline, if any: if (nextNewline+1 == (PRInt32)length && tString[nextNewline-1] == nl) ++nextNewline; // Trim trailing spaces: PRInt32 lastRealChar = nextNewline; while ((PRUint32)lastRealChar > posInString && nsCRT::IsAsciiSpace(tString[lastRealChar-1])) --lastRealChar; aOutString += Substring(tString, posInString, lastRealChar - posInString); outStringCol += lastRealChar - posInString; posInString = nextNewline + 1; continue; } PRInt32 eol = posInString + aWrapCol - citeLevel - outStringCol; // eol is the prospective end of line. // We'll first look backwards from there for a place to break. // If it's already less than our current position, // then our line is already too long, so break now. if (eol <= (PRInt32)posInString) { BreakLine(aOutString, outStringCol, citeLevel); continue; // continue inner loop, with outStringCol now at bol } PRUint32 breakPt; rv = NS_ERROR_BASE; if (lineBreaker) { PRBool needMore; rv = lineBreaker->Prev(tString.get() + posInString, length - posInString, eol + 1 - posInString, &breakPt, &needMore); if (NS_FAILED(rv) || needMore) { // if we couldn't find a breakpoint looking backwards, // and we're not starting a new line, then end this line // and loop around again: if (outStringCol > citeLevel + 1) { BreakLine(aOutString, outStringCol, citeLevel); continue; // continue inner loop, with outStringCol now at bol } // Else try looking forwards: rv = lineBreaker->Next(tString.get() + posInString, length - posInString, eol - posInString, &breakPt, &needMore); if (needMore) rv = NS_ERROR_BASE; } } // If rv is okay, then breakPt is the place to break. // If we get out here and rv is set, something went wrong with line // breaker. Just break the line, hard. if (NS_FAILED(rv)) { #ifdef DEBUG_akkana printf("nsInternetCiter: LineBreaker not working -- breaking hard\n"); #endif breakPt = eol; } // Special case: maybe we should have wrapped last time. // If the first breakpoint here makes the current line too long, // then if we already have text on the current line, // break and loop around again. // If we're at the beginning of the current line, though, // don't force a break since the long word might be a url // and breaking it would make it unclickable on the other end. const int SLOP = 6; if (outStringCol + breakPt > aWrapCol + SLOP && outStringCol > citeLevel+1) { BreakLine(aOutString, outStringCol, citeLevel); continue; } nsAutoString sub (Substring(tString, posInString, breakPt)); // skip newlines or whitespace at the end of the string PRInt32 subend = sub.Length(); while (subend > 0 && IsSpace(sub[subend-1])) --subend; sub.Left(sub, subend); aOutString += sub; outStringCol += sub.Length(); // Advance past the whitespace which caused the wrap: posInString += breakPt; while (posInString < length && IsSpace(tString[posInString])) ++posInString; // Add a newline and the quote level to the out string if (posInString < length) // not for the last line, though BreakLine(aOutString, outStringCol, citeLevel); } // end inner loop within one line of aInString #ifdef DEBUG_wrapping printf("---------\nEnd inner loop: out string is now '%s'\n-----------\n", NS_LossyConvertUCS2toASCII(aOutString).get()); #endif } // end outer loop over lines of aInString #ifdef DEBUG_wrapping printf("Final out string is now: '%s'\n", NS_LossyConvertUCS2toASCII(aOutString).get()); #endif return NS_OK; }
bool SVGFragmentIdentifier::ProcessSVGViewSpec(const nsAString &aViewSpec, nsSVGSVGElement *root) { if (!IsMatchingParameter(aViewSpec, NS_LITERAL_STRING("svgView"))) { return false; } // SVGViewAttribute may occur in any order, but each type may only occur at most one time // in a correctly formed SVGViewSpec. // If we encounter any element more than once or get any syntax errors we're going to // return without updating the root element const nsAString *viewBoxParams = nsnull; const nsAString *preserveAspectRatioParams = nsnull; const nsAString *zoomAndPanParams = nsnull; // Each token is a SVGViewAttribute PRInt32 bracketPos = aViewSpec.FindChar('('); CharTokenizer<';'>tokenizer( Substring(aViewSpec, bracketPos + 1, aViewSpec.Length() - bracketPos - 2)); while (tokenizer.hasMoreTokens()) { nsAutoString token(tokenizer.nextToken()); bracketPos = token.FindChar('('); if (bracketPos < 1 || token.Last() != ')') { // invalid SVGViewAttribute syntax return false; } const nsAString ¶ms = Substring(token, bracketPos + 1, token.Length() - bracketPos - 2); if (IsMatchingParameter(token, NS_LITERAL_STRING("viewBox"))) { if (viewBoxParams) { return false; } viewBoxParams = ¶ms; } else if (IsMatchingParameter(token, NS_LITERAL_STRING("preserveAspectRatio"))) { if (preserveAspectRatioParams) { return false; } preserveAspectRatioParams = ¶ms; } else if (IsMatchingParameter(token, NS_LITERAL_STRING("zoomAndPan"))) { if (zoomAndPanParams) { return false; } zoomAndPanParams = ¶ms; } else { // We don't support transform or viewTarget currently return false; } } const nsSVGViewBoxRect *oldViewBoxPtr = root->GetViewBoxProperty(); if (viewBoxParams) { SaveOldViewBox(root); root->mViewBox.SetBaseValueString(*viewBoxParams, root); } else { RestoreOldViewBox(root); } const SVGPreserveAspectRatio *oldPARPtr = root->GetPreserveAspectRatioProperty(); if (preserveAspectRatioParams) { SaveOldPreserveAspectRatio(root); root->mPreserveAspectRatio.SetBaseValueString(*preserveAspectRatioParams, root); } else { RestoreOldPreserveAspectRatio(root); } const PRUint16 *oldZoomAndPanPtr = root->GetZoomAndPanProperty(); if (zoomAndPanParams) { SaveOldZoomAndPan(root); nsCOMPtr<nsIAtom> valAtom = do_GetAtom(*zoomAndPanParams); const nsSVGEnumMapping *mapping = root->sZoomAndPanMap; while (mapping->mKey) { if (valAtom == *(mapping->mKey)) { root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].SetBaseValue(mapping->mVal, root); break; } mapping++; } } else { RestoreOldZoomAndPan(root); } return true; }
bool SVGFragmentIdentifier::ProcessSVGViewSpec(const nsAString &aViewSpec, nsSVGSVGElement *root) { if (!IsMatchingParameter(aViewSpec, NS_LITERAL_STRING("svgView"))) { return false; } // SVGViewAttributes may occur in any order, but each type may only occur // at most one time in a correctly formed SVGViewSpec. // If we encounter any attribute more than once or get any syntax errors // we're going to return false and cancel any changes. bool viewBoxFound = false; bool preserveAspectRatioFound = false; bool transformFound = false; bool zoomAndPanFound = false; // Each token is a SVGViewAttribute int32_t bracketPos = aViewSpec.FindChar('('); uint32_t lengthOfViewSpec = aViewSpec.Length() - bracketPos - 2; nsCharSeparatedTokenizerTemplate<IgnoreWhitespace> tokenizer( Substring(aViewSpec, bracketPos + 1, lengthOfViewSpec), ';'); if (!tokenizer.hasMoreTokens()) { return false; } do { nsAutoString token(tokenizer.nextToken()); bracketPos = token.FindChar('('); if (bracketPos < 1 || token.Last() != ')') { // invalid SVGViewAttribute syntax return false; } const nsAString ¶ms = Substring(token, bracketPos + 1, token.Length() - bracketPos - 2); if (IsMatchingParameter(token, NS_LITERAL_STRING("viewBox"))) { if (viewBoxFound || NS_FAILED(root->mViewBox.SetBaseValueString( params, root, true))) { return false; } viewBoxFound = true; } else if (IsMatchingParameter(token, NS_LITERAL_STRING("preserveAspectRatio"))) { if (preserveAspectRatioFound || NS_FAILED(root->mPreserveAspectRatio.SetBaseValueString( params, root, true))) { return false; } preserveAspectRatioFound = true; } else if (IsMatchingParameter(token, NS_LITERAL_STRING("transform"))) { SVGAnimatedTransformList transforms; if (transformFound || NS_FAILED(transforms.SetBaseValueString(params))) { return false; } if (!root->mFragmentIdentifierTransform) { root->mFragmentIdentifierTransform = new gfxMatrix(); } *root->mFragmentIdentifierTransform = transforms.GetBaseValue().GetConsolidationMatrix(); root->InvalidateTransformNotifyFrame(); transformFound = true; } else if (IsMatchingParameter(token, NS_LITERAL_STRING("zoomAndPan"))) { if (zoomAndPanFound) { return false; } nsIAtom *valAtom = NS_GetStaticAtom(params); if (!valAtom) { return false; } const nsSVGEnumMapping *mapping = nsSVGSVGElement::sZoomAndPanMap; while (mapping->mKey) { if (valAtom == *(mapping->mKey)) { // If we've got a valid zoomAndPan value, then set it on our root element. if (NS_FAILED(root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].SetBaseValue( mapping->mVal, root))) { return false; } break; } mapping++; } if (!mapping->mKey) { // Unrecognised zoomAndPan value return false; } zoomAndPanFound = true; } else { // We don't support viewTarget currently return false; } } while (tokenizer.hasMoreTokens()); if (root->mUseCurrentView) { // A previous SVGViewSpec may have overridden some attributes. // If they are no longer overridden we need to restore the old values. if (!transformFound) { ClearTransform(root); } if (!viewBoxFound) { RestoreOldViewBox(root); } if (!preserveAspectRatioFound) { RestoreOldPreserveAspectRatio(root); } if (!zoomAndPanFound) { RestoreOldZoomAndPan(root); } } return true; }
nsresult InternetCiter::Rewrap(const nsAString& aInString, uint32_t aWrapCol, uint32_t aFirstLineOffset, bool aRespectNewlines, nsAString& aOutString) { // There shouldn't be returns in this string, only dom newlines. // Check to make sure: #ifdef DEBUG int32_t cr = aInString.FindChar(char16_t('\r')); NS_ASSERTION((cr < 0), "Rewrap: CR in string gotten from DOM!\n"); #endif /* DEBUG */ aOutString.Truncate(); nsresult rv; RefPtr<mozilla::intl::LineBreaker> lineBreaker = mozilla::intl::LineBreaker::Create(); MOZ_ASSERT(lineBreaker); // Loop over lines in the input string, rewrapping each one. uint32_t length; uint32_t posInString = 0; uint32_t outStringCol = 0; uint32_t citeLevel = 0; const nsPromiseFlatString &tString = PromiseFlatString(aInString); length = tString.Length(); while (posInString < length) { // Get the new cite level here since we're at the beginning of a line uint32_t newCiteLevel = 0; while (posInString < length && tString[posInString] == gt) { ++newCiteLevel; ++posInString; while (posInString < length && tString[posInString] == space) { ++posInString; } } if (posInString >= length) { break; } // Special case: if this is a blank line, maintain a blank line // (retain the original paragraph breaks) if (tString[posInString] == nl && !aOutString.IsEmpty()) { if (aOutString.Last() != nl) { aOutString.Append(nl); } AddCite(aOutString, newCiteLevel); aOutString.Append(nl); ++posInString; outStringCol = 0; continue; } // If the cite level has changed, then start a new line with the // new cite level (but if we're at the beginning of the string, // don't bother). if (newCiteLevel != citeLevel && posInString > newCiteLevel+1 && outStringCol) { BreakLine(aOutString, outStringCol, 0); } citeLevel = newCiteLevel; // Prepend the quote level to the out string if appropriate if (!outStringCol) { AddCite(aOutString, citeLevel); outStringCol = citeLevel + (citeLevel ? 1 : 0); } // If it's not a cite, and we're not at the beginning of a line in // the output string, add a space to separate new text from the // previous text. else if (outStringCol > citeLevel) { aOutString.Append(space); ++outStringCol; } // find the next newline -- don't want to go farther than that int32_t nextNewline = tString.FindChar(nl, posInString); if (nextNewline < 0) { nextNewline = length; } // For now, don't wrap unquoted lines at all. // This is because the plaintext edit window has already wrapped them // by the time we get them for rewrap, yet when we call the line // breaker, it will refuse to break backwards, and we'll end up // with a line that's too long and gets displayed as a lone word // on a line by itself. Need special logic to detect this case // and break it ourselves without resorting to the line breaker. if (!citeLevel) { aOutString.Append(Substring(tString, posInString, nextNewline-posInString)); outStringCol += nextNewline - posInString; if (nextNewline != (int32_t)length) { aOutString.Append(nl); outStringCol = 0; } posInString = nextNewline+1; continue; } // Otherwise we have to use the line breaker and loop // over this line of the input string to get all of it: while ((int32_t)posInString < nextNewline) { // Skip over initial spaces: while ((int32_t)posInString < nextNewline && nsCRT::IsAsciiSpace(tString[posInString])) { ++posInString; } // If this is a short line, just append it and continue: if (outStringCol + nextNewline - posInString <= aWrapCol-citeLevel-1) { // If this short line is the final one in the in string, // then we need to include the final newline, if any: if (nextNewline+1 == (int32_t)length && tString[nextNewline-1] == nl) { ++nextNewline; } // Trim trailing spaces: int32_t lastRealChar = nextNewline; while ((uint32_t)lastRealChar > posInString && nsCRT::IsAsciiSpace(tString[lastRealChar-1])) { --lastRealChar; } aOutString += Substring(tString, posInString, lastRealChar - posInString); outStringCol += lastRealChar - posInString; posInString = nextNewline + 1; continue; } int32_t eol = posInString + aWrapCol - citeLevel - outStringCol; // eol is the prospective end of line. // We'll first look backwards from there for a place to break. // If it's already less than our current position, // then our line is already too long, so break now. if (eol <= (int32_t)posInString) { BreakLine(aOutString, outStringCol, citeLevel); continue; // continue inner loop, with outStringCol now at bol } int32_t breakPt = 0; // XXX Why this uses NS_ERROR_"BASE"? rv = NS_ERROR_BASE; if (lineBreaker) { breakPt = lineBreaker->Prev(tString.get() + posInString, length - posInString, eol + 1 - posInString); if (breakPt == NS_LINEBREAKER_NEED_MORE_TEXT) { // if we couldn't find a breakpoint looking backwards, // and we're not starting a new line, then end this line // and loop around again: if (outStringCol > citeLevel + 1) { BreakLine(aOutString, outStringCol, citeLevel); continue; // continue inner loop, with outStringCol now at bol } // Else try looking forwards: breakPt = lineBreaker->Next(tString.get() + posInString, length - posInString, eol - posInString); rv = breakPt == NS_LINEBREAKER_NEED_MORE_TEXT ? NS_ERROR_BASE : NS_OK; } else { rv = NS_OK; } } // If rv is okay, then breakPt is the place to break. // If we get out here and rv is set, something went wrong with line // breaker. Just break the line, hard. if (NS_FAILED(rv)) { breakPt = eol; } // Special case: maybe we should have wrapped last time. // If the first breakpoint here makes the current line too long, // then if we already have text on the current line, // break and loop around again. // If we're at the beginning of the current line, though, // don't force a break since the long word might be a url // and breaking it would make it unclickable on the other end. const int SLOP = 6; if (outStringCol + breakPt > aWrapCol + SLOP && outStringCol > citeLevel+1) { BreakLine(aOutString, outStringCol, citeLevel); continue; } nsAutoString sub (Substring(tString, posInString, breakPt)); // skip newlines or whitespace at the end of the string int32_t subend = sub.Length(); while (subend > 0 && IsSpace(sub[subend-1])) { --subend; } sub.Left(sub, subend); aOutString += sub; outStringCol += sub.Length(); // Advance past the whitespace which caused the wrap: posInString += breakPt; while (posInString < length && IsSpace(tString[posInString])) { ++posInString; } // Add a newline and the quote level to the out string if (posInString < length) { // not for the last line, though BreakLine(aOutString, outStringCol, citeLevel); } } // end inner loop within one line of aInString } // end outer loop over lines of aInString return NS_OK; }