10#include <rtl/ustring.hxx>
28 sal_Int32 lcl_IndexOfUnicode(
29 std::string_view rSource,
const sal_Int32 nFrom = 0 )
31 static constexpr std::string_view sHexDigits =
"0123456789abcdefABCDEF";
32 size_t nIndex = rSource.find(
"\\u", nFrom );
33 if( nIndex == std::string_view::npos )
37 bool bIsUnicode =
true;
38 for(
short nDist = 2; nDist <= 5; ++nDist )
40 if( sHexDigits.find( rSource[nIndex + nDist] ) == std::string_view::npos )
45 return bIsUnicode ?
nIndex : -1;
49 OString lcl_ConvertToUTF8(
const OString& rText )
51 OString sResult = rText;
52 sal_Int32
nIndex = lcl_IndexOfUnicode( sResult );
53 while( nIndex != -1 && nIndex < rText.getLength() )
55 const OString sHex = sResult.copy( nIndex + 2, 4 );
57 static_cast<sal_Unicode>( strtol( sHex.getStr(),
nullptr, 16 ) );
58 const OString sNewChar( &cDec, 1, RTL_TEXTENCODING_UTF8 );
59 sResult = sResult.replaceAll(
"\\u" + sHex, sNewChar );
60 nIndex = lcl_IndexOfUnicode( sResult, nIndex );
66 void lcl_PrintJavaStyle( std::string_view rText, std::ofstream &rOfstream )
68 const OUString sTemp =
69 OStringToOUString( rText, RTL_TEXTENCODING_UTF8 );
70 for ( sal_Int32 nIndex = 0;
nIndex < sTemp.getLength(); ++
nIndex )
75 rOfstream << static_cast<char>( cUniCode );
81 << std::setfill(
'0') << std::setw(2) << std::uppercase
82 << std::hex << (cUniCode >> 8)
83 << std::setfill(
'0') << std::setw(2) << std::uppercase
84 << std::hex << (cUniCode & 0xFF);
92 OString _sInputFile, OString _sLang,
94 : m_sSource(
std::move( _sInputFile ))
95 , m_sLang(
std::move( _sLang ))
96 , m_bIsInitialized( false )
98 std::ifstream aIfstream(
m_sSource.getStr() );
99 if( aIfstream.is_open() )
102 std::getline( aIfstream, s );
103 while( !aIfstream.eof() )
105 OString sLine( s.data(), s.length() );
107 ( !sLine.startsWith(
" *") && !sLine.startsWith(
"/*") ) )
111 std::getline( aIfstream, s );
117 <<
"Propex error: Cannot open source file: "
136 <<
"Propex error: Cannot open pofile for extract: "
137 << rPOFile << std::endl;
144 const sal_Int32 nEqualSign = sLine.indexOf(
'=');
145 if( nEqualSign != -1 )
147 std::string_view sID =
o3tl::trim(sLine.subView( 0, nEqualSign ));
148 OString sText = lcl_ConvertToUTF8( OString(
o3tl::trim(sLine.subView( nEqualSign + 1 ))) );
151 "Propex", aPOStream,
m_sSource,
"property",
152 OString(sID), OString(), OString(), sText);
163 std::ofstream aDestination(
164 rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc );
165 if( !aDestination.is_open() ) {
167 <<
"Propex error: Cannot open source file for merge: "
168 << rDestinationFile << std::endl;
172 std::unique_ptr<MergeDataFile> pMergeDataFile;
177 const std::vector<OString> vLanguages = pMergeDataFile->GetLanguages();
178 if( !vLanguages.empty() && vLanguages[0] !=
m_sLang )
181 << (
"Propex error: given language conflicts with language of"
184 << vLanguages[0] << std::endl;
192 const sal_Int32 nEqualSign = sLine.indexOf(
'=');
193 if( !sLine.startsWith(
" *") && !sLine.startsWith(
"/*") &&
196 const OString sID(
o3tl::trim(sLine.subView( 0, sLine.indexOf(
'=') )) );
202 const OString sOriginText = lcl_ConvertToUTF8(OString(
o3tl::trim(sLine.subView( nEqualSign + 1 ))));
205 else if( pMergeDataFile )
207 MergeEntrys* pEntrys = pMergeDataFile->GetMergeEntrys( &aResData );
213 if( !sNewText.isEmpty() )
215 aDestination << OString(sID +
"=");
216 lcl_PrintJavaStyle( sNewText, aDestination );
217 aDestination << std::endl;
221 aDestination << sLine << std::endl;
226 aDestination << sLine << std::endl;
229 aDestination.close();
Purpose: holds information of data to merge, read from PO file.
Purpose: holds information of data to merge.
static OString GetQTZText(const ResData &rResData, std::string_view rOrigText)
Generate QTZ string with ResData For executable which works one language and without PO files.
bool GetText(OString &rReturn, const OString &nLangIndex, bool bDel=false)
Interface to write po entry to files as output streams.
void Merge(const OString &rMergeSrc, const OString &rDestinationFile)
std::vector< OString > m_vLines
PropParser(OString sInputFile, OString sLang, const bool bMergeMode)
void Extract(const OString &rPOFile)
Purpose: holds mandatory data to export a single res.
void writePoEntry(const OString &rExecutable, PoOfstream &rPoStream, const OString &rSourceFile, std::string_view rResType, const OString &rGroupId, const OString &rLocalId, const OString &rHelpText, const OString &rText, const PoEntry::TYPE eType)
Write out a PoEntry with attention to exceptions.
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)