Gems/Atom/RPI/Code/Source/RPI.Edit/Shader/ShaderSourceData.cpp
static void GetListOfMacroDefinitionNames( 
            const AZStd::string& stringWithArguments, AZStd::vector<AZStd::string>& macroDefinitionNames)
        {
            const AZStd::regex macroRegex(R"(-D\s*(\w+))", AZStd::regex::ECMAScript);

            AZStd::string hayStack(stringWithArguments);
            AZStd::smatch match;
            while (AZStd::regex_search(hayStack.c_str(), match, macroRegex))
            {
                // First pattern is always the entire string
                for (unsigned i = 1; i < match.size(); ++i)
                {
                    if (match[i].matched)
                    {
                        AZStd::string macroToAdd(match[i].str().c_str());
                        const bool isPresent = AZStd::any_of(AZ_BEGIN_END(macroDefinitionNames),
                            [&](AZStd::string_view macroName) -> bool
                            {
                                return macroToAdd == macroName;
                            }
                        );
                        if (isPresent)
                        {
                            continue;
                        }
                        macroDefinitionNames.push_back(macroToAdd);
                    }
                }
                hayStack = match.suffix();
            }
        }
//! Helper function.
//! Parses a string of command line arguments looking for c-preprocessor macro definitions and appends the name of macro definition arguments.
//! Example:
//! Input string: "--switch1 -DMACRO1 -v -DMACRO2=23"
//! append the following items: ["MACRO1", "MACRO2"]
Helper function.
Parses a string of command line arguments looking for c-preprocessor macro definitions and appends the name of macro definition arguments.
Helper function . Parses a string of command line arguments looking for c - preprocessor macro definitions and appends the name of macro definition arguments .
static void GetListOfMacroDefinitionNames( 
            const AZStd::string& stringWithArguments, AZStd::vector<AZStd::string>& macroDefinitionNames)
        {
            const AZStd::regex macroRegex(R"(-D\s*(\w+))", AZStd::regex::ECMAScript);
            AZStd::string hayStack(stringWithArguments);
            AZStd::smatch match;
            while (AZStd::regex_search(hayStack.c_str(), match, macroRegex))
            {
                for (unsigned i = 1; i < match.size(); ++i)
                {
                    if (match[i].matched)
                    {
                        AZStd::string macroToAdd(match[i].str().c_str());
                        const bool isPresent = AZStd::any_of(AZ_BEGIN_END(macroDefinitionNames),
                            [&](AZStd::string_view macroName) -> bool
                            {
                                return macroToAdd == macroName;
                            }
                        );
                        if (isPresent)
                        {
                            continue;
                        }
                        macroDefinitionNames.push_back(macroToAdd);
                    }
                }
                hayStack = match.suffix();
            }
        }
static void GetListOfMacroDefinitionNames ( const AZStd :: string & stringWithArguments , AZStd :: vector < AZStd :: string > & macroDefinitionNames ) { const AZStd :: regex macroRegex ( R" ( -D\s*(\w+) ) " , AZStd :: regex :: ECMAScript ) ; AZStd :: string hayStack ( stringWithArguments ) ; AZStd :: smatch match ; while ( AZStd :: regex_search ( hayStack . c_str ( ) , match , macroRegex ) ) { for ( unsigned i = 1 ; i < match . size ( ) ; ++ i ) { if ( match [ i ] . matched ) { AZStd :: string macroToAdd ( match [ i ] . str ( ) . c_str ( ) ) ; const bool isPresent = AZStd :: any_of ( AZ_BEGIN_END ( macroDefinitionNames ) , [ & ] ( AZStd :: string_view macroName ) -> bool { return macroToAdd == macroName ; } ) ; if ( isPresent ) { continue ; } macroDefinitionNames . push_back ( macroToAdd ) ; } } hayStack = match . suffix ( ) ; } }
Helper function.
Helper function .
// First pattern is always the entire string