@@ -43,17 +43,7 @@ bool file_settings::equals(const file_settings& rhs) const noexcept {
43
43
44
44
void file_settings::load (const xtd::ustring& file_path) {
45
45
file_path_ = path::get_full_path (file_path);
46
- auto stream = stream_reader {file_path_};
47
- auto section = ustring::empty_string;
48
- while (!stream.end_of_stream ()) {
49
- auto line = stream.read_line ().trim ();
50
- if (ustring::is_empty (line) || line.starts_with (' ;' ) || line.starts_with (' #' )) continue ;
51
- if (line.starts_with (' [' ) && line.ends_with (' ]' )) section = line.substring (1 , line.size () - 2 );
52
- else {
53
- auto key_value = line.split ({' =' });
54
- section_key_values_[section][key_value[0 ].trim ().trim (' "' )] = key_value.size () == 1 ? " " : ustring::join (" =" , key_value, 1 ).trim ().trim (' "' );
55
- }
56
- }
46
+ from_string (stream_reader {file_path_}.read_to_end ());
57
47
}
58
48
59
49
ustring file_settings::read (const ustring& key, const ustring& default_value) noexcept {
@@ -100,6 +90,18 @@ void file_settings::save_as(const xtd::ustring& file_path) {
100
90
stream.write (to_string ());
101
91
}
102
92
93
+ void file_settings::from_string (const xtd::ustring& text) {
94
+ auto section = ustring::empty_string;
95
+ for (auto line : text.split ({10 , 13 }, string_split_options::remove_empty_entries)) {
96
+ if (ustring::is_empty (line) || line.starts_with (' ;' ) || line.starts_with (' #' )) continue ;
97
+ if (line.starts_with (' [' ) && line.ends_with (' ]' )) section = line.substring (1 , line.size () - 2 );
98
+ else {
99
+ auto key_value = line.split ({' =' });
100
+ section_key_values_[section][key_value[0 ].trim ().trim (' "' )] = key_value.size () == 1 ? " " : ustring::join (" =" , key_value, 1 ).trim ().trim (' "' );
101
+ }
102
+ }
103
+ }
104
+
103
105
ustring file_settings::to_string () const noexcept {
104
106
auto text = ustring::empty_string;
105
107
for (auto [section, key_value] : section_key_values_) {
0 commit comments