Clean up string usage in nsFont::EnumerateFamilies and nsCSSStyleSheet.cpp's ValueIncludes, although not all the other places to which this pattern was copied. b=235755 r+sr=roc

This commit is contained in:
dbaron%dbaron.org 2004-07-17 19:03:13 +00:00
Родитель 0ee5ed9f79
Коммит 45c8de80a6
3 изменённых файлов: 71 добавлений и 90 удалений

Просмотреть файл

@ -3224,34 +3224,31 @@ const nsString* RuleProcessorData::GetLang(void)
static const PRUnichar kNullCh = PRUnichar('\0');
static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue,
static PRBool ValueIncludes(const nsSubstring& aValueList,
const nsSubstring& aValue,
const nsStringComparator& aComparator)
{
nsAutoString valueList(aValueList);
const PRUnichar *p = aValueList.BeginReading(),
*p_end = aValueList.EndReading();
valueList.Append(kNullCh); // put an extra null at the end
while (p < p_end) {
// skip leading space
while (p != p_end && nsCRT::IsAsciiSpace(*p))
++p;
PRUnichar* start = valueList.BeginWriting();
PRUnichar* end = start;
const PRUnichar *val_start = p;
while (kNullCh != *start) {
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
start++;
}
end = start;
// look for space or end
while (p != p_end && !nsCRT::IsAsciiSpace(*p))
++p;
while ((kNullCh != *end) && (PR_FALSE == nsCRT::IsAsciiSpace(*end))) { // look for space or end
end++;
}
*end = kNullCh; // end string here
const PRUnichar *val_end = p;
if (start < end) {
if (aValue.Equals(nsDependentString(start, end), aComparator)) {
return PR_TRUE;
}
}
if (val_start < val_end &&
aValue.Equals(Substring(val_start, val_end), aComparator))
return PR_TRUE;
start = ++end;
++p; // we know the next character is not whitespace
}
return PR_FALSE;
}

Просмотреть файл

@ -135,66 +135,53 @@ const PRUnichar kComma = PRUnichar(',');
PRBool nsFont::EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const
{
PRBool running = PR_TRUE;
const PRUnichar *p, *p_end;
name.BeginReading(p);
name.EndReading(p_end);
nsAutoString family;
nsAutoString familyList; familyList.Assign(name); // copy to work buffer
nsAutoString familyStr;
while (p < p_end) {
while (nsCRT::IsAsciiSpace(*p))
if (++p == p_end)
return PR_TRUE;
familyList.Append(kNullCh); // put an extra null at the end
PRBool generic;
if (*p == kSingleQuote || *p == kDoubleQuote) {
// quoted font family
PRUnichar quoteMark = *p;
if (++p == p_end)
return PR_TRUE;
const PRUnichar *nameStart = p;
// XXX This code is evil...
PRUnichar* start = familyList.BeginWriting();
PRUnichar* end = start;
// XXX What about CSS character escapes?
while (*p != quoteMark)
if (++p == p_end)
return PR_TRUE;
while (running && (kNullCh != *start)) {
PRBool quoted = PR_FALSE;
PRBool generic = PR_FALSE;
family = Substring(nameStart, p);
generic = PR_FALSE;
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
start++;
while (++p != p_end && *p != kComma)
/* nothing */ ;
} else {
// unquoted font family
const PRUnichar *nameStart = p;
while (++p != p_end && *p != kComma)
/* nothing */ ;
family = Substring(nameStart, p);
family.CompressWhitespace(PR_FALSE, PR_TRUE);
generic = IsGenericFontFamily(family);
}
if ((kSingleQuote == *start) || (kDoubleQuote == *start)) { // quoted string
PRUnichar quote = *start++;
quoted = PR_TRUE;
end = start;
while (kNullCh != *end) {
if (quote == *end) { // found closing quote
*end++ = kNullCh; // end string here
while ((kNullCh != *end) && (kComma != *end)) { // keep going until comma
end++;
}
break;
}
end++;
}
}
else { // non-quoted string or ended
end = start;
if (!family.IsEmpty() && !(*aFunc)(family, generic, aData))
return PR_FALSE;
while ((kNullCh != *end) && (kComma != *end)) { // look for comma
end++;
}
*end = kNullCh; // end string here
}
familyStr = start;
if (PR_FALSE == quoted) {
familyStr.CompressWhitespace(PR_FALSE, PR_TRUE);
if (!familyStr.IsEmpty()) {
generic = IsGenericFontFamily(familyStr);
}
}
if (!familyStr.IsEmpty()) {
running = (*aFunc)(familyStr, generic, aData);
}
start = ++end;
++p; // may advance past p_end
}
return running;
return PR_TRUE;
}
static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)

Просмотреть файл

@ -3224,34 +3224,31 @@ const nsString* RuleProcessorData::GetLang(void)
static const PRUnichar kNullCh = PRUnichar('\0');
static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue,
static PRBool ValueIncludes(const nsSubstring& aValueList,
const nsSubstring& aValue,
const nsStringComparator& aComparator)
{
nsAutoString valueList(aValueList);
const PRUnichar *p = aValueList.BeginReading(),
*p_end = aValueList.EndReading();
valueList.Append(kNullCh); // put an extra null at the end
while (p < p_end) {
// skip leading space
while (p != p_end && nsCRT::IsAsciiSpace(*p))
++p;
PRUnichar* start = valueList.BeginWriting();
PRUnichar* end = start;
const PRUnichar *val_start = p;
while (kNullCh != *start) {
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
start++;
}
end = start;
// look for space or end
while (p != p_end && !nsCRT::IsAsciiSpace(*p))
++p;
while ((kNullCh != *end) && (PR_FALSE == nsCRT::IsAsciiSpace(*end))) { // look for space or end
end++;
}
*end = kNullCh; // end string here
const PRUnichar *val_end = p;
if (start < end) {
if (aValue.Equals(nsDependentString(start, end), aComparator)) {
return PR_TRUE;
}
}
if (val_start < val_end &&
aValue.Equals(Substring(val_start, val_end), aComparator))
return PR_TRUE;
start = ++end;
++p; // we know the next character is not whitespace
}
return PR_FALSE;
}