// Returns true if the function can match the whole token (case insensitive) // incrementing pos on match, otherwise leaving pos unchanged. // Note: Might return pos == str.length() static inline bool skipToken(const String& str, unsigned& pos, const char* token) { unsigned len = str.length(); unsigned current = pos; while (current < len && *token) { if (toASCIILower(str[current]) != *token++) return false; ++current; } if (*token) return false; pos = current; return true; }
// This returns an AtomicString because attribute names are always stored // as AtomicString types in Element (see setAttribute()). static AtomicString convertPropertyNameToAttributeName(const String& name) { StringBuilder builder; builder.append("data-"); unsigned length = name.length(); for (unsigned i = 0; i < length; ++i) { UChar character = name[i]; if (isASCIIUpper(character)) { builder.append('-'); builder.append(toASCIILower(character)); } else builder.append(character); } return builder.toAtomicString(); }
// returns 0-11 (Jan-Dec); -1 on failure static int findMonth(const char* monthStr) { ASSERT(monthStr); char needle[4]; for (int i = 0; i < 3; ++i) { if (!*monthStr) return -1; needle[i] = static_cast<char>(toASCIILower(*monthStr++)); } needle[3] = '\0'; const char *haystack = "janfebmaraprmayjunjulaugsepoctnovdec"; const char *str = strstr(haystack, needle); if (str) { int position = static_cast<int>(str - haystack); if (position % 3 == 0) return position / 3; } return -1; }
static PropertyNamePrefix getCSSPropertyNamePrefix(const StringImpl& propertyName) { ASSERT(propertyName.length()); // First character of the prefix within the property name may be upper or lowercase. UChar firstChar = toASCIILower(propertyName[0]); switch (firstChar) { #if ENABLE(LEGACY_CSS_VENDOR_PREFIXES) case 'a': if (RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled() && matchesCSSPropertyNamePrefix(propertyName, "apple")) return PropertyNamePrefixApple; break; #endif case 'c': if (matchesCSSPropertyNamePrefix(propertyName, "css")) return PropertyNamePrefixCSS; break; #if ENABLE(LEGACY_CSS_VENDOR_PREFIXES) case 'k': if (RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled() && matchesCSSPropertyNamePrefix(propertyName, "khtml")) return PropertyNamePrefixKHTML; break; #endif case 'e': if (matchesCSSPropertyNamePrefix(propertyName, "epub")) return PropertyNamePrefixEpub; break; case 'p': if (matchesCSSPropertyNamePrefix(propertyName, "pos")) return PropertyNamePrefixPos; if (matchesCSSPropertyNamePrefix(propertyName, "pixel")) return PropertyNamePrefixPixel; break; case 'w': if (matchesCSSPropertyNamePrefix(propertyName, "webkit")) return PropertyNamePrefixWebKit; break; default: break; } return PropertyNamePrefixNone; }
// 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.size()); #endif if (toASCIILower(propertyName.data()[0]) != prefix[0]) return false; unsigned length = propertyName.size(); for (unsigned i = 1; i < length; ++i) { if (!prefix[i]) return isASCIIUpper(propertyName.data()[i]); if (propertyName.data()[i] != prefix[i]) return false; } return false; }
static String convertPropertyNameToAttributeName(const String& name) { Vector<UChar> newStringBuffer; newStringBuffer.append('d'); newStringBuffer.append('a'); newStringBuffer.append('t'); newStringBuffer.append('a'); newStringBuffer.append('-'); const UChar* characters = name.characters(); unsigned length = name.length(); for (unsigned i = 0; i < length; ++i) { if (isASCIIUpper(characters[i])) { newStringBuffer.append('-'); newStringBuffer.append(toASCIILower(characters[i])); } else newStringBuffer.append(characters[i]); } return String::adopt(newStringBuffer); }
static PropertyNamePrefix getCSSPropertyNamePrefix(const StringImpl& propertyName) { ASSERT(propertyName.length()); // First character of the prefix within the property name may be upper or lowercase. UChar firstChar = toASCIILower(propertyName[0]); switch (firstChar) { case 'a': if (matchesCSSPropertyNamePrefix(propertyName, "apple")) return PropertyNamePrefixApple; break; case 'c': if (matchesCSSPropertyNamePrefix(propertyName, "css")) return PropertyNamePrefixCSS; break; case 'k': if (matchesCSSPropertyNamePrefix(propertyName, "khtml")) return PropertyNamePrefixKHTML; break; case 'e': if (matchesCSSPropertyNamePrefix(propertyName, "epub")) return PropertyNamePrefixEpub; break; case 'p': if (matchesCSSPropertyNamePrefix(propertyName, "pos")) return PropertyNamePrefixPos; if (matchesCSSPropertyNamePrefix(propertyName, "pixel")) return PropertyNamePrefixPixel; break; case 'w': if (matchesCSSPropertyNamePrefix(propertyName, "webkit")) return PropertyNamePrefixWebKit; break; default: break; } return PropertyNamePrefixNone; }
static CSSPropertyInfo cssPropertyIDForJSCSSPropertyName(PropertyName propertyName) { CSSPropertyInfo propertyInfo = {CSSPropertyInvalid, false}; bool hadPixelOrPosPrefix = false; StringImpl* propertyNameString = propertyName.publicName(); if (!propertyNameString) return propertyInfo; unsigned length = propertyNameString->length(); if (!length) return propertyInfo; String stringForCache = String(propertyNameString); typedef HashMap<String, CSSPropertyInfo> CSSPropertyInfoMap; static NeverDestroyed<CSSPropertyInfoMap> propertyInfoCache; propertyInfo = propertyInfoCache.get().get(stringForCache); if (propertyInfo.propertyID) return propertyInfo; const size_t bufferSize = maxCSSPropertyNameLength + 1; char buffer[bufferSize]; char* bufferPtr = buffer; const char* name = bufferPtr; unsigned i = 0; // Prefixes CSS, Pixel, Pos are ignored. // Prefixes Apple, KHTML and Webkit are transposed to "-webkit-". // The prefix "Epub" becomes "-epub-". switch (getCSSPropertyNamePrefix(*propertyNameString)) { case PropertyNamePrefixNone: if (isASCIIUpper((*propertyNameString)[0])) return propertyInfo; break; case PropertyNamePrefixCSS: i += 3; break; case PropertyNamePrefixPixel: i += 5; hadPixelOrPosPrefix = true; break; case PropertyNamePrefixPos: i += 3; hadPixelOrPosPrefix = true; break; #if ENABLE(LEGACY_CSS_VENDOR_PREFIXES) case PropertyNamePrefixApple: case PropertyNamePrefixKHTML: ASSERT(RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled()); writeWebKitPrefix(bufferPtr); i += 5; break; #endif case PropertyNamePrefixEpub: writeEpubPrefix(bufferPtr); i += 4; break; case PropertyNamePrefixWebKit: writeWebKitPrefix(bufferPtr); i += 6; break; } *bufferPtr++ = toASCIILower((*propertyNameString)[i++]); char* bufferEnd = buffer + bufferSize; char* stringEnd = bufferEnd - 1; size_t bufferSizeLeft = stringEnd - bufferPtr; size_t propertySizeLeft = length - i; if (propertySizeLeft > bufferSizeLeft) return propertyInfo; for (; i < length; ++i) { UChar c = (*propertyNameString)[i]; if (!c || c >= 0x7F) return propertyInfo; // illegal character if (isASCIIUpper(c)) { size_t bufferSizeLeft = stringEnd - bufferPtr; size_t propertySizeLeft = length - i + 1; if (propertySizeLeft > bufferSizeLeft) return propertyInfo; *bufferPtr++ = '-'; *bufferPtr++ = toASCIILower(c); } else *bufferPtr++ = c; ASSERT_WITH_SECURITY_IMPLICATION(bufferPtr < bufferEnd); } ASSERT_WITH_SECURITY_IMPLICATION(bufferPtr < bufferEnd); *bufferPtr = '\0'; unsigned outputLength = bufferPtr - buffer; #if PLATFORM(IOS) cssPropertyNameIOSAliasing(buffer, name, outputLength); #endif const Property* hashTableEntry = findProperty(name, outputLength); int propertyID = hashTableEntry ? hashTableEntry->id : 0; if (propertyID) { propertyInfo.hadPixelOrPosPrefix = hadPixelOrPosPrefix; propertyInfo.propertyID = static_cast<CSSPropertyID>(propertyID); propertyInfoCache.get().add(stringForCache, propertyInfo); } return propertyInfo; }
static const QuotesForLanguage* quotesForLanguage(const String& language) { // Table of quotes from http://www.whatwg.org/specs/web-apps/current-work/multipage/rendering.html#quotes static const QuotesForLanguage quoteTable[] = { { "af", 0x201c, 0x201d, 0x2018, 0x2019 }, { "agq", 0x201e, 0x201d, 0x201a, 0x2019 }, { "ak", 0x201c, 0x201d, 0x2018, 0x2019 }, { "am", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "ar", 0x201d, 0x201c, 0x2019, 0x2018 }, { "asa", 0x201c, 0x201d, 0x2018, 0x2019 }, { "az-cyrl", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "bas", 0x00ab, 0x00bb, 0x201e, 0x201c }, { "bem", 0x201c, 0x201d, 0x2018, 0x2019 }, { "bez", 0x201c, 0x201d, 0x2018, 0x2019 }, { "bg", 0x201e, 0x201c, 0x201a, 0x2018 }, { "bm", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "bn", 0x201c, 0x201d, 0x2018, 0x2019 }, { "br", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "brx", 0x201c, 0x201d, 0x2018, 0x2019 }, { "bs-cyrl", 0x201e, 0x201c, 0x201a, 0x2018 }, { "ca", 0x201c, 0x201d, 0x00ab, 0x00bb }, { "cgg", 0x201c, 0x201d, 0x2018, 0x2019 }, { "chr", 0x201c, 0x201d, 0x2018, 0x2019 }, { "cs", 0x201e, 0x201c, 0x201a, 0x2018 }, { "da", 0x201c, 0x201d, 0x2018, 0x2019 }, { "dav", 0x201c, 0x201d, 0x2018, 0x2019 }, { "de", 0x201e, 0x201c, 0x201a, 0x2018 }, { "de-ch", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "dje", 0x201c, 0x201d, 0x2018, 0x2019 }, { "dua", 0x00ab, 0x00bb, 0x2018, 0x2019 }, { "dyo", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "dz", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ebu", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ee", 0x201c, 0x201d, 0x2018, 0x2019 }, { "el", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "en", 0x201c, 0x201d, 0x2018, 0x2019 }, { "en-gb", 0x201c, 0x201d, 0x2018, 0x2019 }, { "es", 0x201c, 0x201d, 0x00ab, 0x00bb }, { "et", 0x201e, 0x201c, 0x201a, 0x2018 }, { "eu", 0x201c, 0x201d, 0x00ab, 0x00bb }, { "ewo", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "fa", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "ff", 0x201e, 0x201d, 0x201a, 0x2019 }, { "fi", 0x201d, 0x201d, 0x2019, 0x2019 }, { "fr", 0x00ab, 0x00bb, 0x00ab, 0x00bb }, { "fr-ca", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "fr-ch", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "gsw", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "gu", 0x201c, 0x201d, 0x2018, 0x2019 }, { "guz", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ha", 0x201c, 0x201d, 0x2018, 0x2019 }, { "he", 0x0022, 0x0022, 0x0027, 0x0027 }, { "hi", 0x201c, 0x201d, 0x2018, 0x2019 }, { "hr", 0x201e, 0x201c, 0x201a, 0x2018 }, { "hu", 0x201e, 0x201d, 0x00bb, 0x00ab }, { "id", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ig", 0x201c, 0x201d, 0x2018, 0x2019 }, { "it", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "ja", 0x300c, 0x300d, 0x300e, 0x300f }, { "jgo", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "jmc", 0x201c, 0x201d, 0x2018, 0x2019 }, { "kab", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "kam", 0x201c, 0x201d, 0x2018, 0x2019 }, { "kde", 0x201c, 0x201d, 0x2018, 0x2019 }, { "kea", 0x201c, 0x201d, 0x2018, 0x2019 }, { "khq", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ki", 0x201c, 0x201d, 0x2018, 0x2019 }, { "kkj", 0x00ab, 0x00bb, 0x2039, 0x203a }, { "kln", 0x201c, 0x201d, 0x2018, 0x2019 }, { "km", 0x201c, 0x201d, 0x2018, 0x2019 }, { "kn", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ko", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ksb", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ksf", 0x00ab, 0x00bb, 0x2018, 0x2019 }, { "lag", 0x201d, 0x201d, 0x2019, 0x2019 }, { "lg", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ln", 0x201c, 0x201d, 0x2018, 0x2019 }, { "lo", 0x201c, 0x201d, 0x2018, 0x2019 }, { "lt", 0x201e, 0x201c, 0x201e, 0x201c }, { "lu", 0x201c, 0x201d, 0x2018, 0x2019 }, { "luo", 0x201c, 0x201d, 0x2018, 0x2019 }, { "luy", 0x201e, 0x201c, 0x201a, 0x2018 }, { "lv", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mas", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mer", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mfe", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mg", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "mgo", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mk", 0x201e, 0x201c, 0x201a, 0x2018 }, { "ml", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mr", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ms", 0x201c, 0x201d, 0x2018, 0x2019 }, { "mua", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "my", 0x201c, 0x201d, 0x2018, 0x2019 }, { "naq", 0x201c, 0x201d, 0x2018, 0x2019 }, { "nb", 0x00ab, 0x00bb, 0x2018, 0x2019 }, { "nd", 0x201c, 0x201d, 0x2018, 0x2019 }, { "nl", 0x201c, 0x201d, 0x2018, 0x2019 }, { "nmg", 0x201e, 0x201d, 0x00ab, 0x00bb }, { "nn", 0x00ab, 0x00bb, 0x2018, 0x2019 }, { "nnh", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "nus", 0x201c, 0x201d, 0x2018, 0x2019 }, { "nyn", 0x201c, 0x201d, 0x2018, 0x2019 }, { "pl", 0x201e, 0x201d, 0x00ab, 0x00bb }, { "pt", 0x201c, 0x201d, 0x2018, 0x2019 }, { "pt-pt", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "rn", 0x201d, 0x201d, 0x2019, 0x2019 }, { "ro", 0x201e, 0x201d, 0x00ab, 0x00bb }, { "rof", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ru", 0x00ab, 0x00bb, 0x201e, 0x201c }, { "rw", 0x00ab, 0x00bb, 0x2018, 0x2019 }, { "rwk", 0x201c, 0x201d, 0x2018, 0x2019 }, { "saq", 0x201c, 0x201d, 0x2018, 0x2019 }, { "sbp", 0x201c, 0x201d, 0x2018, 0x2019 }, { "seh", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ses", 0x201c, 0x201d, 0x2018, 0x2019 }, { "sg", 0x00ab, 0x00bb, 0x201c, 0x201d }, { "shi", 0x00ab, 0x00bb, 0x201e, 0x201d }, { "shi-tfng", 0x00ab, 0x00bb, 0x201e, 0x201d }, { "si", 0x201c, 0x201d, 0x2018, 0x2019 }, { "sk", 0x201e, 0x201c, 0x201a, 0x2018 }, { "sl", 0x201e, 0x201c, 0x201a, 0x2018 }, { "sn", 0x201d, 0x201d, 0x2019, 0x2019 }, { "so", 0x201c, 0x201d, 0x2018, 0x2019 }, { "sq", 0x201e, 0x201c, 0x201a, 0x2018 }, { "sr", 0x201e, 0x201c, 0x201a, 0x2018 }, { "sr-latn", 0x201e, 0x201c, 0x201a, 0x2018 }, { "sv", 0x201d, 0x201d, 0x2019, 0x2019 }, { "sw", 0x201c, 0x201d, 0x2018, 0x2019 }, { "swc", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ta", 0x201c, 0x201d, 0x2018, 0x2019 }, { "te", 0x201c, 0x201d, 0x2018, 0x2019 }, { "teo", 0x201c, 0x201d, 0x2018, 0x2019 }, { "th", 0x201c, 0x201d, 0x2018, 0x2019 }, { "ti-er", 0x2018, 0x2019, 0x201c, 0x201d }, { "to", 0x201c, 0x201d, 0x2018, 0x2019 }, { "tr", 0x201c, 0x201d, 0x2018, 0x2019 }, { "twq", 0x201c, 0x201d, 0x2018, 0x2019 }, { "tzm", 0x201c, 0x201d, 0x2018, 0x2019 }, { "uk", 0x00ab, 0x00bb, 0x201e, 0x201c }, { "ur", 0x201d, 0x201c, 0x2019, 0x2018 }, { "vai", 0x201c, 0x201d, 0x2018, 0x2019 }, { "vai-latn", 0x201c, 0x201d, 0x2018, 0x2019 }, { "vi", 0x201c, 0x201d, 0x2018, 0x2019 }, { "vun", 0x201c, 0x201d, 0x2018, 0x2019 }, { "xh", 0x2018, 0x2019, 0x201c, 0x201d }, { "xog", 0x201c, 0x201d, 0x2018, 0x2019 }, { "yav", 0x00ab, 0x00bb, 0x00ab, 0x00bb }, { "yo", 0x201c, 0x201d, 0x2018, 0x2019 }, { "zh", 0x201c, 0x201d, 0x2018, 0x2019 }, { "zh-hant", 0x300c, 0x300d, 0x300e, 0x300f }, { "zu", 0x201c, 0x201d, 0x2018, 0x2019 }, }; const unsigned maxLanguageLength = 8; #if !ASSERT_DISABLED // One time check that the table meets the constraints that the code below relies on. static bool didOneTimeCheck = false; if (!didOneTimeCheck) { didOneTimeCheck = true; checkNumberOfDistinctQuoteCharacters(quotationMark); checkNumberOfDistinctQuoteCharacters(apostrophe); for (unsigned i = 0; i < WTF_ARRAY_LENGTH(quoteTable); ++i) { ASSERT(strlen(quoteTable[i].language) <= maxLanguageLength); if (i) ASSERT(strcmp(quoteTable[i - 1].language, quoteTable[i].language) < 0); for (unsigned j = 0; UChar character = quoteTable[i].language[j]; ++j) ASSERT(isASCIILower(character) || character == '-'); checkNumberOfDistinctQuoteCharacters(quoteTable[i].open1); checkNumberOfDistinctQuoteCharacters(quoteTable[i].close1); checkNumberOfDistinctQuoteCharacters(quoteTable[i].open2); checkNumberOfDistinctQuoteCharacters(quoteTable[i].close2); } } #endif unsigned length = language.length(); if (!length || length > maxLanguageLength) return 0; char languageKeyBuffer[maxLanguageLength + 1]; for (unsigned i = 0; i < length; ++i) { UChar character = toASCIILower(language[i]); if (!(isASCIILower(character) || character == '-')) return 0; languageKeyBuffer[i] = static_cast<char>(character); } languageKeyBuffer[length] = 0; QuotesForLanguage languageKey = { languageKeyBuffer, 0, 0, 0, 0 }; return static_cast<const QuotesForLanguage*>(bsearch(&languageKey, quoteTable, WTF_ARRAY_LENGTH(quoteTable), sizeof(quoteTable[0]), quoteTableLanguageComparisonFunction)); }
CSSPrimitiveValue::UnitTypes cssPrimitiveValueUnitFromTrie(const CharacterType* data, unsigned length) { ASSERT(data); ASSERT(length); switch (length) { case 1: switch (toASCIILower(data[0])) { case 's': return CSSPrimitiveValue::UnitTypes::CSS_S; } break; case 2: switch (toASCIILower(data[0])) { case 'c': switch (toASCIILower(data[1])) { case 'h': return CSSPrimitiveValue::UnitTypes::CSS_CHS; case 'm': return CSSPrimitiveValue::UnitTypes::CSS_CM; } break; case 'e': switch (toASCIILower(data[1])) { case 'm': return CSSPrimitiveValue::UnitTypes::CSS_EMS; case 'x': return CSSPrimitiveValue::UnitTypes::CSS_EXS; } break; case 'f': if (toASCIILower(data[1]) == 'r') return CSSPrimitiveValue::UnitTypes::CSS_FR; break; case 'h': if (toASCIILower(data[1]) == 'z') return CSSPrimitiveValue::UnitTypes::CSS_HZ; break; case 'i': if (toASCIILower(data[1]) == 'n') return CSSPrimitiveValue::UnitTypes::CSS_IN; break; case 'm': switch (toASCIILower(data[1])) { case 'm': return CSSPrimitiveValue::UnitTypes::CSS_MM; case 's': return CSSPrimitiveValue::UnitTypes::CSS_MS; } break; case 'p': switch (toASCIILower(data[1])) { case 'c': return CSSPrimitiveValue::UnitTypes::CSS_PC; case 't': return CSSPrimitiveValue::UnitTypes::CSS_PT; case 'x': return CSSPrimitiveValue::UnitTypes::CSS_PX; } break; case 'v': switch (toASCIILower(data[1])) { case 'h': return CSSPrimitiveValue::UnitTypes::CSS_VH; case 'w': return CSSPrimitiveValue::UnitTypes::CSS_VW; } break; } break; case 3: switch (toASCIILower(data[0])) { case 'd': switch (toASCIILower(data[1])) { case 'e': if (toASCIILower(data[2]) == 'g') return CSSPrimitiveValue::UnitTypes::CSS_DEG; break; case 'p': if (toASCIILower(data[2]) == 'i') return CSSPrimitiveValue::UnitTypes::CSS_DPI; break; } break; case 'k': if (toASCIILower(data[1]) == 'h' && toASCIILower(data[2]) == 'z') return CSSPrimitiveValue::UnitTypes::CSS_KHZ; break; case 'r': switch (toASCIILower(data[1])) { case 'a': if (toASCIILower(data[2]) == 'd') return CSSPrimitiveValue::UnitTypes::CSS_RAD; break; case 'e': if (toASCIILower(data[2]) == 'm') return CSSPrimitiveValue::UnitTypes::CSS_REMS; break; } break; } break; case 4: switch (toASCIILower(data[0])) { case 'd': switch (toASCIILower(data[1])) { case 'p': switch (toASCIILower(data[2])) { case 'c': if (toASCIILower(data[3]) == 'm') return CSSPrimitiveValue::UnitTypes::CSS_DPCM; break; case 'p': if (toASCIILower(data[3]) == 'x') return CSSPrimitiveValue::UnitTypes::CSS_DPPX; break; } break; } break; case 'g': if (toASCIILower(data[1]) == 'r' && toASCIILower(data[2]) == 'a' && toASCIILower(data[3]) == 'd') return CSSPrimitiveValue::UnitTypes::CSS_GRAD; break; case 't': if (toASCIILower(data[1]) == 'u' && toASCIILower(data[2]) == 'r' && toASCIILower(data[3]) == 'n') return CSSPrimitiveValue::UnitTypes::CSS_TURN; break; case 'v': switch (toASCIILower(data[1])) { case 'm': switch (toASCIILower(data[2])) { case 'a': if (toASCIILower(data[3]) == 'x') return CSSPrimitiveValue::UnitTypes::CSS_VMAX; break; case 'i': if (toASCIILower(data[3]) == 'n') return CSSPrimitiveValue::UnitTypes::CSS_VMIN; break; } break; } break; } break; case 5: switch (toASCIILower(data[0])) { case '_': if (toASCIILower(data[1]) == '_' && toASCIILower(data[2]) == 'q' && toASCIILower(data[3]) == 'e' && toASCIILower(data[4]) == 'm') return CSSPrimitiveValue::UnitTypes::CSS_QUIRKY_EMS; break; } break; } return CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN; }
static PassRefPtrWillBeRawPtr<CSSFunctionValue> parseSimpleTransformValue(CharType*& pos, CharType* end) { static const int shortestValidTransformStringLength = 12; if (end - pos < shortestValidTransformStringLength) return nullptr; const bool isTranslate = toASCIILower(pos[0]) == 't' && toASCIILower(pos[1]) == 'r' && toASCIILower(pos[2]) == 'a' && toASCIILower(pos[3]) == 'n' && toASCIILower(pos[4]) == 's' && toASCIILower(pos[5]) == 'l' && toASCIILower(pos[6]) == 'a' && toASCIILower(pos[7]) == 't' && toASCIILower(pos[8]) == 'e'; if (isTranslate) { CSSValueID transformType; unsigned expectedArgumentCount = 1; unsigned argumentStart = 11; CharType c9 = toASCIILower(pos[9]); if (c9 == 'x' && pos[10] == '(') { transformType = CSSValueTranslateX; } else if (c9 == 'y' && pos[10] == '(') { transformType = CSSValueTranslateY; } else if (c9 == 'z' && pos[10] == '(') { transformType = CSSValueTranslateZ; } else if (c9 == '(') { transformType = CSSValueTranslate; expectedArgumentCount = 2; argumentStart = 10; } else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(') { transformType = CSSValueTranslate3d; expectedArgumentCount = 3; argumentStart = 12; } else { return nullptr; } pos += argumentStart; RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(transformType); if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, transformValue.get())) return nullptr; return transformValue.release(); } const bool isMatrix3d = toASCIILower(pos[0]) == 'm' && toASCIILower(pos[1]) == 'a' && toASCIILower(pos[2]) == 't' && toASCIILower(pos[3]) == 'r' && toASCIILower(pos[4]) == 'i' && toASCIILower(pos[5]) == 'x' && pos[6] == '3' && toASCIILower(pos[7]) == 'd' && pos[8] == '('; if (isMatrix3d) { pos += 9; RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSValueMatrix3d); if (!parseTransformNumberArguments(pos, end, 16, transformValue.get())) return nullptr; return transformValue.release(); } const bool isScale3d = toASCIILower(pos[0]) == 's' && toASCIILower(pos[1]) == 'c' && toASCIILower(pos[2]) == 'a' && toASCIILower(pos[3]) == 'l' && toASCIILower(pos[4]) == 'e' && pos[5] == '3' && toASCIILower(pos[6]) == 'd' && pos[7] == '('; if (isScale3d) { pos += 8; RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSValueScale3d); if (!parseTransformNumberArguments(pos, end, 3, transformValue.get())) return nullptr; return transformValue.release(); } return nullptr; }
static String keyTextForNixKeyEvent(const NIXKeyEvent& event) { if (event.text) return String::fromUTF8(event.text); int keycode = static_cast<int>(event.key); if (isASCIIPrintable(keycode)) return String::format("%c", event.shouldUseUpperCase ? toASCIIUpper(keycode) : toASCIILower(keycode)); switch (event.key) { case kNIXKeyEventKey_Tab: case kNIXKeyEventKey_Backtab: return "\t"; case kNIXKeyEventKey_Enter: case kNIXKeyEventKey_Return: return "\r"; default: break; } return ""; }
inline static void toASCIILower(UChar* src, int32_t srcLen) { for(int32_t i=0; i<srcLen; i++) { src[i] = toASCIILower(src[i]); } }