diff options
author | kh1 <karsten.heimrich@nokia.com> | 2012-03-15 14:53:47 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@nokia.com> | 2012-03-19 16:14:04 +0100 |
commit | be3b47d0d504a3409ce66bd77bb8c0acff87c4f5 (patch) | |
tree | 09dfb02d484a4f395991972b828da71400fb761a /src/libs/7zip/win/CPP/Common/ListFileUtils.cpp | |
parent | 9fd62353cf7f973d78cd2093328ac15b5c4980b6 (diff) |
Reorganize the tree, have better ifw.pri. Shadow build support.
Change-Id: I01fb12537f863ed0744979973c7e4153889cc5cb
Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
Diffstat (limited to 'src/libs/7zip/win/CPP/Common/ListFileUtils.cpp')
-rw-r--r-- | src/libs/7zip/win/CPP/Common/ListFileUtils.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp b/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp new file mode 100644 index 000000000..c1c682a2c --- /dev/null +++ b/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp @@ -0,0 +1,75 @@ +// Common/ListFileUtils.cpp + +#include "StdAfx.h" + +#include "MyWindows.h" +#include "../Windows/FileIO.h" + +#include "ListFileUtils.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(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage) +{ + NWindows::NFile::NIO::CInFile file; + if (!file.Open(fileName)) + return false; + UInt64 length; + if (!file.GetLength(length)) + return false; + if (length > ((UInt32)1 << 31)) + return false; + AString s; + char *p = s.GetBuffer((int)length + 1); + UInt32 processed; + if (!file.Read(p, (UInt32)length, processed)) + return false; + p[(UInt32)length] = 0; + s.ReleaseBuffer(); + file.Close(); + + UString u; + #ifdef CP_UTF8 + if (codePage == CP_UTF8) + { + if (!ConvertUTF8ToUnicode(s, u)) + return false; + } + else + #endif + 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' || c == 0xD) + { + 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; +} |