bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mozab / bootstrap / MNSINIParser.cxx
blob04c27cd0ed716850e143c0d23d1168478afa2f56
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 <rtl/byteseq.hxx>
22 #include <sal/log.hxx>
24 IniParser::IniParser(OUString const & rIniName)
26 OUString iniUrl;
27 if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData))
28 return;
31 oslFileHandle handle=nullptr;
32 oslFileError fileError = osl_File_E_INVAL;
33 try{
34 if (!iniUrl.isEmpty())
35 fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read);
37 catch(const css::io::IOException&)
39 SAL_WARN("connectivity.mozab", "couldn't open file: " << iniUrl );
42 if (osl_File_E_None == fileError)
44 rtl::ByteSequence seq;
45 sal_uInt64 nSize = 0;
47 osl_getFileSize(handle, &nSize);
48 OUString sectionName( "no name section" );
49 while (true)
51 sal_uInt64 nPos;
52 if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize)
53 break;
54 if (osl_File_E_None != osl_readLine(handle, reinterpret_cast<sal_Sequence **>(&seq)))
55 break;
56 OString line(reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength() );
57 sal_Int32 nIndex = line.indexOf('=');
58 if (nIndex >= 1)
60 ini_Section *aSection = &mAllSection[sectionName];
61 struct ini_NameValue nameValue;
62 nameValue.sName = OStringToOUString(
63 line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
64 nameValue.sValue = OStringToOUString(
65 line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
67 aSection->vVector.push_back(nameValue);
70 else
72 sal_Int32 nIndexStart = line.indexOf('[');
73 sal_Int32 nIndexEnd = line.indexOf(']');
74 if ( nIndexEnd > nIndexStart && nIndexStart >=0)
76 sectionName = OStringToOUString(
77 line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US );
78 if (sectionName.isEmpty())
79 sectionName = "no name section";
83 osl_closeFile(handle);
85 else
87 SAL_INFO("connectivity.mozab", "couldn't open file: " << iniUrl );
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */