Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / shlxthandler / util / fileextensions.cxx
blob2ee68f3b5f428acf6120976d629112bd5b6be081
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 "algorithm"
21 #include "internal/fileextensions.hxx"
22 #include <sal/macros.h>
26 const std::string WRITER_FILE_EXTENSIONS = "sxwstwsxgodtottodm";
27 const std::string CALC_FILE_EXTENSIONS = "sxcstcodsots";
28 const std::string DRAW_FILE_EXTENSIONS = "sxdstdodgotg";
29 const std::string IMPRESS_FILE_EXTENSIONS = "sxistiodpotp";
30 const std::string MATH_FILE_EXTENSIONS = "sxmodf";
31 const std::string WEB_FILE_EXTENSIONS = "oth";
32 const std::string DATABASE_FILE_EXTENSIONS = "odb";
34 FileExtensionEntry OOFileExtensionTable[] = {
35 { ".sxw", L".sxw", "soffice.StarWriterDocument.6" },
36 { ".sxc", L".sxc", "soffice.StarCalcDocument.6" },
37 { ".sxi", L".sxi", "soffice.StarImpressDocument.6" },
38 { ".sxd", L".sxd", "soffice.StarDrawDocument.6" },
39 { ".sxm", L".sxm", "soffice.StarMathDocument.6" },
40 { ".stw", L".stw", "soffice.StarWriterTemplate.6" },
41 { ".sxg", L".sxg", "soffice.StarWriterGlobalDocument.6" },
42 { ".std", L".std", "soffice.StarDrawTemplate.6" },
43 { ".sti", L".sti", "soffice.StarImpressTemplate.6" },
44 { ".stc", L".stc", "soffice.StarCalcTemplate.6" },
45 { ".odt", L".odt", "LibreOffice.WriterDocument.1" },
46 { ".ott", L".ott", "LibreOffice.WriterTemplate.1" },
47 { ".odm", L".odm", "LibreOffice.WriterGlobalDocument.1" },
48 { ".oth", L".oth", "LibreOffice.WriterWebTemplate.1" },
49 { ".ods", L".ods", "LibreOffice.CalcDocument.1" },
50 { ".ots", L".ots", "LibreOffice.CalcTemplate.1" },
51 { ".odg", L".odg", "LibreOffice.DrawDocument.1" },
52 { ".otg", L".otg", "LibreOffice.DrawTemplate.1" },
53 { ".odp", L".odp", "LibreOffice.ImpressDocument.1" },
54 { ".otp", L".otp", "LibreOffice.ImpressTemplate.1" },
55 { ".odf", L".odf", "LibreOffice.MathDocument.1" },
56 { ".odb", L".odb", "LibreOffice.DatabaseDocument.1" }
60 size_t OOFileExtensionTableSize = sizeof(OOFileExtensionTable)/sizeof(OOFileExtensionTable[0]);
63 /** Return the extension of a file
64 name without the '.'
66 std::string get_file_name_extension(const std::string& file_name)
68 std::string::size_type idx = file_name.find_last_of(".");
70 if (std::string::npos != idx++)
71 return std::string(file_name.begin() + idx, file_name.end());
73 return std::string();
77 /** Return the type of a file
80 char easytolower( char in )
82 if( in<='Z' && in>='A' )
83 return in-('Z'-'z');
84 return in;
87 File_Type_t get_file_type(const std::string& file_name)
89 std::string fext = get_file_name_extension(file_name);
90 std::transform(fext.begin(), fext.end(), fext.begin(), easytolower);
92 if (std::string::npos != WRITER_FILE_EXTENSIONS.find(fext))
93 return WRITER;
94 else if (std::string::npos != CALC_FILE_EXTENSIONS.find(fext))
95 return CALC;
96 else if (std::string::npos != DRAW_FILE_EXTENSIONS.find(fext))
97 return DRAW;
98 else if (std::string::npos != IMPRESS_FILE_EXTENSIONS.find(fext))
99 return IMPRESS;
100 else if (std::string::npos != MATH_FILE_EXTENSIONS.find(fext))
101 return MATH;
102 else if (std::string::npos != WEB_FILE_EXTENSIONS.find(fext))
103 return WEB;
104 else if (std::string::npos != DATABASE_FILE_EXTENSIONS.find(fext))
105 return DATABASE;
106 else
107 return UNKNOWN;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */