diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2008-03-18 11:27:21 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2008-03-18 11:27:21 +0000 |
commit | 40c3966925d000e0d9110f7224993a0af00fa56c (patch) | |
tree | 036484176d9cf0db7767d0a3e6d4620f21926b0d /tools | |
parent | 0cddf53d5910d7816c35f60a74644ff42fd33979 (diff) |
INTEGRATION: CWS sb83 (1.1.2); FILE ADDED
2008/02/12 08:34:16 sb 1.1.2.1: #i86033# added tools::appendUnixShellWord
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/misc/appendunixshellword.cxx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tools/source/misc/appendunixshellword.cxx b/tools/source/misc/appendunixshellword.cxx new file mode 100644 index 000000000000..ecd7511ffbda --- /dev/null +++ b/tools/source/misc/appendunixshellword.cxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: appendunixshellword.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: vg $ $Date: 2008-03-18 12:27:21 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2008 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#include "precompiled_tools.hxx" +#include "sal/config.h" + +#if defined UNX + +#include <cstddef> + +#include "osl/diagnose.h" +#include "rtl/strbuf.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "sal/types.h" +#include "tools/appendunixshellword.hxx" + +namespace tools { + +void appendUnixShellWord( + rtl::OStringBuffer * accumulator, rtl::OString const & text) +{ + OSL_ASSERT(accumulator != NULL); + if (text.getLength() == 0) { + accumulator->append(RTL_CONSTASCII_STRINGPARAM("''")); + } else { + bool quoted = false; + for (sal_Int32 i = 0; i < text.getLength(); ++i) { + char c = text[i]; + if (c == '\'') { + if (quoted) { + accumulator->append('\''); + quoted = false; + } + accumulator->append(RTL_CONSTASCII_STRINGPARAM("\\'")); + } else { + if (!quoted) { + accumulator->append('\''); + quoted = true; + } + accumulator->append(c); + } + } + if (quoted) { + accumulator->append('\''); + } + } +} + +} + +#endif |