diff --git a/nel/include/nel/gui/css_selector.h b/nel/include/nel/gui/css_selector.h index ed04ba86d..3228869f3 100644 --- a/nel/include/nel/gui/css_selector.h +++ b/nel/include/nel/gui/css_selector.h @@ -96,6 +96,8 @@ namespace NLGUI // match An+B rule to child index (1 based) bool matchNth(sint childNr, sint a, sint b) const; + // match :lang(xx) + bool matchLang(const CHtmlElement &elm, const std::string &pseudo) const; // parse nth-child string to 'a' and 'b' components // :nth-child(odd) diff --git a/nel/src/gui/css_selector.cpp b/nel/src/gui/css_selector.cpp index 18d0375b0..dfc01b855 100644 --- a/nel/src/gui/css_selector.cpp +++ b/nel/src/gui/css_selector.cpp @@ -235,6 +235,11 @@ namespace NLGUI // 1st child should be '1' and not '0' if (!matchNth(elm.childIndex+1, a, b)) return false; } + else if (startsWith(PseudoClass[i], "lang(")) + { + std::string lang = PseudoClass[i].substr(5, PseudoClass[i].size() - 6); + if (lang.empty() || !matchLang(elm, lang)) return false; + } else { return false; @@ -324,6 +329,29 @@ namespace NLGUI } } + bool CCssSelector::matchLang(const CHtmlElement &elm, const std::string &pseudo) const + { + // TODO: does not support comma separated, or escaped/quoted/wildcard tags + std::string lang = toLowerAscii(elm.getInheritedLanguage()); + if (lang.empty() || pseudo.empty()) + return false; + + // lang = 'en', pseudo = 'en-US' + if (lang.size() < pseudo.size()) + return false; + + std::string selector = toLowerAscii(pseudo); + bool selectorHasRegion = selector.find("-") != std::string::npos; + bool langHasRegion = lang.find("-") != std::string::npos; + + // both are 'en', or 'en-US' type + if (langHasRegion == selectorHasRegion) + return lang == selector; + + // lang = 'en-US', selector = 'en' + return lang[selector.size()] == '-' && startsWith(lang, selector); + } + std::string CCssSelector::toString() const { std::string ret;