1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "precompiled_comphelper.hxx"
29 #include "sal/config.h"
36 #include <rtl/ustring.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <sal/types.h>
40 #include <comphelper/string.hxx>
41 #include <comphelper/stlunosequence.hxx>
42 #include <comphelper/stl_types.hxx>
45 namespace comphelper
{ namespace string
{
47 rtl::OUString
searchAndReplaceAsciiL(
48 rtl::OUString
const & source
, char const * from
, sal_Int32 fromLength
,
49 rtl::OUString
const & to
, sal_Int32 beginAt
, sal_Int32
* replacedAt
)
51 sal_Int32 n
= source
.indexOfAsciiL(from
, fromLength
, beginAt
);
52 if (replacedAt
!= NULL
) {
55 return n
== -1 ? source
: source
.replaceAt(n
, fromLength
, to
);
58 ::rtl::OUString
searchAndReplaceAllAsciiWithAscii(
59 const ::rtl::OUString
& _source
, const sal_Char
* _from
, const sal_Char
* _to
,
60 const sal_Int32 _beginAt
)
62 sal_Int32 fromLength
= strlen( _from
);
63 sal_Int32 n
= _source
.indexOfAsciiL( _from
, fromLength
, _beginAt
);
67 ::rtl::OUString
dest( _source
);
68 ::rtl::OUString
to( ::rtl::OUString::createFromAscii( _to
) );
71 dest
= dest
.replaceAt( n
, fromLength
, to
);
72 n
= dest
.indexOfAsciiL( _from
, fromLength
, n
+ to
.getLength() );
79 ::rtl::OUString
& searchAndReplaceAsciiI(
80 ::rtl::OUString
& _source
, sal_Char
const * _asciiPattern
, ::rtl::OUString
const & _replace
,
81 sal_Int32 _beginAt
, sal_Int32
* _replacedAt
)
83 sal_Int32 fromLength
= strlen( _asciiPattern
);
84 sal_Int32 n
= _source
.indexOfAsciiL( _asciiPattern
, fromLength
, _beginAt
);
85 if ( _replacedAt
!= NULL
)
89 _source
= _source
.replaceAt( n
, fromLength
, _replace
);
94 // convert between sequence of string and comma separated string
96 ::rtl::OUString
convertCommaSeparated(
97 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> const& i_rSeq
)
99 ::rtl::OUStringBuffer buf
;
100 ::comphelper::intersperse(
101 ::comphelper::stl_begin(i_rSeq
), ::comphelper::stl_end(i_rSeq
),
102 ::comphelper::OUStringBufferAppender(buf
),
103 ::rtl::OUString::createFromAscii(", "));
104 return buf
.makeStringAndClear();
107 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
108 convertCommaSeparated( ::rtl::OUString
const& i_rString
)
110 std::vector
< ::rtl::OUString
> vec
;
114 i_rString
.getToken(0, static_cast<sal_Unicode
> (','), idx
);
116 if (kw
.getLength() > 0) {
120 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> kws(vec
.size());
121 std::copy(vec
.begin(), vec
.end(), stl_begin(kws
));