1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_COMPHELPER_STRING_HXX 25 #define INCLUDED_COMPHELPER_STRING_HXX 26 27 #include "sal/config.h" 28 29 #include <cstddef> 30 #include "comphelper/comphelperdllapi.h" 31 #include "sal/types.h" 32 #include <com/sun/star/uno/Sequence.hxx> 33 34 35 namespace rtl { class OUString; } 36 37 // rtl::OUString helper functions that are not widespread or mature enough to 38 // go into the stable URE API: 39 namespace comphelper { namespace string { 40 41 /** 42 Replace the first occurrence of a substring with another string. 43 44 @param source 45 The source string, in which the search will take place. 46 47 @param from 48 The ASCII substring to search for. Must point to at least fromLength ASCII 49 characters. 50 51 @param fromLength 52 The length of the from substring. Must not be negative. 53 54 @param to 55 The string to use as replacement. 56 57 @param beginAt 58 The index at which to begin the search. Must be between zero and the length 59 of source, inclusive. 60 61 @param replacedAt 62 If non-null, receives the starting index at which the replacement took place 63 or -1 if from was not found. 64 65 @return 66 The resulting string, in which the replacement has taken place. 67 */ 68 COMPHELPER_DLLPUBLIC rtl::OUString searchAndReplaceAsciiL( 69 rtl::OUString const & source, char const * from, sal_Int32 fromLength, 70 rtl::OUString const & to, sal_Int32 beginAt = 0, 71 sal_Int32 * replacedAt = NULL); 72 73 /** replaces, in the given source string, all occurrences of a given ASCII pattern 74 with another ASCII pattern 75 */ 76 COMPHELPER_DLLPUBLIC ::rtl::OUString searchAndReplaceAllAsciiWithAscii( 77 const ::rtl::OUString& source, const sal_Char* from, const sal_Char* to, 78 const sal_Int32 beginAt = 0 ); 79 80 /** does an in-place replacement of the first occurrence of a sub string with 81 another string 82 83 @param source 84 the string to search and replace in. 85 @param asciiPattern 86 the ASCII sub string to search for. Must point to a 0-terminated string. 87 @param replace 88 The string to use as replacement. 89 @param beginAt 90 The index at which to begin the search. Must be between zero and the length 91 of source, inclusive. 92 93 @param replacedAt 94 If non-null, receives the starting index at which the replacement took place 95 or -1 if from was not found. 96 97 @return 98 a reference to <code>source</code> 99 */ 100 COMPHELPER_DLLPUBLIC ::rtl::OUString& 101 searchAndReplaceAsciiI( ::rtl::OUString & source, sal_Char const * asciiPattern, 102 ::rtl::OUString const & replace, sal_Int32 beginAt = 0, 103 sal_Int32 * replacedAt = NULL ); 104 105 /** Convert a sequence of strings to a single comma separated string. 106 107 Note that no escaping of commas or anything fancy is done. 108 109 @param i_rSeq A list of strings to be concatenated. 110 111 @return A single string containing the concatenation of the given 112 list, interspersed with the string ", ". 113 */ 114 COMPHELPER_DLLPUBLIC ::rtl::OUString convertCommaSeparated( 115 ::com::sun::star::uno::Sequence< ::rtl::OUString > const & i_rSeq); 116 117 /** Convert a single comma separated string to a sequence of strings. 118 119 Note that no escaping of commas or anything fancy is done. 120 121 @param i_rString A string containing comma-separated words. 122 123 @return A sequence of strings resulting from splitting the given 124 string at ',' tokens and stripping whitespace. 125 */ 126 COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > 127 convertCommaSeparated( ::rtl::OUString const & i_rString ); 128 129 } } 130 131 #endif 132