void IniFile::Parse(LPCVOID data, size_t size) { LPCWSTR begin = (LPCWSTR)data; LPCWSTR end = begin + size / sizeof(*begin); if (*begin == 0xFEFF) ++begin; Section* currentSection = nullptr; CString* varToAppend = nullptr; while (1) { const wchar_t* eol = GetEol(begin, end); if (begin >= eol) break; CStringW line(begin, int(eol - begin)); begin = eol + 1; line.Trim(L" \t\r\n"); if (varToAppend) { bool appendNext = line.Right(1) == L"\\"; if (appendNext) line.Delete(line.GetLength() - 1); *varToAppend += line; if (!appendNext) varToAppend = nullptr; continue; } if (line.IsEmpty() || line[0] == L';') continue; if (line[0] == L'[' && line[line.GetLength() - 1] == L']') { currentSection = &m_sections[line.Trim(L"[]")]; continue; } if (!currentSection) continue; int equalPos = line.Find(L'='); if (equalPos == -1 || equalPos == 0) continue; CStringW var = line.Left(equalPos); CStringW text = line.Mid(equalPos + 1); if (text.Right(1) == L"\\") { text.Delete(text.GetLength() - 1); varToAppend = &(*currentSection)[var]; } (*currentSection)[var] = text; } }
BOOL CFileBasedProjectTemplateItem::CreateMainFile(LPCTSTR lpszTargetPath, LPCTSTR lpszCrLf) { CStringW text; TextDocument doc; bool result = doc.Read(m_strPath,text); if (result) { const CStringW lineendings(L"\r\n"); int index = text.FindOneOf(lineendings); if (index != -1) { CStringW line = text.Left(index); const CStringW strKey(L"%DESCRIPTION: "); CStringW strStartOfLine = line.Left(strKey.GetLength()); strStartOfLine.MakeUpper(); if (strKey == strStartOfLine) { text.Delete(0,index); text.TrimLeft(lineendings + L' '); } } LPCWSTR le = GetLineEnding(static_cast<LPCWSTR>(text),text.GetLength()); USES_CONVERSION; if (std::wcscmp(le,T2CW(lpszCrLf)) != 0) // Line endings not equal text.Replace(le,lpszCrLf); result = doc.Write(lpszTargetPath,text); } return result; }
void GenTextFromPat(const STRARRAY &Pat, const STRARRAY &Var, CStringW &strOut) { if (!Pat.empty() || Pat.size() % 2 != 1) { strOut.Empty(); STRARRAY::const_iterator i = Pat.begin(); strOut.Append(*i++); for (; i != Pat.end(); ++i) { BOOL bFile = FALSE; CStringW strCurVar = *i; if (strCurVar[0] == _T('f') || strCurVar[0] == _T('F')) { bFile = TRUE; strCurVar.Delete(0, 1); } UINT nNum = atoi(CStringA(strCurVar)); if (nNum < Var.size()) { if (bFile) { CStringW strFile; if (0 == LoadTextFile(CString(Var[nNum]), CODEPAGE_GB2312, strFile)) { strOut.Append(strFile); } } else { strOut.Append(Var[nNum]); } } strOut.Append(*++i); } } }