blob: 7b123261b1a7d6ad05196258e6f2ca3fa2f742c9 [file] [log] [blame]
Manuel Novoa III cad53642003-03-19 09:13:01 +00001/* vi: set sw=4 ts=4: */
2/*
3 * skip_whitespace implementation for busybox
4 *
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
6 *
Rob Landleyea224be2006-06-18 20:20:07 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Manuel Novoa III cad53642003-03-19 09:13:01 +00008 */
9
Manuel Novoa III cad53642003-03-19 09:13:01 +000010#include "libbb.h"
11
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000012char* FAST_FUNC skip_whitespace(const char *s)
Manuel Novoa III cad53642003-03-19 09:13:01 +000013{
Denys Vlasenkof125b6d2009-10-22 19:41:45 +020014 /* In POSIX/C locale (the only locale we care about: do we REALLY want
15 * to allow Unicode whitespace in, say, .conf files? nuts!)
16 * isspace is only these chars: "\t\n\v\f\r" and space.
17 * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
18 * Use that.
19 */
20 while (*s == ' ' || (unsigned char)(*s - 9) <= (13 - 9))
21 s++;
Manuel Novoa III cad53642003-03-19 09:13:01 +000022
Rob Landleyea224be2006-06-18 20:20:07 +000023 return (char *) s;
Manuel Novoa III cad53642003-03-19 09:13:01 +000024}
Denis Vlasenko0de93752006-12-26 02:51:29 +000025
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000026char* FAST_FUNC skip_non_whitespace(const char *s)
Denis Vlasenko0de93752006-12-26 02:51:29 +000027{
Denys Vlasenkof125b6d2009-10-22 19:41:45 +020028 while (*s != '\0' && *s != ' ' && (unsigned char)(*s - 9) > (13 - 9))
29 s++;
Denis Vlasenko0de93752006-12-26 02:51:29 +000030
31 return (char *) s;
32}