| 101 | } |
| 102 | |
| 103 | Settings::Settings( const char* file_name ) |
| 104 | : file_name_(file_name) |
| 105 | { |
| 106 | FILE* const file= std::fopen( file_name, "rb" ); |
| 107 | if( file == nullptr ) |
| 108 | { |
| 109 | Log::Warning( "Can not open settins file \"", file_name, "\"" ); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | std::fseek( file, 0, SEEK_END ); |
| 114 | const unsigned int file_size= std::ftell( file ); |
| 115 | std::fseek( file, 0, SEEK_SET ); |
| 116 | |
| 117 | std::vector<char> file_data; |
| 118 | file_data.resize( file_size + 1u ); |
| 119 | file_data[ file_size ]= '\0'; |
| 120 | |
| 121 | FileRead( file, file_data.data(), file_size ); |
| 122 | std::fclose( file ); |
| 123 | |
| 124 | const char* s= file_data.data(); |
| 125 | while( *s != '\0' ) |
| 126 | { |
| 127 | std::string str[2]; // key-value pair |
| 128 | |
| 129 | for( unsigned int i= 0u; i < 2u; i++ ) |
| 130 | { |
| 131 | while( std::isspace( *s ) && *s != '\0' ) s++; |
| 132 | if( *s == '\0' ) break; |
| 133 | |
| 134 | if( *s == '"' ) // string in quotes |
| 135 | { |
| 136 | s++; |
| 137 | while( *s != '\0' && *s != '"' ) |
| 138 | { |
| 139 | if( *s == '\\' && ( s[1] == '"' || s[1] == '\\' ) ) s++; // Escaped symbol |
| 140 | str[i].push_back( *s ); |
| 141 | s++; |
| 142 | } |
| 143 | if( *s == '"' ) |
| 144 | s++; |
| 145 | else |
| 146 | break; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | while( *s != '\0' && !std::isspace( *s ) ) |
| 151 | { |
| 152 | str[i].push_back( *s ); |
| 153 | s++; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if( ! str[0].empty() ) |
| 159 | map_[ SettingsStringContainer(str[0]) ]= str[1]; |
| 160 | } |
nothing calls this directly
no test coverage detected