1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscchar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
38 #ifndef _TABLE_HXX //autogen
39 #include <tools/table.hxx>
43 #include <tools/solar.h>
44 #include <rsctools.hxx>
46 #include <rtl/textcvt.h>
47 #include <rtl/textenc.h>
48 #include <rtl/alloc.h>
50 /*************************************************************************
52 |* RscChar::MakeChar()
54 |* Beschreibung Der String wird nach C-Konvention umgesetzt
55 |* Ersterstellung MM 20.03.91
56 |* Letzte Aenderung MM 20.03.91
58 *************************************************************************/
59 char * RscChar::MakeUTF8( char * pStr
, UINT16 nTextEncoding
)
61 sal_Size nMaxUniCodeBuf
= strlen( pStr
) + 1;
62 char * pOrgStr
= new char[ nMaxUniCodeBuf
];
63 sal_uInt32 nOrgLen
= 0;
65 if( nMaxUniCodeBuf
* 6 > 0x0FFFFF )
113 if( '0' <= *pStr
&& '7' >= *pStr
)
115 sal_uInt16 nChar
= 0;
117 while( '0' <= *pStr
&& '7' >= *pStr
&& i
!= 3 )
119 nChar
= nChar
* 8 + (BYTE
)*pStr
- (BYTE
)'0';
125 rtl_freeMemory( pOrgStr
);
127 // Wert zu gross, oder kein 3 Ziffern
133 else if( 'x' == *pStr
)
135 sal_uInt16 nChar
= 0;
138 while( isxdigit( *pStr
) && i
!= 2 )
140 if( isdigit( *pStr
) )
141 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'0';
142 else if( isupper( *pStr
) )
143 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'A' +10;
145 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'a' +10;
159 pOrgStr
[ nOrgLen
++ ] = c
;
164 sal_Unicode
* pUniCode
= new sal_Unicode
[ nMaxUniCodeBuf
];
165 rtl_TextToUnicodeConverter hConv
= rtl_createTextToUnicodeConverter( nTextEncoding
);
168 sal_Size nSrcCvtBytes
;
169 sal_Size nUniSize
= rtl_convertTextToUnicode( hConv
, 0,
171 pUniCode
, nMaxUniCodeBuf
,
172 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT
173 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT
174 | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
175 | RTL_TEXTTOUNICODE_FLAGS_FLUSH
,
179 rtl_destroyTextToUnicodeConverter( hConv
);
181 hConv
= rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8
);
182 // factor fo 6 is the maximum size of an UNICODE character as utf8
183 char * pUtf8
= (char *)rtl_allocateMemory( nUniSize
* 6 );
184 rtl_convertUnicodeToText( hConv
, 0,
187 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT
188 | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
189 | RTL_UNICODETOTEXT_FLAGS_FLUSH
,
193 rtl_destroyTextToUnicodeConverter( hConv
);
201 /*************************************************************************
203 |* RscChar::MakeChar()
205 |* Beschreibung Der String wird nach C-Konvention umgesetzt
206 |* Ersterstellung MM 20.03.91
207 |* Letzte Aenderung MM 20.03.91
209 *************************************************************************/
210 char * RscChar::MakeUTF8FromL( char * pStr
)
212 sal_Size nUniPos
= 0;
213 sal_Unicode
* pUniCode
= new sal_Unicode
[ strlen( pStr
) + 1 ];
259 if( '0' <= *pStr
&& '7' >= *pStr
)
263 while( '0' <= *pStr
&& '7' >= *pStr
&& i
!= 6 )
265 nChar
= nChar
* 8 + (BYTE
)*pStr
- (BYTE
)'0';
270 // Wert zu gross, oder kein 3 Ziffern
275 else if( 'x' == *pStr
|| 'X' == *pStr
)
280 while( isxdigit( *pStr
) && i
!= 4 )
282 if( isdigit( *pStr
) )
283 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'0';
284 else if( isupper( *pStr
) )
285 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'A' +10;
287 nChar
= nChar
* 16 + (BYTE
)*pStr
- (BYTE
)'a' +10;
302 pUniCode
[ nUniPos
++ ] = c
;
307 // factor fo 6 is the maximum size of an UNICODE character as utf8
308 sal_Size nMaxUtf8Len
= nUniPos
* 6;
309 if( nUniPos
* 6 > 0x0FFFFF )
312 char * pUtf8
= (char *)rtl_allocateMemory( nMaxUtf8Len
);
313 rtl_TextToUnicodeConverter hConv
= rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8
);
316 sal_Size nSrcCvtBytes
;
317 rtl_convertUnicodeToText( hConv
, 0,
320 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT
321 | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
322 | RTL_UNICODETOTEXT_FLAGS_FLUSH
,
326 rtl_destroyUnicodeToTextConverter( hConv
);