| 34 | } |
| 35 | |
| 36 | bool GetEnvironmentVariableAsBool( const char *pchVarName, bool bDefault ) |
| 37 | { |
| 38 | std::string sValue = GetEnvironmentVariable( pchVarName ); |
| 39 | |
| 40 | if ( sValue.empty() ) |
| 41 | { |
| 42 | return bDefault; |
| 43 | } |
| 44 | |
| 45 | sValue = StringToLower( sValue ); |
| 46 | std::string sYesValues[] = { "y", "yes", "true" }; |
| 47 | std::string sNoValues[] = { "n", "no", "false" }; |
| 48 | |
| 49 | for ( std::string &sMatch : sYesValues ) |
| 50 | { |
| 51 | if ( sMatch == sValue ) |
| 52 | { |
| 53 | return true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | for ( std::string &sMatch : sNoValues ) |
| 58 | { |
| 59 | if ( sMatch == sValue ) |
| 60 | { |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if ( std::isdigit( sValue.at(0) ) ) |
| 66 | { |
| 67 | return atoi( sValue.c_str() ) != 0; |
| 68 | } |
| 69 | |
| 70 | fprintf( stderr, |
| 71 | "GetEnvironmentVariableAsBool(%s): Unable to parse value '%s', using default %d\n", |
| 72 | pchVarName, sValue.c_str(), bDefault ); |
| 73 | return bDefault; |
| 74 | } |
| 75 | |
| 76 | bool SetEnvironmentVariable( const char *pchVarName, const char *pchVarValue ) |
| 77 | { |
nothing calls this directly
no test coverage detected