mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 10:24:13 -06:00
4.44 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
804edc5756
commit
d9666cf046
Executable
+60
@@ -0,0 +1,60 @@
|
||||
// Common/ListFileUtils.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ListFileUtils.h"
|
||||
#include "StdInStream.h"
|
||||
#include "StringConvert.h"
|
||||
#include "UTFConvert.h"
|
||||
|
||||
static const char kQuoteChar = '\"';
|
||||
static void RemoveQuote(UString &s)
|
||||
{
|
||||
if (s.Length() >= 2)
|
||||
if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)
|
||||
s = s.Mid(1, s.Length() - 2);
|
||||
}
|
||||
|
||||
bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT codePage)
|
||||
{
|
||||
CStdInStream file;
|
||||
if (!file.Open(fileName))
|
||||
return false;
|
||||
|
||||
AString s;
|
||||
file.ReadToString(s);
|
||||
UString u;
|
||||
if (codePage == CP_UTF8)
|
||||
{
|
||||
if (!ConvertUTF8ToUnicode(s, u))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
u = MultiByteToUnicodeString(s, codePage);
|
||||
if (!u.IsEmpty())
|
||||
{
|
||||
if (u[0] == 0xFEFF)
|
||||
u.Delete(0);
|
||||
}
|
||||
|
||||
UString t;
|
||||
for(int i = 0; i < u.Length(); i++)
|
||||
{
|
||||
wchar_t c = u[i];
|
||||
if (c == L'\n')
|
||||
{
|
||||
t.Trim();
|
||||
RemoveQuote(t);
|
||||
if (!t.IsEmpty())
|
||||
resultStrings.Add(t);
|
||||
t.Empty();
|
||||
}
|
||||
else
|
||||
t += c;
|
||||
}
|
||||
t.Trim();
|
||||
RemoveQuote(t);
|
||||
if (!t.IsEmpty())
|
||||
resultStrings.Add(t);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user