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: string.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 #include "precompiled_comphelper.hxx"
32 #include "sal/config.h"
39 #include <rtl/ustring.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <sal/types.h>
43 #include <comphelper/string.hxx>
44 #include <comphelper/stlunosequence.hxx>
45 #include <comphelper/stl_types.hxx>
48 namespace comphelper
{ namespace string
{
50 rtl::OUString
searchAndReplaceAsciiL(
51 rtl::OUString
const & source
, char const * from
, sal_Int32 fromLength
,
52 rtl::OUString
const & to
, sal_Int32 beginAt
, sal_Int32
* replacedAt
)
54 sal_Int32 n
= source
.indexOfAsciiL(from
, fromLength
, beginAt
);
55 if (replacedAt
!= NULL
) {
58 return n
== -1 ? source
: source
.replaceAt(n
, fromLength
, to
);
61 ::rtl::OUString
searchAndReplaceAllAsciiWithAscii(
62 const ::rtl::OUString
& _source
, const sal_Char
* _from
, const sal_Char
* _to
,
63 const sal_Int32 _beginAt
)
65 sal_Int32 fromLength
= strlen( _from
);
66 sal_Int32 n
= _source
.indexOfAsciiL( _from
, fromLength
, _beginAt
);
70 ::rtl::OUString
dest( _source
);
71 ::rtl::OUString
to( ::rtl::OUString::createFromAscii( _to
) );
74 dest
= dest
.replaceAt( n
, fromLength
, to
);
75 n
= dest
.indexOfAsciiL( _from
, fromLength
, n
+ to
.getLength() );
82 ::rtl::OUString
& searchAndReplaceAsciiI(
83 ::rtl::OUString
& _source
, sal_Char
const * _asciiPattern
, ::rtl::OUString
const & _replace
,
84 sal_Int32 _beginAt
, sal_Int32
* _replacedAt
)
86 sal_Int32 fromLength
= strlen( _asciiPattern
);
87 sal_Int32 n
= _source
.indexOfAsciiL( _asciiPattern
, fromLength
, _beginAt
);
88 if ( _replacedAt
!= NULL
)
92 _source
= _source
.replaceAt( n
, fromLength
, _replace
);
97 // convert between sequence of string and comma separated string
99 ::rtl::OUString
convertCommaSeparated(
100 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> const& i_rSeq
)
102 ::rtl::OUStringBuffer buf
;
103 ::comphelper::intersperse(
104 ::comphelper::stl_begin(i_rSeq
), ::comphelper::stl_end(i_rSeq
),
105 ::comphelper::OUStringBufferAppender(buf
),
106 ::rtl::OUString::createFromAscii(", "));
107 return buf
.makeStringAndClear();
110 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
111 convertCommaSeparated( ::rtl::OUString
const& i_rString
)
113 std::vector
< ::rtl::OUString
> vec
;
117 i_rString
.getToken(0, static_cast<sal_Unicode
> (','), idx
);
119 if (kw
.getLength() > 0) {
123 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> kws(vec
.size());
124 std::copy(vec
.begin(), vec
.end(), stl_begin(kws
));