Skip to content

Commit 3dbe558

Browse files
committed
Bugfixing
1 parent 90b2f8e commit 3dbe558

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

Actions.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ void Extension::actionNew(TCHAR const *file, int flag)
247247
void Extension::actionLoad(TCHAR const *file, int flag)
248248
{
249249
data->ReadOnly = (flag? true : false);
250-
std::basic_ifstream<TCHAR> ifs (file);
250+
std::ifstream ifs (file);
251251
if(ifs)
252252
{
253-
return loadIni(ifs);
253+
//load entire file and convert it to unicode
254+
std::basic_istringstream<TCHAR> iss {utf16from8(std::string(std::istreambuf_iterator<char>(ifs), {}))};
255+
return loadIni(iss);
254256
}
255257
else
256258
{
@@ -265,7 +267,11 @@ void Extension::actionSave()
265267

266268
void Extension::actionSaveAs(TCHAR const *file)
267269
{
268-
//CHRILLEY
270+
//TODO: optionally create folders if they don't exist
271+
std::basic_ostringstream<TCHAR> oss;
272+
saveIni(oss);
273+
auto str = utf8from16(oss.str());
274+
std::ofstream{file} << str;
269275
}
270276

271277
void Extension::actionBackupTo(TCHAR const *file, int flag, TCHAR const *key)
@@ -482,16 +488,15 @@ void Extension::actionLoadChangeFile(TCHAR const *file, paramExt *settings) //TO
482488

483489
if(lt == LoadType::Load)
484490
{
485-
loadIni(std::basic_ifstream<TCHAR>{file});
486-
data->ReadOnly = readOnly;
491+
actionLoad(file, readOnly);
487492
}
488493
if(ft == FNameType::Change || (ft == FNameType::ChangeIfOk && exists))
489494
{
490495
data->autoSavePath = file;
491496
}
492497
if(saveNow)
493498
{
494-
saveIni(std::basic_ofstream<TCHAR>{file});
499+
actionSave();
495500
}
496501
}
497502

Extension.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,38 @@ void Extension::loadIni(std::basic_istream<TCHAR> &in) //TODO: quoted values
358358
stdtstring line;
359359
while(std::getline(in, line)) //TODO: nonstandard newlines
360360
{
361+
line.erase(0, line.find_first_not_of(_T(' '))); //trim unescaped leading spaces (TODO: deal with tabs first)
361362
stdtstring current, name;
362363
bool item = false;
364+
std::size_t spaces = 0;
363365
depth = 0;
364366
for(std::size_t i = 0; i < line.length(); ++i)
365367
{
366368
auto const c = line[i];
367-
if(c == _T('\r') || c == _T(' '))
369+
if(c == _T(' '))
368370
{
371+
++spaces; //count spaces that might be trailing or might be inner
369372
continue;
370373
}
371-
else if(c == _T('\t'))
374+
else if(c == _T('\r'))
375+
{
376+
continue;
377+
}
378+
else if(c == _T('='))
379+
{
380+
name += current;
381+
current.clear();
382+
spaces = 0;
383+
item = true;
384+
if(i+1 < line.length())
385+
{
386+
line.erase(i+1, line.find_first_not_of(_T(' '), i+1)-i-1); //trim unescaped leading spaces
387+
}
388+
continue;
389+
}
390+
current.append(spaces, _T(' ')); //add the spaces since they're clearly inner and not trailing
391+
spaces = 0;
392+
if(c == _T('\t'))
372393
{
373394
if(current.empty())
374395
{
@@ -384,6 +405,7 @@ void Extension::loadIni(std::basic_istream<TCHAR> &in) //TODO: quoted values
384405
{
385406
case _T('n'): current += _T('\n'); ++i; continue;
386407
case _T('t'): current += _T('\t'); ++i; continue;
408+
case _T(' '): current += _T(' ' ); ++i; continue;
387409
default: continue;
388410
}
389411
}
@@ -422,13 +444,6 @@ void Extension::loadIni(std::basic_istream<TCHAR> &in) //TODO: quoted values
422444
}
423445
break;
424446
}
425-
else if(c == _T('='))
426-
{
427-
name += current;
428-
current.clear();
429-
item = true;
430-
continue;
431-
}
432447
current += c;
433448
}
434449
if(item)

0 commit comments

Comments
 (0)