FontFamilyValue.cpp [plain text]
#include "config.h"
#include "FontFamilyValue.h"
#include "PlatformString.h"
#include "RegularExpression.h"
namespace WebCore {
static bool isValidCSSIdentifier(const String& string)
{
unsigned length = string.length();
if (!length)
return false;
const UChar* characters = string.characters();
UChar c = characters[0];
if (!(c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c >= 0x80))
return false;
for (unsigned i = 1; i < length; ++i) {
c = characters[i];
if (!(c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c >= 0x80))
return false;
}
return true;
}
static String quoteStringIfNeeded(const String& string)
{
if (isValidCSSIdentifier(string))
return string;
String quotedString = string;
quotedString.replace('\\', "\\\\");
quotedString.replace('\'', "\\'");
return "'" + quotedString + "'";
}
FontFamilyValue::FontFamilyValue(const DeprecatedString& string)
: CSSPrimitiveValue(String(), CSS_STRING)
{
static const RegularExpression parenReg(" \\(.*\\)$");
static const RegularExpression braceReg(" \\[.*\\]$");
parsedFontName = string;
parsedFontName.replace(parenReg, "");
parsedFontName.replace(braceReg, "");
}
String FontFamilyValue::cssText() const
{
return quoteStringIfNeeded(parsedFontName);
}
}