MCPcopy Create free account
hub / github.com/SpartanJ/eepp / isColorStringT

Method isColorStringT

src/eepp/system/color.cpp:719–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

717
718template <AllowedFunctionString StringType>
719bool Color::isColorStringT( StringType str, bool searchColorNames ) {
720 if ( str.empty() )
721 return false;
722
723 if ( str[0] == '#' )
724 return validHexColorString( str );
725
726 if ( searchColorNames && str.size() <= 32 ) {
727 initColorMap();
728
729 String::HashType hash = String::hashToLower( str );
730 if ( sColorMap.find( hash ) != sColorMap.end() )
731 return true;
732
733 if ( sColorHash.find( hash ) != sColorHash.end() )
734 return true;
735 }
736
737 if ( String::istartsWith( str, "@color/" ) ) {
738 std::string utf8Str;
739 if constexpr ( std::is_same_v<StringType, String::View> ) {
740 if ( LuaPattern::hasMatches( String( str ).toUtf8(), "@color/[%w_][%w_-]+" ) ) {
741 return true;
742 }
743 } else {
744 if ( LuaPattern::hasMatches( str, "@color/[%w_][%w_-]+" ) ) {
745 return true;
746 }
747 }
748 }
749
750 if ( str.back() == ')' ) {
751 FunctionString func = FunctionString::parse( str );
752
753 if ( !func.isEmpty() ) {
754 std::string name = func.getName();
755 String::toLowerInPlace( name );
756
757 if ( name == "rgb" || name == "rgba" || name == "hsl" || name == "hsla" ||
758 name == "hsv" || name == "hsva" ) {
759
760 const auto& params = func.getParameters();
761 if ( params.empty() || params.size() > 4 )
762 return false;
763
764 for ( const auto& param : params ) {
765 if ( param.empty() )
766 return false;
767
768 bool hasFunc = false;
769 static const char* allowedFuncs[] = {
770 "var(", "calc(", "min(", "max(", "clamp(", "env(", "color-mix(", "color(" };
771
772 for ( const char* f : allowedFuncs ) {
773 if ( param.find( f ) != std::string::npos ) {
774 hasFunc = true;
775 break;
776 }

Callers

nothing calls this directly

Calls 8

hashToLowerFunction · 0.85
toUtf8Method · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
isEmptyMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected