1 /* $Id: normalize7bit.c,v 1.2 2007-04-27 12:17:04 marc Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /** \file normalize7bit.c
23 \brief char and string normalization for 7bit ascii only
34 #include "normalize7bit.h"
37 char * normalize7bit_generic(char * str, const char * rm_chars)
40 for (p = str; *p && isspace(*p); p++)
42 for (pe = p + strlen(p) - 1;
43 pe > p && strchr(rm_chars, *pe); pe--)
50 char * normalize7bit_mergekey(char *buf, int skiparticle)
52 char *p = buf, *pout = buf;
57 char articles[] = "the den der die des an a "; // must end in space
59 while (*p && !isalnum(*p))
62 while (*p && *p != ' ' && pout - firstword < 62)
63 *(pout++) = tolower(*(p++));
66 if (!strstr(articles, firstword))
73 while (*p && !isalnum(*p))
76 *(pout++) = tolower(*(p++));
79 while (*p && !isalnum(*p))
86 while (pout > buf && *pout == ' ');
91 // Extract what appears to be years from buf, storing highest and
93 int extract7bit_years(const char *buf, int *first, int *last)
102 while (*buf && !isdigit(*buf))
105 for (e = buf; *e && isdigit(*e); e++)
109 int value = atoi(buf);
110 if (*first < 0 || value < *first)
112 if (*last < 0 || value > *last)
125 * indent-tabs-mode: nil
127 * vim: shiftwidth=4 tabstop=8 expandtab