/************************************************************************* * * 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