Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
0ec26858
Commit
0ec26858
authored
7 years ago
by
Peter W. Draper
Browse files
Options
Downloads
Patches
Plain Diff
Move general string trimming functions into tools
parent
5a826948
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!564
Yaml arrays
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/parser.c
+1
-37
1 addition, 37 deletions
src/parser.c
src/tools.c
+45
-0
45 additions, 0 deletions
src/tools.c
src/tools.h
+4
-0
4 additions, 0 deletions
src/tools.h
with
50 additions
and
37 deletions
src/parser.c
+
1
−
37
View file @
0ec26858
...
...
@@ -34,6 +34,7 @@
#include
"common_io.h"
#include
"error.h"
#include
"restart.h"
#include
"tools.h"
#define PARSER_COMMENT_STRING "#"
#define PARSER_COMMENT_CHAR '#'
...
...
@@ -57,43 +58,6 @@ static void find_duplicate_section(const struct swift_params *params,
const
char
*
section_name
);
static
int
lineNumber
=
0
;
/**
* @brief trim leading white space from a string.
*
* @param s the string.
* @result the result.
*/
static
char
*
trim_leading
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
while
(
isspace
(
*
s
))
s
++
;
return
s
;
}
/**
* @brief trim trailing white space from a string.
*
* @param s the string.
* @result the result.
*/
static
char
*
trim_trailing
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
char
*
end
=
s
+
strlen
(
s
)
-
1
;
while
(
isspace
(
*
end
))
end
--
;
*
(
end
+
1
)
=
'\0'
;
return
s
;
}
/**
* @brief trim leading and trailing white space from a string.
*
* @param s the string.
* @result the result.
*/
static
char
*
trim_both
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
return
trim_trailing
(
trim_leading
(
s
));
}
/**
* @brief parse a YAML list of strings returning a set of pointers to
* the strings.
...
...
This diff is collapsed.
Click to expand it.
src/tools.c
+
45
−
0
View file @
0ec26858
...
...
@@ -23,6 +23,7 @@
#include
"../config.h"
/* Some standard headers. */
#include
<ctype.h>
#include
<math.h>
#include
<stddef.h>
#include
<stdio.h>
...
...
@@ -728,3 +729,47 @@ long get_maxrss() {
getrusage
(
RUSAGE_SELF
,
&
usage
);
return
usage
.
ru_maxrss
;
}
/**
* @brief trim leading white space from a string.
*
* Returns pointer to first character.
*
* @param s the string.
* @result the result.
*/
char
*
trim_leading
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
while
(
isspace
(
*
s
))
s
++
;
return
s
;
}
/**
* @brief trim trailing white space from a string.
*
* Modifies the string by adding a NULL to the end.
*
* @param s the string.
* @result the result.
*/
char
*
trim_trailing
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
char
*
end
=
s
+
strlen
(
s
)
-
1
;
while
(
isspace
(
*
end
))
end
--
;
*
(
end
+
1
)
=
'\0'
;
return
s
;
}
/**
* @brief trim leading and trailing white space from a string.
*
* Can modify the string by adding a NULL to the end.
*
* @param s the string.
* @result the result.
*/
char
*
trim_both
(
char
*
s
)
{
if
(
s
==
NULL
||
strlen
(
s
)
<
2
)
return
s
;
return
trim_trailing
(
trim_leading
(
s
));
}
This diff is collapsed.
Click to expand it.
src/tools.h
+
4
−
0
View file @
0ec26858
...
...
@@ -54,4 +54,8 @@ int compare_particles(struct part a, struct part b, double threshold);
long
get_maxrss
(
void
);
char
*
trim_leading
(
char
*
s
);
char
*
trim_trailing
(
char
*
s
);
char
*
trim_both
(
char
*
s
);
#endif
/* SWIFT_TOOL_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment