stacinhtml

Static C in HTML - simple static site generator
git clone git://git.kocotian.pl/stacinhtml.git
Log | Files | Refs | README | LICENSE

str.h (1852B)


      1 /*
      2    stacinhtml - STAtic C IN HTML - simple static site generator
      3    Copyright (C) 2021  Kacper Kocot <kocotian@kocotian.pl>
      4 
      5    This program is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    This program is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program; if not, write to the Free Software Foundation,
     17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
     18 
     19 */
     20 
     21 #ifndef _STR_H
     22 #define _STR_H
     23 
     24 #include <ctype.h>
     25 #include <sys/types.h>
     26 #include <string.h>
     27 
     28 /* Types and pseudo-types */
     29 typedef struct {
     30 	char *data;
     31 	size_t len;
     32 } String;
     33 
     34 #define Array(TYPE) struct { TYPE *data; size_t len; }
     35 
     36 /* String functions */
     37 String toString(char *s);
     38 int Strcmp(String a, String b);
     39 int Strcmpc(String s1, char *s2);
     40 ssize_t Strtok(String string, String *out, char c);
     41 String Striden(String string);
     42 String Strtrim(String str);
     43 
     44 /* Array functions */
     45 int _inArray(char *data, size_t len, void *val, size_t vlen);
     46 #define inArray(ARR, VAL) (_inArray( \
     47 				   (void *)(ARR).data, (ARR).len, &(VAL), sizeof (VAL)))
     48 void *_prepareArray(void *data, size_t siz);
     49 #define prepareArray(ARR) (_prepareArray(&(ARR), sizeof (ARR)))
     50 
     51 /* Vector - dynamic Array */
     52 #define newVector(ARR) ((ARR).data = malloc((ARR).len = 0))
     53 #define pushVector(ARR, VAL) (((ARR).data = \
     54 			realloc((ARR).data, \
     55 				++((ARR).len) * (sizeof *((ARR).data)))), \
     56 		(ARR).data[(ARR).len - 1] = (VAL))
     57 
     58 #endif