-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Get locales from the system Signed-off-by: lbgracioso <[email protected]> * Remove destructor, mark functions with '[[nodiscard]]' Signed-off-by: lbgracioso <[email protected]> * Turn Locale::fetchAvailableLocales to private Signed-off-by: lbgracioso <[email protected]> --------- Signed-off-by: lbgracioso <[email protected]>
- Loading branch information
1 parent
103a533
commit 589c31f
Showing
6 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Created by Lucas Gracioso <[email protected]> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef CLOYSTERHPC_LOCALE_H_ | ||
#define CLOYSTERHPC_LOCALE_H_ | ||
|
||
#include <list> | ||
#include <string> | ||
|
||
class Locale { | ||
private: | ||
std::string m_locale; | ||
std::list<std::string> m_availableLocales; | ||
|
||
public: | ||
Locale(); | ||
void setLocale(std::string_view locale); | ||
[[nodiscard]] std::string_view getLocale() const; | ||
[[nodiscard]] std::list<std::string> getAvailableLocales() const; | ||
|
||
private: | ||
[[nodiscard]] std::list<std::string> fetchAvailableLocales() const; | ||
}; | ||
|
||
#endif // CLOYSTERHPC_LOCALE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Created by Lucas Gracioso <[email protected]> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "cloysterhpc/services/locale.h" | ||
#include "cloysterhpc/functions.h" | ||
#include <cloysterhpc/services/log.h> | ||
|
||
Locale::Locale() | ||
: m_availableLocales { fetchAvailableLocales() } | ||
{ | ||
} | ||
|
||
void Locale::setLocale(std::string_view locale) | ||
{ | ||
if (std::find(m_availableLocales.begin(), m_availableLocales.end(), locale) | ||
!= m_availableLocales.end()) | ||
m_locale = locale; | ||
else | ||
throw std::runtime_error("Unsupported locale"); | ||
} | ||
|
||
std::string_view Locale::getLocale() const { return m_locale; } | ||
|
||
std::list<std::string> Locale::getAvailableLocales() const | ||
{ | ||
return m_availableLocales; | ||
} | ||
|
||
std::list<std::string> Locale::fetchAvailableLocales() const | ||
{ | ||
LOG_DEBUG("Fetching available system locales") | ||
std::list<std::string> output; | ||
|
||
cloyster::runCommand(fmt::format("locale -a"), output, true); | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters