source: rrlib_util/string.cpp @ 110:d1cbdd7d17fd

Last change on this file since 110:d1cbdd7d17fd was 110:d1cbdd7d17fd, checked in by Max Reichardt <mreichardt@…>, 6 years ago

Added slim collection of string utility functions as discussed with Tobias

File size: 3.1 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/util/string.cpp
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2014-03-10
27 *
28 */
29//----------------------------------------------------------------------
30#include "rrlib/util/string.h"
31
32//----------------------------------------------------------------------
33// External includes (system with <>, local with "")
34//----------------------------------------------------------------------
35
36//----------------------------------------------------------------------
37// Internal includes with ""
38//----------------------------------------------------------------------
39
40//----------------------------------------------------------------------
41// Debugging
42//----------------------------------------------------------------------
43#include <cassert>
44
45//----------------------------------------------------------------------
46// Namespace usage
47//----------------------------------------------------------------------
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace rrlib
53{
54namespace util
55{
56
57//----------------------------------------------------------------------
58// Forward declarations / typedefs / enums
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Const values
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Implementation
67//----------------------------------------------------------------------
68
69void TrimWhitespace(std::string& string)
70{
71  size_t start_pos = 0;
72  while (start_pos < string.length() && isspace(string[start_pos]))
73  {
74    start_pos++;
75  }
76  size_t end_pos = string.length();
77  while (end_pos > start_pos && isspace(string[end_pos - 1]))
78  {
79    end_pos--;
80  }
81  if (start_pos > 0 || end_pos < string.length())
82  {
83    string.assign(string, start_pos, end_pos - start_pos);
84  }
85}
86
87//----------------------------------------------------------------------
88// End of namespace declaration
89//----------------------------------------------------------------------
90}
91}
Note: See TracBrowser for help on using the repository browser.