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/ops/string.cc | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 src/ops/string.cc (limited to 'src/ops/string.cc') diff --git a/src/ops/string.cc b/src/ops/string.cc new file mode 100644 index 0000000..76b7e72 --- /dev/null +++ b/src/ops/string.cc @@ -0,0 +1,274 @@ +/************************************************************************* + * + * 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 + */ + +#include +#include +#include + +OP2_IMPL(intersect) { mset a(L),b(R),c; c.Intersection(a,b); out<0&&Split(first,rest)); + out<=0);} +OP2_IMPL(cntn) {out<<(L.find(R,cset_lcase)>=0);} + +OP2_IMPL(concat) {out< \n" + ); + OP_ADD(32,skipws, + "Skip whitespace\n" + "Syntax: skipws (string)\n" + "Returns: (string)\n" + "\n" + "Skips trailing whitespace\n" + ); + + OP_ADD(32,first, + "First element in list\n" + "Syntax: first (list)\n" + "Returns: (string)\n" + "\n" + "Elements are separated by whitespace\n" + ); + OP_ADD(32,last, + "Last element in list\n" + "Syntax: last (list)\n" + "Returns: (string)\n" + "\n" + "Elements are separated by whitespace\n" + ); + OP_ADD(32,rest, + "Rest of elements in list\n" + "Syntax: rest (list)\n" + "Returns: (list)\n" + "\n" + "Elements are separated by whitespace\n" + ); + OP_ADD(32,count, + "Count elements in list\n" + "Syntax: count (list)\n" + "Returns: (int)\n" + "\n" + "Elements are separated by whitespace\n" + ); + + OP_ADD(30,nth, + "Nth element in list\n" + "Syntax: (list) nth (int)\n" + "Returns: (string)\n" + "\n" + "First element is denoted 1\n" + "Elements out of range returns empty\n" + "Elements are separated by whitespace\n" + ); + OP_ADD(30,which, + "Which element in list\n" + "Syntax: (list) a which (string) b\n" + "Returns: (int)\n" + "\n" + "Which element in a is b (0 if not found)\n" + "First element is denoted 1\n" + "Elements are separated by whitespace\n" + ); + + OP_ADD(28,left, + "Left of substring\n" + "Syntax: (string) a left (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the left of first b, of a if b not found in a\n" + ); + OP_ADD(28,leftand, + "Left of substring inclusive\n" + "Syntax: (string) a leftand (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the left of first b inclusive, of a if b not found in a\n" + ); + OP_ADD(28,right, + "Right of substring inclusive\n" + "Syntax: (string) a right (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the right of first b inclusive, of empty if b not found in a\n" + ); + OP_ADD(28,past, + "Right of substring\n" + "Syntax: (string) a past (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the right of first b, of empty if b not found in a\n" + ); + + OP_ADD(28,rleft, + "Left of substring (reversed)\n" + "Syntax: (string) a rleft (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the left of last b, of a if b not found in a\n" + ); + OP_ADD(28,rleftand, + "Left of substring inclusive, (reversed)\n" + "Syntax: (string) a rleftand (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the left of last b inclusive, of a if b not found in a\n" + ); + OP_ADD(28,rright, + "Right of substring inclusive (reversed)\n" + "Syntax: (string) a rright (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the right of last b inclusive, of empty if b not found in a\n" + ); + OP_ADD(28,rpast, + "Right of substring (reversed)\n" + "Syntax: (string) a rpast (string) b\n" + "Returns: (string)\n" + "\n" + "Everything in a to the right of last b, of empty if b not found in a\n" + ); + + OP_ADDN(24,concat,++, + "String concatenation\n" + "Syntax: (string) ++ (string)\n" + "Returns: (string)\n" + ); + OP_ADDN(24,concats,+++, + "List concatenation\n" + "Syntax: (list) +++ (list)\n" + "Returns: (list)\n" + "\n" + "Lists are concatenated with space\n" + ); + + OP_ADD(18,cnt, + "Contains substring\n" + "Syntax: (string) a cnt (string) b\n" + "Returns: (int)\n" + "\n" + "Nonzero if b found in a\n" + ); + OP_ADD(18,cntn, + "Contains substring, case insensitive\n" + "Syntax: (string) a cnt (string) b\n" + "Returns: (int)\n" + "\n" + "Nonzero if b found in a\n" + ); + OP_ADD(18,eqnn, + "NN-style equal\n" + "Syntax: (string) eqnn (string)\n" + "Returns: (int)\n" + "\n" + "NN-style converts names to \n" + ); + OP_ADD(18,nenn, + "NN-style not equal\n" + "Syntax: (string) eqnn (string)\n" + "Returns: (int)\n" + "\n" + "NN-style converts names to \n" + ); + + OP_ADDN(10,intersect,&&&, + "List intersection\n" + "Syntax: (list) a &&& (list) b\n" + "Returns: (list)\n" + "\n" + "Finds the set intersection of a and b\n" + ); + OP_ADDN(9,difference,---, + "List difference\n" + "Syntax: (list) a &&& (list) b\n" + "Returns: (list)\n" + "\n" + "Finds the set difference of a and b\n" + ); + OP_ADDN(9,union,|||, + "List union\n" + "Syntax: (list) a &&& (list) b\n" + "Returns: (list)\n" + "\n" + "Finds the set union of a and b\n" + ); +} -- cgit v1.2.3