MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / GetEnvironmentVariableAsBool

Function GetEnvironmentVariableAsBool

src/vrcore/envvartools_public.cpp:36–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36bool 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
76bool SetEnvironmentVariable( const char *pchVarName, const char *pchVarValue )
77{

Callers

nothing calls this directly

Calls 3

GetEnvironmentVariableFunction · 0.85
emptyMethod · 0.80
StringToLowerFunction · 0.70

Tested by

no test coverage detected