LibreOffice Module shell (master) 1
fileextensions.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <algorithm>
21#include <fileextensions.hxx>
22#include <rtl/character.hxx>
23#include <sal/macros.h>
24
25
26const std::wstring WRITER_FILE_EXTENSIONS = L"sxwstwsxgodtottodm";
27const std::wstring CALC_FILE_EXTENSIONS = L"sxcstcodsots";
28const std::wstring DRAW_FILE_EXTENSIONS = L"sxdstdodgotg";
29const std::wstring IMPRESS_FILE_EXTENSIONS = L"sxistiodpotp";
30const std::wstring MATH_FILE_EXTENSIONS = L"sxmodf";
31const std::wstring WEB_FILE_EXTENSIONS = L"oth";
32const std::wstring DATABASE_FILE_EXTENSIONS = L"odb";
33
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" }
57 };
58
59
61
62
67{
68 std::wstring::size_type idx = file_name.find_last_of(L".");
69
70 if (std::wstring::npos != idx++)
71 return std::wstring(file_name.begin() + idx, file_name.end());
72
73 return std::wstring();
74}
75
76
81{
82 std::wstring fext = get_file_name_extension(file_name);
83 std::transform(
84 fext.begin(), fext.end(), fext.begin(),
85 [](wchar_t c) {
86 return rtl::toAsciiLowerCase(c); });
87
88 if (std::wstring::npos != WRITER_FILE_EXTENSIONS.find(fext))
89 return WRITER;
90 else if (std::wstring::npos != CALC_FILE_EXTENSIONS.find(fext))
91 return CALC;
92 else if (std::wstring::npos != DRAW_FILE_EXTENSIONS.find(fext))
93 return DRAW;
94 else if (std::wstring::npos != IMPRESS_FILE_EXTENSIONS.find(fext))
95 return IMPRESS;
96 else if (std::wstring::npos != MATH_FILE_EXTENSIONS.find(fext))
97 return MATH;
98 else if (std::wstring::npos != WEB_FILE_EXTENSIONS.find(fext))
99 return WEB;
100 else if (std::wstring::npos != DATABASE_FILE_EXTENSIONS.find(fext))
101 return DATABASE;
102 else
103 return UNKNOWN;
104}
105
106/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Filepath_t get_file_name_extension(const Filepath_t &file_name)
Return the extension of a file name without the '.
const std::wstring MATH_FILE_EXTENSIONS
const std::wstring WEB_FILE_EXTENSIONS
const std::wstring IMPRESS_FILE_EXTENSIONS
const FileExtensionEntry OOFileExtensionTable[]
const std::wstring DRAW_FILE_EXTENSIONS
const size_t OOFileExtensionTableSize
const std::wstring DATABASE_FILE_EXTENSIONS
const std::wstring WRITER_FILE_EXTENSIONS
File_Type_t get_file_type(const Filepath_t &file_name)
Return the type of a file.
const std::wstring CALC_FILE_EXTENSIONS
File_Type_t
Return the type of a file.
@ WRITER
@ IMPRESS
@ WEB
@ DRAW
@ UNKNOWN
@ DATABASE
@ CALC
@ MATH
std::string Filepath_t
Definition: filepath.hxx:22
const sal_uInt16 idx[]
#define SAL_N_ELEMENTS(arr)
A FileExtensionEntry consists of the extension as ansi and as unicode string and of the currently use...