1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_COMPHELPER_STRING_HXX
29 #define INCLUDED_COMPHELPER_STRING_HXX
30 
31 #include "sal/config.h"
32 
33 #include <cstddef>
34 #include "comphelper/comphelperdllapi.h"
35 #include "sal/types.h"
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 
39 namespace rtl { class OUString; }
40 
41 // rtl::OUString helper functions that are not widespread or mature enough to
42 // go into the stable URE API:
43 namespace comphelper { namespace string {
44 
45 /**
46    Replace the first occurrence of a substring with another string.
47 
48    @param source
49    The source string, in which the search will take place.
50 
51    @param from
52    The ASCII substring to search for.  Must point to at least fromLength ASCII
53    characters.
54 
55    @param fromLength
56    The length of the from substring.  Must not be negative.
57 
58    @param to
59    The string to use as replacement.
60 
61    @param beginAt
62    The index at which to begin the search.  Must be between zero and the length
63    of source, inclusive.
64 
65    @param replacedAt
66    If non-null, receives the starting index at which the replacement took place
67    or -1 if from was not found.
68 
69    @return
70    The resulting string, in which the replacement has taken place.
71 */
72 COMPHELPER_DLLPUBLIC rtl::OUString searchAndReplaceAsciiL(
73     rtl::OUString const & source, char const * from, sal_Int32 fromLength,
74     rtl::OUString const & to, sal_Int32 beginAt = 0,
75     sal_Int32 * replacedAt = NULL);
76 
77 /** replaces, in the given source string, all occurences of a given ASCII pattern
78     with another ASCII pattern
79 */
80 COMPHELPER_DLLPUBLIC ::rtl::OUString searchAndReplaceAllAsciiWithAscii(
81     const ::rtl::OUString& source, const sal_Char* from, const sal_Char* to,
82     const sal_Int32 beginAt = 0 );
83 
84 /** does an in-place replacement of the first occurance of a sub string with
85     another string
86 
87     @param source
88         the string to search and replace in.
89     @param asciiPattern
90         the ASCII sub string to search for. Must point to a 0-terminated string.
91     @param replace
92         The string to use as replacement.
93     @param beginAt
94         The index at which to begin the search.  Must be between zero and the length
95         of source, inclusive.
96 
97     @param replacedAt
98         If non-null, receives the starting index at which the replacement took place
99         or -1 if from was not found.
100 
101     @return
102         a reference to <code>source</code>
103 */
104 COMPHELPER_DLLPUBLIC ::rtl::OUString&
105     searchAndReplaceAsciiI( ::rtl::OUString & source, sal_Char const * asciiPattern,
106                             ::rtl::OUString const & replace, sal_Int32 beginAt = 0,
107                             sal_Int32 * replacedAt = NULL );
108 
109 /** Convert a sequence of strings to a single comma separated string.
110 
111     Note that no escaping of commas or anything fancy is done.
112 
113     @param i_rSeq   A list of strings to be concatenated.
114 
115     @return         A single string containing the concatenation of the given
116                     list, interspersed with the string ", ".
117  */
118 COMPHELPER_DLLPUBLIC ::rtl::OUString convertCommaSeparated(
119     ::com::sun::star::uno::Sequence< ::rtl::OUString > const & i_rSeq);
120 
121 /** Convert a single comma separated string to a sequence of strings.
122 
123     Note that no escaping of commas or anything fancy is done.
124 
125     @param i_rString    A string containing comma-separated words.
126 
127     @return         A sequence of strings resulting from splitting the given
128                     string at ',' tokens and stripping whitespace.
129  */
130 COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString >
131     convertCommaSeparated( ::rtl::OUString const & i_rString );
132 
133 } }
134 
135 #endif
136