static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) { if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = false; unsigned length = propertyName.length(); if (!length) return String(); StringBuilder builder; builder.reserveCapacity(length); unsigned i = 0; if (hasCSSPropertyNamePrefix(propertyName, "css")) i += 3; else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) { i += 5; if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = true; } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) { i += 3; if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = true; } else if (hasCSSPropertyNamePrefix(propertyName, "webkit") || hasCSSPropertyNamePrefix(propertyName, "khtml") || hasCSSPropertyNamePrefix(propertyName, "apple") || hasCSSPropertyNamePrefix(propertyName, "epub")) builder.append('-'); else { if (isASCIIUpper(propertyName.characters()[0])) return String(); } builder.append(toASCIILower(propertyName.characters()[i++])); for (; i < length; ++i) { UChar c = propertyName.characters()[i]; if (!isASCIIUpper(c)) builder.append(c); else builder.append(makeString('-', toASCIILower(c))); } return builder.toString(); }
// Check for a CSS prefix. // Passed prefix is all lowercase. // First character of the prefix within the property name may be upper or lowercase. // Other characters in the prefix within the property name must be lowercase. // The prefix within the property name must be followed by a capital letter. static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix) { #ifndef NDEBUG ASSERT(*prefix); for (const char* p = prefix; *p; ++p) ASSERT(isASCIILower(*p)); ASSERT(propertyName.length()); #endif if (toASCIILower(propertyName.characters()[0]) != prefix[0]) return false; unsigned length = propertyName.length(); for (unsigned i = 1; i < length; ++i) { if (!prefix[i]) return isASCIIUpper(propertyName.characters()[i]); if (propertyName.characters()[i] != prefix[i]) return false; } return false; }