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 #include "precompiled_tools.hxx" 25 #include "sal/config.h" 26 27 #if defined UNX 28 29 #include <cstddef> 30 31 #include "osl/diagnose.h" 32 #include "rtl/strbuf.hxx" 33 #include "rtl/string.h" 34 #include "rtl/string.hxx" 35 #include "sal/types.h" 36 #include "tools/appendunixshellword.hxx" 37 38 namespace tools { 39 appendUnixShellWord(rtl::OStringBuffer * accumulator,rtl::OString const & text)40void appendUnixShellWord( 41 rtl::OStringBuffer * accumulator, rtl::OString const & text) 42 { 43 OSL_ASSERT(accumulator != NULL); 44 if (text.getLength() == 0) { 45 accumulator->append(RTL_CONSTASCII_STRINGPARAM("''")); 46 } else { 47 bool quoted = false; 48 for (sal_Int32 i = 0; i < text.getLength(); ++i) { 49 char c = text[i]; 50 if (c == '\'') { 51 if (quoted) { 52 accumulator->append('\''); 53 quoted = false; 54 } 55 accumulator->append(RTL_CONSTASCII_STRINGPARAM("\\'")); 56 } else { 57 if (!quoted) { 58 accumulator->append('\''); 59 quoted = true; 60 } 61 accumulator->append(c); 62 } 63 } 64 if (quoted) { 65 accumulator->append('\''); 66 } 67 } 68 } 69 70 } 71 72 #endif 73