2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @author Dawid Kozinski (d.kozinski@samsung.com)
21 * @brief Trimming functions taken from
22 * http://stackoverflow.com/questions/122616/how-do-i-trim-leading-trailing-whitespace-in-a-standard-way
31 * @brief trim from start, i.e. left side
32 * Trimming leading whitespace from string
37 char *plugin_internal_ltrim(char *s);
40 * @brief trim from end, i.e. right side
41 * Trimming trailing whitespace from string
46 char *plugin_internal_rtrim(char *s);
49 * @brief trim from both ends
50 * Trimming leading and trailing whitespace from string
54 char *plugin_internal_trim(char *s);
56 /* ////////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////// */
59 char *plugin_internal_ltrim(char *s)
63 while (isspace(*newstart)) {
67 /* newstart points to first non-whitespace char (which might be '\0') */
68 memmove(s, newstart, strlen(newstart) + 1); /* don't forget to move the '\0' terminator */
73 char *plugin_internal_rtrim(char *s)
75 char *end = s + strlen(s);
77 /* find the last non-whitespace character */
78 while ((end != s) && isspace(*(end - 1))) {
82 /* at this point either (end == s) and s is either empty or all whitespace
83 so it needs to be made empty, or
84 end points just past the last non-whitespace character (it might point
85 at the '\0' terminator, in which case there's no problem writing
92 char *plugin_internal_trim(char *s)
94 return plugin_internal_rtrim(plugin_internal_ltrim(s));