From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/mt/split.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/mt/split.h (limited to 'src/mt/split.h') diff --git a/src/mt/split.h b/src/mt/split.h new file mode 100644 index 0000000..52e66e3 --- /dev/null +++ b/src/mt/split.h @@ -0,0 +1,72 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef MSPLITH +#define MSPLITH + +#include + +inline sref Skip(const sref& a,const charset& ws=cset_ws) { + return a.right_first_not_of(ws); +} + +inline sref Trim(const sref& a,const charset& ws=cset_ws) { + return a.right_first_not_of(ws).leftand_last_not_of(ws); +} + +inline sref Trim(const sref& a,const bracket& enc,const charset& ws=cset_ws) { + sref s=a.right_first_not_of(ws).leftand_last_not_of(ws); + while(s.nempty()&&s.skip(enc)==s.size()) + s=s(1,-3).right_first_not_of(ws).leftand_last_not_of(ws); + return s; +} + +inline sref First(const sref& a,const charset& ws=cset_ws) { + return a.right_first_not_of(ws).left_first_of(ws); +} + +inline sref Rest(const sref& a,const charset& ws=cset_ws) { + return a.right_first_not_of(ws).right_first_of(ws).right_first_not_of(ws); +} + +inline sref Last(const sref& a,const charset& ws=cset_ws) { + sref p=a.leftand_last_not_of(ws); + sref e=p.past_last_of(ws); + return e.nempty()?e:p; +} + +inline int Split(sref& first,sref& rest,const charset& ws=cset_ws) { + rest=rest.right_first_not_of(ws); + int s=rest.find_of(ws); + first=rest.left(s); + rest=rest.right(s); + return first.nempty(); +} + +inline int Splitln(sref& first,sref& rest) { + int s=rest.find_of(cset_newl); + first=rest.left(s); + rest=rest.right(s).past_nl(); + return first.begin()!=rest.begin(); +} + +typedef int (*split_t)(sref& first,sref& rest); + +#endif + -- cgit v1.2.3