1 /* This file is part of Pazpar2.
2 Copyright (C) Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /** \file facet_limit.c
21 \brief Parse facet limit
31 #include <yaz/yaz-version.h>
34 #include "facet_limit.h"
42 facet_limits_t facet_limits_dup(facet_limits_t fl)
45 NMEM nmem = nmem_create();
46 facet_limits_t fn = nmem_malloc(nmem, sizeof(*fn));
52 fn->darray = nmem_malloc(nmem, fn->num * sizeof(*fn->darray));
53 for (i = 0; i < fn->num; i++)
55 const char *src = fl->darray[i];
56 size_t sz = strlen(src) + 2 + strlen(src + strlen(src) + 1);
57 fn->darray[i] = nmem_malloc(nmem, sz);
58 memcpy(fn->darray[i], src, sz);
64 facet_limits_t facet_limits_create(const char *param)
67 NMEM nmem = nmem_create();
68 facet_limits_t fl = nmem_malloc(nmem, sizeof(*fl));
73 nmem_strsplit_escape2(fl->nmem, ",", param, &fl->darray,
74 &fl->num, 1, '\\', 0);
75 /* replace = with \0 .. for each item */
76 for (i = 0; i < fl->num; i++)
78 char *cp = strchr(fl->darray[i], '=');
81 facet_limits_destroy(fl);
89 int facet_limits_num(facet_limits_t fl)
94 const char *facet_limits_get(facet_limits_t fl, int idx, const char **value)
96 if (idx >= fl->num || idx < 0)
98 *value = fl->darray[idx] + strlen(fl->darray[idx]) + 1;
99 return fl->darray[idx];
102 void facet_limits_destroy(facet_limits_t fl)
105 nmem_destroy(fl->nmem);
111 * c-file-style: "Stroustrup"
112 * indent-tabs-mode: nil
114 * vim: shiftwidth=4 tabstop=8 expandtab