xref: /trunk/main/xmlreader/source/span.cxx (revision b63233d8)
1*b725e8ebSAndrew Rist /**************************************************************
2*b725e8ebSAndrew Rist  *
3*b725e8ebSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b725e8ebSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b725e8ebSAndrew Rist  * distributed with this work for additional information
6*b725e8ebSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b725e8ebSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b725e8ebSAndrew Rist  * "License"); you may not use this file except in compliance
9*b725e8ebSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b725e8ebSAndrew Rist  *
11*b725e8ebSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b725e8ebSAndrew Rist  *
13*b725e8ebSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b725e8ebSAndrew Rist  * software distributed under the License is distributed on an
15*b725e8ebSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b725e8ebSAndrew Rist  * KIND, either express or implied.  See the License for the
17*b725e8ebSAndrew Rist  * specific language governing permissions and limitations
18*b725e8ebSAndrew Rist  * under the License.
19*b725e8ebSAndrew Rist  *
20*b725e8ebSAndrew Rist  *************************************************************/
21*b725e8ebSAndrew Rist 
22*b725e8ebSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
26cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
27cdf0e10cSrcweir #include "osl/diagnose.h"
28cdf0e10cSrcweir #include "rtl/textcvt.h"
29cdf0e10cSrcweir #include "rtl/textenc.h"
30cdf0e10cSrcweir #include "rtl/ustring.h"
31cdf0e10cSrcweir #include "rtl/ustring.hxx"
32cdf0e10cSrcweir #include "sal/types.h"
33cdf0e10cSrcweir #include "xmlreader/span.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace xmlreader {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace css = com::sun::star;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
convertFromUtf8() const43cdf0e10cSrcweir rtl::OUString Span::convertFromUtf8() const {
44cdf0e10cSrcweir     OSL_ASSERT(is());
45cdf0e10cSrcweir     rtl_uString * s = 0;
46cdf0e10cSrcweir     if (!rtl_convertStringToUString(
47cdf0e10cSrcweir             &s, begin, length, RTL_TEXTENCODING_UTF8,
48cdf0e10cSrcweir             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
49cdf0e10cSrcweir              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
50cdf0e10cSrcweir              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         throw css::uno::RuntimeException(
53cdf0e10cSrcweir             rtl::OUString(
54cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("cannot convert from UTF-8")),
55cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir     return rtl::OUString(s, SAL_NO_ACQUIRE);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir }
61