mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-16 14:15:46 +01:00
make wtrimspace() use internal api
make wtrimspace() use wings' own function for a task semantics change: it used to segfault given null, now it returns null. this doesn't affect any current use (there's exactly one..), and i see no harm in this behaviour, and perceive this to be more natural.
This commit is contained in:
committed by
Carlos R. Mafra
parent
109e504262
commit
9911ecd985
@@ -257,7 +257,7 @@ void wrelease(void *ptr);
|
|||||||
void* wretain(void *ptr);
|
void* wretain(void *ptr);
|
||||||
|
|
||||||
char *wstrdup(const char *str);
|
char *wstrdup(const char *str);
|
||||||
char* wstrndup(char *str, size_t len);
|
char* wstrndup(const char *str, size_t len);
|
||||||
|
|
||||||
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
|
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
|
||||||
* str1 and str2 can be any strings including static and constant strings.
|
* str1 and str2 can be any strings including static and constant strings.
|
||||||
@@ -283,7 +283,7 @@ char* wtokenjoin(char **list, int count);
|
|||||||
|
|
||||||
void wtokenfree(char **tokens, int count);
|
void wtokenfree(char **tokens, int count);
|
||||||
|
|
||||||
char* wtrimspace(char *s);
|
char* wtrimspace(const char *s);
|
||||||
|
|
||||||
|
|
||||||
WMRange wmkrange(int start, int count);
|
WMRange wmkrange(int start, int count);
|
||||||
|
|||||||
@@ -145,22 +145,20 @@ void wtokenfree(char **tokens, int count)
|
|||||||
wfree(tokens);
|
wfree(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wtrimspace(char *s)
|
char *wtrimspace(const char *s)
|
||||||
{
|
{
|
||||||
char *t;
|
char *t;
|
||||||
char *c;
|
|
||||||
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
while (isspace(*s) && *s)
|
while (isspace(*s) && *s)
|
||||||
s++;
|
s++;
|
||||||
t = s + strlen(s) - 1;
|
t = (char *)s + strlen(s) - 1;
|
||||||
while (t > s && isspace(*t))
|
while (t > s && isspace(*t))
|
||||||
t--;
|
t--;
|
||||||
|
|
||||||
c = wmalloc(t - s + 2);
|
return wstrndup(s, t - s + 1);
|
||||||
memcpy(c, s, t - s + 1);
|
|
||||||
c[t - s + 1] = 0;
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wstrdup(const char *str)
|
char *wstrdup(const char *str)
|
||||||
@@ -170,7 +168,7 @@ char *wstrdup(const char *str)
|
|||||||
return strcpy(wmalloc(strlen(str) + 1), str);
|
return strcpy(wmalloc(strlen(str) + 1), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wstrndup(char *str, size_t len)
|
char *wstrndup(const char *str, size_t len)
|
||||||
{
|
{
|
||||||
char *copy;
|
char *copy;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user