1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2012 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 normalize7bit.c
21 \brief char and string normalization for 7bit ascii only
32 #include "normalize7bit.h"
35 /** \brief removes leading whitespace.. Removes suffix cahrs in rm_chars */
36 char * normalize7bit_generic(char * str, const char * rm_chars)
39 for (p = str; *p && isspace(*(unsigned char *)p); p++)
41 for (pe = p + strlen(p) - 1;
42 pe > p && strchr(rm_chars, *pe); pe--)
47 char *normalize7bit_mergekey(char *buf)
49 char *p = buf, *pout = buf;
52 while (*p && !isalnum(*(unsigned char *)p))
54 while (isalnum(*(unsigned char *)p))
55 *(pout++) = tolower(*(unsigned char *)(p++));
58 while (*p && !isalnum(*(unsigned char *)p))
65 while (pout > buf && *pout == ' ');
70 // Extract what appears to be years from buf, storing highest and
72 // longdate==1, look for YYYYMMDD, longdate=0 look only for YYYY
73 int extract7bit_dates(const char *buf, int *first, int *last, int longdate)
82 while (*buf && !isdigit(*(unsigned char *)buf))
85 for (e = buf; *e && isdigit(*(unsigned char *)e); e++)
87 if ((len == 4 && !longdate) || (longdate && len >= 4 && len <= 8))
89 int value = atoi(buf);
90 if (longdate && len == 4)
91 value *= 10000; // should really suffix 0101?
92 if (*first < 0 || value < *first)
94 if (*last < 0 || value > *last)
107 * c-file-style: "Stroustrup"
108 * indent-tabs-mode: nil
110 * vim: shiftwidth=4 tabstop=8 expandtab