* Determine the current charset based on the environment * First check some default values, after this one we passed ourselves * and if none exist return the value for $LANG * @param param environment variable to check conditionally if default ones are not * set. Pass nullptr if you don't want additional checks. * @return return string containing current charset, or nullptr if not-dete
| 2155 | * @return return string containing current charset, or nullptr if not-determinable |
| 2156 | */ |
| 2157 | std::optional<std::string> GetCurrentLocale(const char *param) |
| 2158 | { |
| 2159 | auto env = GetEnv("LANGUAGE"); |
| 2160 | if (env.has_value()) return std::string{*env}; |
| 2161 | |
| 2162 | env = GetEnv("LC_ALL"); |
| 2163 | if (env.has_value()) return std::string{*env}; |
| 2164 | |
| 2165 | if (param != nullptr) { |
| 2166 | env = GetEnv(param); |
| 2167 | if (env.has_value()) return std::string{*env}; |
| 2168 | } |
| 2169 | |
| 2170 | env = GetEnv("LANG"); |
| 2171 | if (env.has_value()) return std::string{*env}; |
| 2172 | |
| 2173 | return std::nullopt; |
| 2174 | } |
| 2175 | #else |
| 2176 | std::optional<std::string> GetCurrentLocale(const char *param); |
| 2177 | #endif /* !(defined(_WIN32) || defined(__APPLE__)) */ |
no test coverage detected