1 | /* $Id: strstrip.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - String Stripping and Trimming.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <iprt/string.h>
|
---|
42 | #include "internal/iprt.h"
|
---|
43 |
|
---|
44 | #include <iprt/ctype.h>
|
---|
45 | #include <iprt/string.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Strips blankspaces from both ends of the string.
|
---|
50 | *
|
---|
51 | * @returns Pointer to first non-blank char in the string.
|
---|
52 | * @param psz The string to strip.
|
---|
53 | */
|
---|
54 | RTDECL(char *) RTStrStrip(char *psz)
|
---|
55 | {
|
---|
56 | /* left */
|
---|
57 | while (RT_C_IS_SPACE(*psz))
|
---|
58 | psz++;
|
---|
59 |
|
---|
60 | /* right */
|
---|
61 | char *pszEnd = strchr(psz, '\0');
|
---|
62 | while (--pszEnd > psz && RT_C_IS_SPACE(*pszEnd))
|
---|
63 | *pszEnd = '\0';
|
---|
64 |
|
---|
65 | return psz;
|
---|
66 | }
|
---|
67 | RT_EXPORT_SYMBOL(RTStrStrip);
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Strips blankspaces from the start of the string.
|
---|
72 | *
|
---|
73 | * @returns Pointer to first non-blank char in the string.
|
---|
74 | * @param psz The string to strip.
|
---|
75 | */
|
---|
76 | RTDECL(char *) RTStrStripL(const char *psz)
|
---|
77 | {
|
---|
78 | /* left */
|
---|
79 | while (RT_C_IS_SPACE(*psz))
|
---|
80 | psz++;
|
---|
81 |
|
---|
82 | return (char *)psz;
|
---|
83 | }
|
---|
84 | RT_EXPORT_SYMBOL(RTStrStripL);
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Strips blankspaces from the end of the string.
|
---|
89 | *
|
---|
90 | * @returns psz.
|
---|
91 | * @param psz The string to strip.
|
---|
92 | */
|
---|
93 | RTDECL(char *) RTStrStripR(char *psz)
|
---|
94 | {
|
---|
95 | /* right */
|
---|
96 | char *pszEnd = strchr(psz, '\0');
|
---|
97 | while (--pszEnd > psz && RT_C_IS_SPACE(*pszEnd))
|
---|
98 | *pszEnd = '\0';
|
---|
99 |
|
---|
100 | return psz;
|
---|
101 | }
|
---|
102 | RT_EXPORT_SYMBOL(RTStrStripR);
|
---|
103 |
|
---|