bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mozab / bootstrap / MNSINIParser.cxx
blobae775b6fca01e8d363b1dc8e3233e64a78f1cb75
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "MNSINIParser.hxx"
21 #include <com/sun/star/io/IOException.hpp>
22 #include <osl/file.h>
23 #include <rtl/byteseq.hxx>
24 #include <sal/log.hxx>
26 IniParser::IniParser(OUString const & rIniName)
28 OUString iniUrl;
29 if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData))
30 return;
33 oslFileHandle handle=nullptr;
34 oslFileError fileError = osl_File_E_INVAL;
35 try{
36 if (!iniUrl.isEmpty())
37 fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read);
39 catch(const css::io::IOException&)
41 SAL_WARN("connectivity.mozab", "couldn't open file: " << iniUrl );
44 if (osl_File_E_None == fileError)
46 rtl::ByteSequence seq;
47 sal_uInt64 nSize = 0;
49 osl_getFileSize(handle, &nSize);
50 OUString sectionName( "no name section" );
51 while (true)
53 sal_uInt64 nPos;
54 if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize)
55 break;
56 if (osl_File_E_None != osl_readLine(handle, reinterpret_cast<sal_Sequence **>(&seq)))
57 break;
58 OString line(reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength() );
59 sal_Int32 nIndex = line.indexOf('=');
60 if (nIndex >= 1)
62 ini_Section *aSection = &mAllSection[sectionName];
63 struct ini_NameValue nameValue;
64 nameValue.sName = OStringToOUString(
65 line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
66 nameValue.sValue = OStringToOUString(
67 line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
69 aSection->vVector.push_back(nameValue);
72 else
74 sal_Int32 nIndexStart = line.indexOf('[');
75 sal_Int32 nIndexEnd = line.indexOf(']');
76 if ( nIndexEnd > nIndexStart && nIndexStart >=0)
78 sectionName = OStringToOUString(
79 line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US );
80 if (sectionName.isEmpty())
81 sectionName = "no name section";
85 osl_closeFile(handle);
87 else
89 SAL_INFO("connectivity.mozab", "couldn't open file: " << iniUrl );
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */