1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _LINGUTIL_HXX_
29 #define _LINGUTIL_HXX_
30 
31 
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <rtl/string.hxx>
34 #include <rtl/ustring.hxx>
35 #include <tools/string.hxx>
36 
37 #include <vector>
38 #include <list>
39 
40 
41 #define A2OU(x) ::rtl::OUString::createFromAscii( x )
42 
43 #define OU2A(rtlOUString) \
44     ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), \
45     RTL_TEXTENCODING_ASCII_US).getStr()
46 
47 #define OU2UTF8(rtlOUString) \
48     ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), \
49     RTL_TEXTENCODING_UTF8).getStr()
50 
51 #define OU2ISO_1(rtlOUString) \
52     ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), \
53     RTL_TEXTENCODING_ISO_8859_1).getStr()
54 
55 #define OU2ENC(rtlOUString, rtlEncoding) \
56     ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), \
57     rtlEncoding, RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK).getStr()
58 
59 
60 struct SvtLinguConfigDictionaryEntry;
61 
62 ///////////////////////////////////////////////////////////////////////////
63 
64 struct lt_rtl_OUString
65 {
66     bool operator() (const rtl::OUString &r1, const rtl::OUString &r2) const
67     {
68         return r1 < r2;
69     }
70 };
71 
72 inline sal_Bool operator == ( const ::com::sun::star::lang::Locale &rL1, const ::com::sun::star::lang::Locale &rL2 )
73 {
74     return  rL1.Language ==  rL2.Language   &&
75             rL1.Country  ==  rL2.Country    &&
76             rL1.Variant  ==  rL2.Variant;
77 }
78 
79 #if 0
80 ///////////////////////////////////////////////////////////////////////////
81 
82 String GetDirectoryPathFromFileURL( const String &rFileURL );
83 #endif
84 
85 #if defined(WNT)
86 ///////////////////////////////////////////////////////////////////////////
87 // to be use to get a short path name under Windows that still can be used with
88 // the 'fopen' call. This is necessary since under Windows there seems to be
89 // a restriction of only about 110-130 characters length to a path name in order
90 // for it to work with 'fopen'. And that length is usually easily exceeded
91 // when using extensions...
92 rtl::OString Win_GetShortPathName( const rtl::OUString &rLongPathName );
93 #endif
94 
95 ///////////////////////////////////////////////////////////////////////////
96 
97 // temporary function, to be removed when new style dictionaries
98 // using configuration entries are fully implemented and provided
99 std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char * pDicType );
100 void MergeNewStyleDicsAndOldStyleDics( std::list< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics );
101 
102 ///////////////////////////////////////////////////////////////////////////
103 
104 
105 //Find an encoding from a charset string, using
106 //rtl_getTextEncodingFromMimeCharset and falling back to
107 //rtl_getTextEncodingFromUnixCharset with the addition of
108 //ISCII-DEVANAGARI. On failure will return final fallback of
109 //RTL_TEXTENCODING_ISO_8859_1
110 rtl_TextEncoding getTextEncodingFromCharset(const sal_Char* pCharset);
111 
112 #endif
113 
114