Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
utils.c
Go to the documentation of this file.
1/*
2 * utils.c
3 *
4 * little generally useful functions which aren't in any way special to PSSE.
5 *
6 * (c) 2019 Simon Brooke <simon@journeyman.cc>
7 * Licensed under GPL version 2.0, or, at your option, any later version.
8 */
9
10#include <ctype.h>
11#include <stdlib.h>
12#include <string.h>
13
14
15int index_of( char c, const char *s ) {
16 int i;
17
18 for ( i = 0; s[i] != c && s[i] != 0; i++ );
19
20 return s[i] == c ? i : -1;
21}
22
23char *trim( char *s ) {
24 int i;
25
26 for ( i = strlen( s ); ( isblank( s[i] ) || iscntrl( s[i] ) ) && i >= 0;
27 i-- ) {
28 s[i] = '\0';
29 }
30 for ( i = 0; s[i] != '\0' && ( isblank( s[i] ) || iscntrl( s[i] ) ); i++ );
31
32 return ( char * ) &s[i];
33}
int index_of(char c, const char *s)
Definition utils.c:15
char * trim(char *s)
Definition utils.c:23