Bump for 3.6-28
[LibreOffice.git] / l10ntools / source / export2.cxx
blob013ae90d164f8bb135323127afe4b495183bca0d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include "export.hxx"
32 #include <stdio.h>
33 #include <osl/time.h>
34 #include <osl/process.h>
35 #include <rtl/strbuf.hxx>
36 #include <rtl/ustring.hxx>
37 #include <sal/macros.h>
38 #include <iostream>
39 #include <iomanip>
40 #include <time.h>
41 #include <stdlib.h>
44 // class ResData();
47 /*****************************************************************************/
48 ResData::~ResData()
49 /*****************************************************************************/
51 if ( pStringList ) {
52 // delete existing res. of type StringList
53 for ( size_t i = 0; i < pStringList->size(); i++ ) {
54 ExportListEntry* test = (*pStringList)[ i ];
55 if( test != NULL ) delete test;
57 delete pStringList;
59 if ( pFilterList ) {
60 // delete existing res. of type FilterList
61 for ( size_t i = 0; i < pFilterList->size(); i++ ) {
62 ExportListEntry* test = (*pFilterList)[ i ];
63 delete test;
65 delete pFilterList;
67 if ( pItemList ) {
68 // delete existing res. of type ItemList
69 for ( size_t i = 0; i < pItemList->size(); i++ ) {
70 ExportListEntry* test = (*pItemList)[ i ];
71 delete test;
73 delete pItemList;
75 if ( pUIEntries ) {
76 // delete existing res. of type UIEntries
77 for ( size_t i = 0; i < pUIEntries->size(); i++ ) {
78 ExportListEntry* test = (*pUIEntries)[ i ];
79 delete test;
81 delete pUIEntries;
86 // class Export
89 /*****************************************************************************/
90 rtl::OString Export::sLanguages;
91 rtl::OString Export::sForcedLanguages;
92 /*****************************************************************************/
94 /*****************************************************************************/
95 void Export::SetLanguages( std::vector<rtl::OString> val ){
96 /*****************************************************************************/
97 aLanguages = val;
98 isInitialized = true;
100 /*****************************************************************************/
101 std::vector<rtl::OString> Export::GetLanguages(){
102 /*****************************************************************************/
103 return aLanguages;
105 /*****************************************************************************/
106 std::vector<rtl::OString> Export::GetForcedLanguages(){
107 /*****************************************************************************/
108 return aForcedLanguages;
110 std::vector<rtl::OString> Export::aLanguages = std::vector<rtl::OString>();
111 std::vector<rtl::OString> Export::aForcedLanguages = std::vector<rtl::OString>();
113 /*****************************************************************************/
114 rtl::OString Export::QuoteHTML( rtl::OString const &rString )
115 /*****************************************************************************/
117 rtl::OStringBuffer sReturn;
118 for ( sal_Int32 i = 0; i < rString.getLength(); i++ ) {
119 rtl::OString sTemp = rString.copy( i );
120 if ( sTemp.match( "<Arg n=" ) ) {
121 while ( i < rString.getLength() && rString[i] != '>' ) {
122 sReturn.append(rString[i]);
123 i++;
125 if ( rString[i] == '>' ) {
126 sReturn.append('>');
127 i++;
130 if ( i < rString.getLength()) {
131 switch ( rString[i]) {
132 case '<':
133 sReturn.append("&lt;");
134 break;
136 case '>':
137 sReturn.append("&gt;");
138 break;
140 case '\"':
141 sReturn.append("&quot;");
142 break;
144 case '\'':
145 sReturn.append("&apos;");
146 break;
148 case '&':
149 if ((( i + 4 ) < rString.getLength()) &&
150 ( rString.copy( i, 5 ) == "&amp;" ))
151 sReturn.append(rString[i]);
152 else
153 sReturn.append("&amp;");
154 break;
156 default:
157 sReturn.append(rString[i]);
158 break;
162 return sReturn.makeStringAndClear();
165 void Export::RemoveUTF8ByteOrderMarker( rtl::OString &rString )
167 if( hasUTF8ByteOrderMarker( rString ) )
168 rString = rString.copy(3);
171 bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString )
173 return rString.getLength() >= 3 && rString[0] == '\xEF' &&
174 rString[1] == '\xBB' && rString[2] == '\xBF' ;
177 /*****************************************************************************/
178 rtl::OString Export::UnquoteHTML( rtl::OString const &rString )
179 /*****************************************************************************/
181 rtl::OStringBuffer sReturn;
182 for (sal_Int32 i = 0; i != rString.getLength();) {
183 if (rString.match("&amp;", i)) {
184 sReturn.append('&');
185 i += RTL_CONSTASCII_LENGTH("&amp;");
186 } else if (rString.match("&lt;", i)) {
187 sReturn.append('<');
188 i += RTL_CONSTASCII_LENGTH("&lt;");
189 } else if (rString.match("&gt;", i)) {
190 sReturn.append('>');
191 i += RTL_CONSTASCII_LENGTH("&gt;");
192 } else if (rString.match("&quot;", i)) {
193 sReturn.append('"');
194 i += RTL_CONSTASCII_LENGTH("&quot;");
195 } else if (rString.match("&apos;", i)) {
196 sReturn.append('\'');
197 i += RTL_CONSTASCII_LENGTH("&apos;");
198 } else {
199 sReturn.append(rString[i]);
200 ++i;
203 return sReturn.makeStringAndClear();
206 bool Export::isSourceLanguage(const rtl::OString &rLanguage)
208 return !isAllowed(rLanguage);
211 bool Export::isAllowed(const rtl::OString &rLanguage)
213 return !rLanguage.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"));
216 bool Export::isInitialized = false;
218 /*****************************************************************************/
219 void Export::InitLanguages( bool bMergeMode ){
220 /*****************************************************************************/
221 if( !isInitialized )
223 rtl::OString sTmp;
224 OStringBoolHashMap aEnvLangs;
226 sal_Int32 nIndex = 0;
229 rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
230 sTmp = aToken.getToken(0, '=').trim();
231 if( bMergeMode && !isAllowed( sTmp ) ){}
232 else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
233 aLanguages.push_back( sTmp );
236 while ( nIndex >= 0 );
238 InitForcedLanguages( bMergeMode );
239 isInitialized = true;
242 /*****************************************************************************/
243 void Export::InitForcedLanguages( bool bMergeMode ){
244 /*****************************************************************************/
245 rtl::OString sTmp;
246 OStringBoolHashMap aEnvLangs;
248 sal_Int32 nIndex = 0;
251 rtl::OString aToken = sForcedLanguages.getToken(0, ',', nIndex);
253 sTmp = aToken.getToken(0, '=').trim();
254 if( bMergeMode && isAllowed( sTmp ) ){}
255 else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) )
256 aForcedLanguages.push_back( sTmp );
258 while ( nIndex >= 0 );
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */