fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / rsc / source / tools / rscchar.cxx
blobe216c13c09e5e8ff7f40b8e40f6e0f74f05fd86f
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 <stdio.h>
21 #include <string.h>
22 #include <ctype.h>
24 #include <rsctools.hxx>
26 #include <rtl/textcvt.h>
27 #include <rtl/textenc.h>
28 #include <rtl/alloc.h>
30 char * RscChar::MakeUTF8( char * pStr, sal_uInt16 nTextEncoding )
32 sal_Size nMaxUniCodeBuf = strlen( pStr ) + 1;
33 if( nMaxUniCodeBuf * 6 > 0x0FFFFF )
34 RscExit( 10 );
36 char * pOrgStr = new char[ nMaxUniCodeBuf ];
37 sal_uInt32 nOrgLen = 0;
39 char cOld = '1';
40 while( cOld != 0 )
42 char c;
44 if( *pStr == '\\' )
46 ++pStr;
47 switch( *pStr )
49 case 'a':
50 c = '\a';
51 break;
52 case 'b':
53 c = '\b';
54 break;
55 case 'f':
56 c = '\f';
57 break;
58 case 'n':
59 c = '\n';
60 break;
61 case 'r':
62 c = '\r';
63 break;
64 case 't':
65 c = '\t';
66 break;
67 case 'v':
68 c = '\v';
69 break;
70 case '\\':
71 c = '\\';
72 break;
73 case '?':
74 c = '\?';
75 break;
76 case '\'':
77 c = '\'';
78 break;
79 case '\"':
80 c = '\"';
81 break;
82 default:
84 if( '0' <= *pStr && '7' >= *pStr )
86 sal_uInt16 nChar = 0;
87 int i = 0;
88 while( '0' <= *pStr && '7' >= *pStr && i != 3 )
90 nChar = nChar * 8 + (sal_uInt8)*pStr - (sal_uInt8)'0';
91 ++pStr;
92 i++;
94 if( nChar > 255 )
96 // value is too big, or more than 3 digits
97 delete [] pOrgStr;
98 return NULL;
100 c = (char)nChar;
101 pStr--;
103 else if( 'x' == *pStr )
105 sal_uInt16 nChar = 0;
106 int i = 0;
107 ++pStr;
108 while( isxdigit( *pStr ) && i != 2 )
110 if( isdigit( *pStr ) )
111 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'0';
112 else if( isupper( *pStr ) )
113 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'A' +10;
114 else
115 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'a' +10;
116 ++pStr;
117 i++;
119 c = (char)nChar;
120 pStr--;
122 else
123 c = *pStr;
127 else
128 c = *pStr;
129 pOrgStr[ nOrgLen++ ] = c;
130 cOld = *pStr;
131 pStr++;
134 sal_Unicode * pUniCode = new sal_Unicode[ nMaxUniCodeBuf ];
135 rtl_TextToUnicodeConverter hConv = rtl_createTextToUnicodeConverter( nTextEncoding );
137 sal_uInt32 nInfo;
138 sal_Size nSrcCvtBytes;
139 sal_Size nUniSize = rtl_convertTextToUnicode( hConv, 0,
140 pOrgStr, nOrgLen,
141 pUniCode, nMaxUniCodeBuf,
142 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT
143 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT
144 | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
145 | RTL_TEXTTOUNICODE_FLAGS_FLUSH,
146 &nInfo,
147 &nSrcCvtBytes );
149 rtl_destroyTextToUnicodeConverter( hConv );
150 delete[] pOrgStr, pOrgStr = 0;
152 hConv = rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8 );
153 // factor of 6 is the maximum size of an UNICODE character as utf8
154 char * pUtf8 = static_cast<char *>(rtl_allocateMemory( nUniSize * 6 ));
155 rtl_convertUnicodeToText( hConv, 0,
156 pUniCode, nUniSize,
157 pUtf8, nUniSize * 6,
158 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT
159 | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
160 | RTL_UNICODETOTEXT_FLAGS_FLUSH,
161 &nInfo,
162 &nSrcCvtBytes );
164 rtl_destroyTextToUnicodeConverter( hConv );
165 delete[] pUniCode, pUniCode = 0;
167 return pUtf8;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */