On Tue, Sep 24, 2013 at 08:07:59PM +0300, K.Misha wrote:
> This is original file:
> 
> 
> 
>  
> 
> And this is my return str1:
> 
> 

I see only empty lines here, no text, so I don't get what the difference
could be. But are you watching the value of str1 inside the debugger, or
just printing that to a console?

The code attached has non-ASCII characters, it prints the string
returned by OString::getStr() in the standard output; it "works" (all
characters are displayed) fine on Linux, but on Windows you may have to
do system specific stuff (didn't try it right now).
 

Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/

#include <cppuhelper/bootstrap.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>

#include <iostream>

namespace css = ::com::sun::star;
namespace ControlCharacter = css::text::ControlCharacter;
using rtl::OUString;


static const char DummyText[] = "Als Gregor Samsa eines Morgens aus unruhigen 
Träumen erwachte, fand er sich in seinem Bett zu einem ungeheueren Ungeziefer 
verwandelt. Er lag auf seinem panzerartig harten Rücken und sah, wenn er den 
Kopf ein wenig hob, seinen gewölbten, braunen, von bogenförmigen Versteifungen 
geteilten Bauch, auf dessen Höhe sich die Bettdecke, zum gänzlichen 
Niedergleiten bereit, kaum noch erhalten konnte. Seine vielen, im Vergleich zu 
seinem sonstigen Umfang kläglich dünnen Beine flimmerten ihm hilflos vor den 
Augen.\n»Was ist mit mir geschehen?« dachte er. Es war kein Traum, sein Zimmer, 
ein richtiges, nur etwas zu kleines Menschenzimmer, lag ruhig zwischen den vier 
wohlbekannten Wänden, über dem Tisch, auf dem eine auseinandergepackte 
Musterkollektion von Tuchwaren ausgebreitet war - Samsa war Reisender -, hing 
das Bild, das er vor kurzem aus einer illustrierten Zeitschrift ausgeschnitten 
und in einem hübschen, vergoldeten Rahmen untergebracht hatte. Es stellte eine 
Dame dar, die, mit einem Pelzhut und einer Pelzboa versehen, aufrecht dasaß und 
einen schweren Pelzmuff, in dem ihr ganzer Unterarm verschwunden war, dem 
Beschauer entgegenhob.\nGregors Blick richtete sich dann zum Fenster, und das 
trübe Wetter - man hörte Regentropfen auf das Fensterblech aufschlagen - machte 
ihn ganz melancholisch. »Wie wäre es, wenn ich noch ein wenig weiterschliefe 
und alle Narrheiten vergäße,« dachte er, aber das war gänzlich undurchführbar, 
denn er war gewöhnt, auf der rechten Seite zu schlafen, konnte sich aber in 
seinem gegenwärtigen Zustand nicht in diese Lage bringen. Mit welcher Kraft er 
sich auch auf die rechte Seite warf, immer wieder schaukelte er in die 
Rückenlage zurück. Er versuchte es wohl hundertmal, schloß die Augen, um die 
zappelnden Beine nicht sehen zu müssen und ließ erst ab, als er in der Seite 
einen noch nie gefühlten, leichten, dumpfen Schmerz zu fühlen begann.";


template < typename T >
css::uno::Reference< T >
LoadComponent(
    const css::uno::Reference< css::uno::XComponentContext > &xContext,
    css::uno::Reference< css::frame::XComponentLoader  > &xLoader,
    const rtl::OUString &rURL,
    const css::uno::Sequence < css::beans::PropertyValue > &rMediaDescriptor
    = css::uno::Sequence < css::beans::PropertyValue >(),
    const rtl::OUString &rFrame
    = OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ),
    sal_Int32 nFrameSearchFlag = css::frame::FrameSearchFlag::ALL )
throw ( css::uno::Exception )
{
    css::uno::Reference < T > xDoc;

    try
    {
        if ( !xLoader.is() )
        {
            xLoader.set(
                xContext->getServiceManager()->createInstanceWithContext(
                    OUString( RTL_CONSTASCII_USTRINGPARAM(
                                  "com.sun.star.frame.Desktop" ) ), xContext ),
                css::uno::UNO_QUERY_THROW );
        }

        xDoc.set(
            xLoader->loadComponentFromURL(
                rURL,
                rFrame,
                nFrameSearchFlag,
                rMediaDescriptor ),
            css::uno::UNO_QUERY_THROW );

    }
    catch ( const css::uno::Exception &e )
    {
        std::cerr << "Caught an exception: "
                  << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 
).getStr()
                  << '\n';
        throw e;
    }

    return xDoc;
}



int main( void )
{
    try
    {
        css::uno::Reference< css::uno::XComponentContext > xContext( 
cppu::bootstrap() );
        css::uno::Reference< css::frame::XComponentLoader  > xLoader;

        css::uno::Reference < css::text::XTextDocument > xDoc(
            LoadComponent< css::text::XTextDocument >(
                xContext,
                xLoader,
                OUString( RTL_CONSTASCII_USTRINGPARAM( 
"private:factory/swriter" ) ) ) );

        css::uno::Reference < css::text::XText > xText( xDoc->getText() );

        // insert some text
        const OUString sDummyText( DummyText, sizeof( DummyText ) - 1, 
RTL_TEXTENCODING_UTF8 );
        sal_Int32 nIndex( 0 );
        do
        {
            OUString sParagraph = sDummyText.getToken( 0, sal_Unicode( '\n' ), 
nIndex );
            xText->insertString( xText->getEnd(), sParagraph, sal_False );
            xText->insertControlCharacter( xText->getEnd(), 
ControlCharacter::PARAGRAPH_BREAK, sal_False );
        }
        while ( nIndex >= 0 );


        // print the text
        const char *pzstr = rtl::OUStringToOString( xText->getString(), 
RTL_TEXTENCODING_UTF8 ).getStr();
        std::cout << pzstr << '\n';

    }
    catch ( const css::uno::Exception &e )
    {
        std::cerr << "Caught an exception: "
                  << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 
).getStr()
                  << '\n';
    }

    return 0;
}

Attachment: pgpavzw6BltJJ.pgp
Description: PGP signature

Reply via email to