1 | /* $Id: strstrip.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - String Stripping and Trimming.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include <iprt/string.h>
|
---|
31 | #include <iprt/ctype.h>
|
---|
32 | #include <iprt/string.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Strips blankspaces from both ends of the string.
|
---|
37 | *
|
---|
38 | * @returns Pointer to first non-blank char in the string.
|
---|
39 | * @param psz The string to strip.
|
---|
40 | */
|
---|
41 | RTDECL(char *) RTStrStrip(char *psz)
|
---|
42 | {
|
---|
43 | /* left */
|
---|
44 | while (isspace(*psz))
|
---|
45 | psz++;
|
---|
46 |
|
---|
47 | /* right */
|
---|
48 | char *pszEnd = strchr(psz, '\0');
|
---|
49 | while (--pszEnd > psz && isspace(*pszEnd))
|
---|
50 | *pszEnd = '\0';
|
---|
51 |
|
---|
52 | return psz;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Strips blankspaces from the start of the string.
|
---|
58 | *
|
---|
59 | * @returns Pointer to first non-blank char in the string.
|
---|
60 | * @param psz The string to strip.
|
---|
61 | */
|
---|
62 | RTDECL(char *) RTStrStripL(const char *psz)
|
---|
63 | {
|
---|
64 | /* left */
|
---|
65 | while (isspace(*psz))
|
---|
66 | psz++;
|
---|
67 |
|
---|
68 | return (char *)psz;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Strips blankspaces from the end of the string.
|
---|
74 | *
|
---|
75 | * @returns psz.
|
---|
76 | * @param psz The string to strip.
|
---|
77 | */
|
---|
78 | RTDECL(char *) RTStrStripR(char *psz)
|
---|
79 | {
|
---|
80 | /* right */
|
---|
81 | char *pszEnd = strchr(psz, '\0');
|
---|
82 | while (--pszEnd > psz && isspace(*pszEnd))
|
---|
83 | *pszEnd = '\0';
|
---|
84 |
|
---|
85 | return psz;
|
---|
86 | }
|
---|
87 |
|
---|