void SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle, nsAString& aType, nsAString& aMedia, bool* aIsScoped, bool* aIsAlternate) { *aIsAlternate = false; nsAutoString title; GetAttr(kNameSpaceID_None, nsGkAtoms::title, title); title.CompressWhitespace(); aTitle.Assign(title); GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia); // The SVG spec is formulated in terms of the CSS2 spec, // which specifies that media queries are case insensitive. nsContentUtils::ASCIIToLower(aMedia); GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType); if (aType.IsEmpty()) { aType.AssignLiteral("text/css"); } *aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped); return; }
NS_IMETHODIMP nsMathMLTokenFrame::Init(nsIContent* aContent, nsIFrame* aParent, nsIFrame* aPrevInFlow) { // leading and trailing whitespace doesn't count -- bug 15402 // brute force removal for people who do <mi> a </mi> instead of <mi>a</mi> // XXX the best fix is to skip these in nsTextFrame CompressWhitespace(aContent); // let the base class do its Init() return nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow); }
static bool test_compress_ws() { nsCStringContainer s; NS_CStringContainerInit(s); NS_CStringSetData(s, " \thello world\r \n"); CompressWhitespace(s); const char *d; NS_CStringGetData(s, &d); bool rv = !strcmp(d, "hello world"); if (!rv) printf("=> \"%s\"\n", d); NS_CStringContainerFinish(s); return rv; }
NS_IMETHODIMP sbTextPropertyInfo::MakeSearchable(const nsAString & aValue, nsAString & _retval) { nsresult rv; bool valid = PR_FALSE; _retval = aValue; CompressWhitespace(_retval); ToLowerCase(_retval); nsCOMPtr<sbIStringTransform> stringTransform = do_CreateInstance(SB_STRINGTRANSFORM_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsString outVal; rv = stringTransform->NormalizeString(EmptyString(), sbIStringTransform::TRANSFORM_IGNORE_NONSPACE, _retval, outVal); NS_ENSURE_SUCCESS(rv, rv); _retval = outVal; PRUint32 len = aValue.Length(); PR_Lock(mMinMaxLock); // If a minimum length is specified and is not respected there's nothing // we can do about it, so we reject it. if(mMinLen && len < mMinLen) { PR_Unlock(mMinMaxLock); _retval = EmptyString(); return NS_ERROR_INVALID_ARG; } // If a maximum length is specified and we exceed it, we cut the string to the // maximum length. if(mMaxLen && len > mMaxLen) { _retval.SetLength(mMaxLen); } PR_Unlock(mMinMaxLock); rv = Validate(_retval, &valid); if(!valid) { rv = NS_ERROR_FAILURE; _retval = EmptyString(); } return rv; }
int testCompressWhitespace() { int32_t ret = 0; // CompressWhitespace utility function nsString s; s.AssignLiteral(" "); CompressWhitespace(s); ret += CHECK(s.EqualsLiteral("")); s.AssignLiteral(" no more leading spaces"); CompressWhitespace(s); ret += CHECK(s.EqualsLiteral("no more leading spaces")); s.AssignLiteral("no more trailing spaces "); CompressWhitespace(s); ret += CHECK(s.EqualsLiteral("no more trailing spaces")); s.AssignLiteral(" hello one 2 three 45 "); CompressWhitespace(s); ret += CHECK(s.EqualsLiteral("hello one 2 three 45")); return ret; }
// text property info needs to compute local-specific collation data instead // of relying on the ancestor's default implementation (which just calls // MakeSearchable), so that proper sort order are achieved. NS_IMETHODIMP sbTextPropertyInfo::MakeSortable(const nsAString & aValue, nsAString & _retval) { // first compress whitespaces nsAutoString val; val = aValue; CompressWhitespace(val); ToLowerCase(val); nsresult rv; nsCOMPtr<sbIStringTransform> stringTransform = do_CreateInstance(SB_STRINGTRANSFORM_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsString outVal; // lone> note that if we ever decide to remove the non-alphanum chars from // more than the leading part of the string, we must still not remove those // chars from the entire string. Ie, we can only extend the filtering to the // trailing part of the string, but not the whole string. the reason for this // is that we do not want to remove the "," in "Beatles, The", or it will not // be recognized by the articles removal code since the pattern is "*, The". rv = stringTransform-> NormalizeString(EmptyString(), sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE | sbIStringTransform::TRANSFORM_IGNORE_LEADING | sbIStringTransform::TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS, val, outVal); NS_ENSURE_SUCCESS(rv, rv); // don't allow normalization to produce an empty sortable string if (!outVal.IsEmpty()) { val = outVal; } rv = stringTransform->RemoveArticles(val, EmptyString(), outVal); NS_ENSURE_SUCCESS(rv, rv); _retval = outVal; // all done return NS_OK; }
static bool test_compressws() { nsString check(NS_LITERAL_STRING(" \tTesting \n\t1\n 2 3\n ")); CompressWhitespace(check); return check.Equals(NS_LITERAL_STRING("Testing 1 2 3")); }
std::string CompressWhitespaceCopy(const std::string& str) { std::string temp(str); return CompressWhitespace(temp); }
NS_IMETHODIMP sbDatetimePropertyInfo::Format(const nsAString & aValue, nsAString & _retval) { PRInt32 timeType = 0; PRInt64 value = 0; NS_ConvertUTF16toUTF8 narrow(aValue); nsresult rv = GetTimeType(&timeType); NS_ENSURE_SUCCESS(rv, rv); if(PR_sscanf(narrow.get(), gsFmtRadix10, &value) != 1) { return NS_ERROR_INVALID_ARG; } { sbSimpleAutoLock lock(mMinMaxDateTimeLock); if(value < mMinDateTime || value > mMaxDateTime) { return NS_ERROR_INVALID_ARG; } } if(timeType != sbIDatetimePropertyInfo::TIMETYPE_TIMESTAMP) { nsAutoString out; sbSimpleAutoLock lockLocale(mAppLocaleLock); if(!mAppLocale) { nsCOMPtr<nsILocaleService> localeService = do_GetService("@mozilla.org/intl/nslocaleservice;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = localeService->GetApplicationLocale(getter_AddRefs(mAppLocale)); NS_ENSURE_SUCCESS(rv, rv); } sbSimpleAutoLock lockFormatter(mDateTimeFormatLock); if(!mDateTimeFormat) { mDateTimeFormat = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); } switch(mTimeType) { case sbIDatetimePropertyInfo::TIMETYPE_TIME: { PRExplodedTime explodedTime = {0}; PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime); rv = mDateTimeFormat->FormatPRExplodedTime(mAppLocale, kDateFormatNone, kTimeFormatSeconds, &explodedTime, out); } break; case sbIDatetimePropertyInfo::TIMETYPE_DATE: { PRExplodedTime explodedTime = {0}; PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime); rv = mDateTimeFormat->FormatPRExplodedTime(mAppLocale, kDateFormatLong, kTimeFormatNone, &explodedTime, out); } break; case sbIDatetimePropertyInfo::TIMETYPE_DATETIME: { PRExplodedTime explodedTime = {0}; PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime); rv = mDateTimeFormat->FormatPRExplodedTime(mAppLocale, kDateFormatShort, kTimeFormatNoSeconds, &explodedTime, out); } break; } NS_ENSURE_SUCCESS(rv, rv); _retval = out; } else { _retval = aValue; CompressWhitespace(_retval); } return NS_OK; }