1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <fileextensions.hxx>
22 #include <rtl/character.hxx>
23 #include <sal/macros.h>
26 const std::wstring WRITER_FILE_EXTENSIONS
= L
"sxwstwsxgodtottodm";
27 const std::wstring CALC_FILE_EXTENSIONS
= L
"sxcstcodsots";
28 const std::wstring DRAW_FILE_EXTENSIONS
= L
"sxdstdodgotg";
29 const std::wstring IMPRESS_FILE_EXTENSIONS
= L
"sxistiodpotp";
30 const std::wstring MATH_FILE_EXTENSIONS
= L
"sxmodf";
31 const std::wstring WEB_FILE_EXTENSIONS
= L
"oth";
32 const std::wstring DATABASE_FILE_EXTENSIONS
= L
"odb";
34 const FileExtensionEntry OOFileExtensionTable
[] = {
35 { ".sxw", L
".sxw", L
"soffice.StarWriterDocument.6" },
36 { ".sxc", L
".sxc", L
"soffice.StarCalcDocument.6" },
37 { ".sxi", L
".sxi", L
"soffice.StarImpressDocument.6" },
38 { ".sxd", L
".sxd", L
"soffice.StarDrawDocument.6" },
39 { ".sxm", L
".sxm", L
"soffice.StarMathDocument.6" },
40 { ".stw", L
".stw", L
"soffice.StarWriterTemplate.6" },
41 { ".sxg", L
".sxg", L
"soffice.StarWriterGlobalDocument.6" },
42 { ".std", L
".std", L
"soffice.StarDrawTemplate.6" },
43 { ".sti", L
".sti", L
"soffice.StarImpressTemplate.6" },
44 { ".stc", L
".stc", L
"soffice.StarCalcTemplate.6" },
45 { ".odt", L
".odt", L
"LibreOffice.WriterDocument.1" },
46 { ".ott", L
".ott", L
"LibreOffice.WriterTemplate.1" },
47 { ".odm", L
".odm", L
"LibreOffice.WriterGlobalDocument.1" },
48 { ".oth", L
".oth", L
"LibreOffice.WriterWebTemplate.1" },
49 { ".ods", L
".ods", L
"LibreOffice.CalcDocument.1" },
50 { ".ots", L
".ots", L
"LibreOffice.CalcTemplate.1" },
51 { ".odg", L
".odg", L
"LibreOffice.DrawDocument.1" },
52 { ".otg", L
".otg", L
"LibreOffice.DrawTemplate.1" },
53 { ".odp", L
".odp", L
"LibreOffice.ImpressDocument.1" },
54 { ".otp", L
".otp", L
"LibreOffice.ImpressTemplate.1" },
55 { ".odf", L
".odf", L
"LibreOffice.MathDocument.1" },
56 { ".odb", L
".odb", L
"LibreOffice.DatabaseDocument.1" }
60 const size_t OOFileExtensionTableSize
= SAL_N_ELEMENTS(OOFileExtensionTable
);
63 /** Return the extension of a file
66 Filepath_t
get_file_name_extension(const Filepath_t
& file_name
)
68 std::wstring::size_type idx
= file_name
.find_last_of(L
".");
70 if (std::wstring::npos
!= idx
++)
71 return std::wstring(file_name
.begin() + idx
, file_name
.end());
73 return std::wstring();
77 /** Return the type of a file
80 File_Type_t
get_file_type(const Filepath_t
& file_name
)
82 std::wstring fext
= get_file_name_extension(file_name
);
84 fext
.begin(), fext
.end(), fext
.begin(),
86 return rtl::toAsciiLowerCase(c
); });
88 if (std::wstring::npos
!= WRITER_FILE_EXTENSIONS
.find(fext
))
90 else if (std::wstring::npos
!= CALC_FILE_EXTENSIONS
.find(fext
))
92 else if (std::wstring::npos
!= DRAW_FILE_EXTENSIONS
.find(fext
))
94 else if (std::wstring::npos
!= IMPRESS_FILE_EXTENSIONS
.find(fext
))
96 else if (std::wstring::npos
!= MATH_FILE_EXTENSIONS
.find(fext
))
98 else if (std::wstring::npos
!= WEB_FILE_EXTENSIONS
.find(fext
))
100 else if (std::wstring::npos
!= DATABASE_FILE_EXTENSIONS
.find(fext
))
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */