// static Modifiers UIEvent::ComputeModifierState(const nsAString& aModifiersList) { if (aModifiersList.IsEmpty()) { return 0; } // Be careful about the performance. If aModifiersList is too long, // parsing it needs too long time. // XXX Should we abort if aModifiersList is too long? Modifiers modifiers = 0; nsAString::const_iterator listStart, listEnd; aModifiersList.BeginReading(listStart); aModifiersList.EndReading(listEnd); for (uint32_t i = 0; i < ArrayLength(kPairs); i++) { nsAString::const_iterator start(listStart), end(listEnd); if (!FindInReadable(NS_ConvertASCIItoUTF16(kPairs[i].name), start, end)) { continue; } if ((start != listStart && !NS_IsAsciiWhitespace(*(--start))) || (end != listEnd && !NS_IsAsciiWhitespace(*(end)))) { continue; } modifiers |= kPairs[i].modifier; } return modifiers; }
NS_INTERFACE_MAP_END /* Implementation */ static nsresult GetValueFromString(const nsAString &aValueAsString, bool aPercentagesAllowed, float *aValue) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_DOM_SYNTAX_ERR; char *rest; *aValue = float(PR_strtod(str, &rest)); if (rest == str || !NS_finite(*aValue)) { return NS_ERROR_DOM_SYNTAX_ERR; } if (*rest == '%' && aPercentagesAllowed) { *aValue /= 100; ++rest; } if (*rest == '\0') { return NS_OK; } return NS_ERROR_DOM_SYNTAX_ERR; }
const nsDependentSubstring IDRefsIterator::NextID() { for (; mCurrIdx < mIDs.Length(); mCurrIdx++) { if (!NS_IsAsciiWhitespace(mIDs[mCurrIdx])) break; } if (mCurrIdx >= mIDs.Length()) return nsDependentSubstring(); nsAString::index_type idStartIdx = mCurrIdx; while (++mCurrIdx < mIDs.Length()) { if (NS_IsAsciiWhitespace(mIDs[mCurrIdx])) break; } return Substring(mIDs, idStartIdx, mCurrIdx++ - idStartIdx); }
nsresult nsSVGElement::ParseIntegerOptionalInteger(const nsAString& aValue, PRUint32 aIndex1, PRUint32 aIndex2) { NS_ConvertUTF16toUTF8 value(aValue); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_FAILURE; char *rest; PRInt32 x = strtol(str, &rest, 10); PRInt32 y = x; if (str == rest) { //first value was illformed return NS_ERROR_FAILURE; } if (*rest != '\0') { while (NS_IsAsciiWhitespace(*rest)) { ++rest; } if (*rest == ',') { ++rest; } y = strtol(rest, &rest, 10); if (*rest != '\0') { //second value was illformed or there was trailing content return NS_ERROR_FAILURE; } } IntegerAttributesInfo integerInfo = GetIntegerInfo(); integerInfo.mIntegers[aIndex1].SetBaseValue(x, this, PR_FALSE); integerInfo.mIntegers[aIndex2].SetBaseValue(y, this, PR_FALSE); return NS_OK; }
void CompressWhitespace(nsAString& aString) { char16_t* start; uint32_t len = NS_StringGetMutableData(aString, UINT32_MAX, &start); char16_t* end = start + len; char16_t* from = start; char16_t* to = start; // Skip any leading whitespace while (from < end && NS_IsAsciiWhitespace(*from)) { from++; } while (from < end) { char16_t theChar = *from++; if (NS_IsAsciiWhitespace(theChar)) { // We found a whitespace char, so skip over any more while (from < end && NS_IsAsciiWhitespace(*from)) { from++; } // Turn all whitespace into spaces theChar = ' '; } *to++ = theChar; } // Drop any trailing space if (to > start && to[-1] == ' ') { to--; } // Re-terminate the string *to = '\0'; // Set the new length aString.SetLength(to - start); }
nsresult nsSVGElement::ParseNumberOptionalNumber(const nsAString& aValue, PRUint32 aIndex1, PRUint32 aIndex2) { NS_ConvertUTF16toUTF8 value(aValue); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_FAILURE; char *rest; float x = float(PR_strtod(str, &rest)); float y = x; if (str == rest || !NS_FloatIsFinite(x)) { //first value was illformed return NS_ERROR_FAILURE; } if (*rest != '\0') { while (NS_IsAsciiWhitespace(*rest)) { ++rest; } if (*rest == ',') { ++rest; } y = float(PR_strtod(rest, &rest)); if (*rest != '\0' || !NS_FloatIsFinite(y)) { //second value was illformed or there was trailing content return NS_ERROR_FAILURE; } } NumberAttributesInfo numberInfo = GetNumberInfo(); numberInfo.mNumbers[aIndex1].SetBaseValue(x, this, PR_FALSE); numberInfo.mNumbers[aIndex2].SetBaseValue(y, this, PR_FALSE); return NS_OK; }
void CompressWhitespace(nsAString& aString) { aString.Trim(" \n\t\r"); PRUnichar *start; PRUint32 len = NS_StringGetMutableData(aString, PR_UINT32_MAX, &start); PRUnichar *end = start + len; for (PRUnichar *cur = start; cur < end; ++cur) { if (!NS_IsAsciiWhitespace(*cur)) continue; *cur = ' '; PRUnichar *wend; for (wend = cur + 1; wend < end && NS_IsAsciiWhitespace(*wend); ++wend) { // nothing to do but loop } if (wend == cur + 1) continue; PRUint32 wlen = wend - cur - 1; // fix "end" end -= wlen; // move everything forwards a bit for (PRUnichar *m = cur + 1; m < end; ++m) { *m = *(m + wlen); } } // re-terminate *end = '\0'; // Set the new length. aString.SetLength(end - start); }
static nsresult GetValueFromString(const nsAString &aValueAsString, float *aValue, PRUint16 *aUnitType) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_DOM_SYNTAX_ERR; char *rest; *aValue = float(PR_strtod(str, &rest)); if (rest != str && NS_FloatIsFinite(*aValue)) { *aUnitType = GetUnitTypeForString(rest); if (IsValidUnitType(*aUnitType)) { return NS_OK; } } return NS_ERROR_DOM_SYNTAX_ERR; }
NS_INTERFACE_MAP_END /* Implementation */ nsresult nsSVGNumber2::SetBaseValueString(const nsAString &aValueAsString, nsSVGElement *aSVGElement, PRBool aDoSetAttr) { NS_ConvertUTF16toUTF8 value(aValueAsString); const char *str = value.get(); if (NS_IsAsciiWhitespace(*str)) return NS_ERROR_FAILURE; char *rest; float val = float(PR_strtod(str, &rest)); if (rest == str || *rest != '\0') { return NS_ERROR_FAILURE; } mBaseVal = mAnimVal = val; return NS_OK; }