[deploy] add ConfigIni::LoadFromString & ConfigIni::SaveToString
This commit is contained in:
parent
4587e5a148
commit
5e9937e0f0
|
|
@ -34,9 +34,9 @@ StringView Trim(StringView str)
|
|||
if (!str.IsEmpty())
|
||||
{
|
||||
std::size_t start = 0, end = str.GetLength();
|
||||
while (std::isspace(str[start]))
|
||||
while (start < end && std::isspace(str[start]))
|
||||
++start;
|
||||
while (std::isspace(str[end - 1]))
|
||||
while (end > 0&& std ::isspace(str[end - 1]))
|
||||
--end;
|
||||
|
||||
if (end > start)
|
||||
|
|
@ -132,6 +132,13 @@ bool ConfigIni::Load(std::istream& istream)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ConfigIni::LoadFromString(const String& content)
|
||||
{
|
||||
StringStream ss;
|
||||
ss.str(content);
|
||||
return Load(ss);
|
||||
}
|
||||
|
||||
bool ConfigIni::Save(const String& file_path)
|
||||
{
|
||||
std::ofstream ofs(file_path);
|
||||
|
|
@ -176,6 +183,17 @@ bool ConfigIni::Save(std::ostream& os)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ConfigIni::SaveToString(String& content)
|
||||
{
|
||||
StringStream ss;
|
||||
if (Save(ss))
|
||||
{
|
||||
content = ss.str();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigIni::SectionMap ConfigIni::GetSectionMap() const
|
||||
{
|
||||
return sections_;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ public:
|
|||
/// @param is 输入流
|
||||
bool Load(std::istream& is);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载 ini 格式字符串
|
||||
/// @param content 输入内容
|
||||
bool LoadFromString(const String& content);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 保存至 ini 文件
|
||||
/// @param file_path 文件路径
|
||||
|
|
@ -67,6 +72,11 @@ public:
|
|||
/// @param os 输出流
|
||||
bool Save(std::ostream& os);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 保存至字符串
|
||||
/// @param content 输出内容
|
||||
bool SaveToString(String& content);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否存在section
|
||||
/// @param section section的名称
|
||||
|
|
|
|||
Loading…
Reference in New Issue