projects
/
pazpar2-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Happy new year
[pazpar2-moved-to-github.git]
/
src
/
charsets.c
diff --git
a/src/charsets.c
b/src/charsets.c
index
f931445
..
784b03c
100644
(file)
--- a/
src/charsets.c
+++ b/
src/charsets.c
@@
-1,5
+1,5
@@
/* This file is part of Pazpar2.
/* This file is part of Pazpar2.
- Copyright (C) 2006-2013 Index Data
+ Copyright (C) Index Data
Pazpar2 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
Pazpar2 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
@@
-53,6
+53,8
@@
struct pp2_charset_s {
const char *(*token_next_handler)(pp2_charset_token_t prt);
const char *(*get_sort_handler)(pp2_charset_token_t prt);
const char *(*get_display_handler)(pp2_charset_token_t prt);
const char *(*token_next_handler)(pp2_charset_token_t prt);
const char *(*get_sort_handler)(pp2_charset_token_t prt);
const char *(*get_display_handler)(pp2_charset_token_t prt);
+ void (*get_org_handler)(pp2_charset_token_t ptr,
+ size_t *start, size_t *len);
#if YAZ_HAVE_ICU
struct icu_chain * icu_chn;
UErrorCode icu_sts;
#if YAZ_HAVE_ICU
struct icu_chain * icu_chn;
UErrorCode icu_sts;
@@
-63,11
+65,15
@@
static const char *pp2_charset_token_null(pp2_charset_token_t prt);
static const char *pp2_charset_token_a_to_z(pp2_charset_token_t prt);
static const char *pp2_get_sort_ascii(pp2_charset_token_t prt);
static const char *pp2_get_display_ascii(pp2_charset_token_t prt);
static const char *pp2_charset_token_a_to_z(pp2_charset_token_t prt);
static const char *pp2_get_sort_ascii(pp2_charset_token_t prt);
static const char *pp2_get_display_ascii(pp2_charset_token_t prt);
+static void pp2_get_org_ascii(pp2_charset_token_t prt,
+ size_t *start, size_t *len);
#if YAZ_HAVE_ICU
static const char *pp2_charset_token_icu(pp2_charset_token_t prt);
static const char *pp2_get_sort_icu(pp2_charset_token_t prt);
static const char *pp2_get_display_icu(pp2_charset_token_t prt);
#if YAZ_HAVE_ICU
static const char *pp2_charset_token_icu(pp2_charset_token_t prt);
static const char *pp2_get_sort_icu(pp2_charset_token_t prt);
static const char *pp2_get_display_icu(pp2_charset_token_t prt);
+static void pp2_get_org_icu(pp2_charset_token_t prt,
+ size_t *start, size_t *len);
#endif
/* tokenzier handle */
#endif
/* tokenzier handle */
@@
-80,6
+86,9
@@
struct pp2_charset_token_s {
#if YAZ_HAVE_ICU
yaz_icu_iter_t iter;
#endif
#if YAZ_HAVE_ICU
yaz_icu_iter_t iter;
#endif
+ const char *cp0;
+ size_t start;
+ size_t len;
};
struct pp2_charset_fact_s {
};
struct pp2_charset_fact_s {
@@
-226,6
+235,7
@@
pp2_charset_t pp2_charset_create(void)
pct->token_next_handler = pp2_charset_token_null;
pct->get_sort_handler = pp2_get_sort_ascii;
pct->get_display_handler = pp2_get_display_ascii;
pct->token_next_handler = pp2_charset_token_null;
pct->get_sort_handler = pp2_get_sort_ascii;
pct->get_display_handler = pp2_get_display_ascii;
+ pct->get_org_handler = pp2_get_org_ascii;
#if YAZ_HAVE_ICU
pct->icu_chn = 0;
#endif // YAZ_HAVE_ICU
#if YAZ_HAVE_ICU
pct->icu_chn = 0;
#endif // YAZ_HAVE_ICU
@@
-250,6
+260,7
@@
pp2_charset_t pp2_charset_create_icu(struct icu_chain *icu_chn)
pct->token_next_handler = pp2_charset_token_icu;
pct->get_sort_handler = pp2_get_sort_icu;
pct->get_display_handler = pp2_get_display_icu;
pct->token_next_handler = pp2_charset_token_icu;
pct->get_sort_handler = pp2_get_sort_icu;
pct->get_display_handler = pp2_get_display_icu;
+ pct->get_org_handler = pp2_get_org_icu;
}
return pct;
}
}
return pct;
}
@@
-290,6
+301,8
@@
pp2_charset_token_t pp2_charset_tokenize(pp2_charset_t pct)
if (pct->icu_chn)
prt->iter = icu_iter_create(pct->icu_chn);
#endif
if (pct->icu_chn)
prt->iter = icu_iter_create(pct->icu_chn);
#endif
+ prt->start = 0;
+ prt->len = 0;
return prt;
}
return prt;
}
@@
-313,6
+326,7
@@
void pp2_charset_token_first(pp2_charset_token_t prt,
wrbuf_rewind(prt->norm_str);
wrbuf_rewind(prt->sort_str);
wrbuf_rewind(prt->norm_str);
wrbuf_rewind(prt->sort_str);
+ prt->cp0 = buf;
prt->cp = buf;
prt->last_cp = 0;
prt->cp = buf;
prt->last_cp = 0;
@@
-354,6
+368,12
@@
const char *pp2_get_display(pp2_charset_token_t prt)
return prt->pct->get_display_handler(prt);
}
return prt->pct->get_display_handler(prt);
}
+void pp2_get_org(pp2_charset_token_t prt, size_t *start, size_t *len)
+{
+ prt->pct->get_org_handler(prt, start, len);
+}
+
+
#define raw_char(c) (((c) >= 'a' && (c) <= 'z') ? (c) : -1)
/* original tokenizer with our tokenize interface, but we
add +1 to ensure no '\0' are in our string (except for EOF)
#define raw_char(c) (((c) >= 'a' && (c) <= 'z') ? (c) : -1)
/* original tokenizer with our tokenize interface, but we
add +1 to ensure no '\0' are in our string (except for EOF)
@@
-363,6
+383,7
@@
static const char *pp2_charset_token_a_to_z(pp2_charset_token_t prt)
const char *cp = prt->cp;
int c;
const char *cp = prt->cp;
int c;
+ prt->start = cp - prt->cp0;
/* skip white space */
while (*cp && (c = raw_char(tolower(*(const unsigned char *)cp))) < 0)
cp++;
/* skip white space */
while (*cp && (c = raw_char(tolower(*(const unsigned char *)cp))) < 0)
cp++;
@@
-381,6
+402,7
@@
static const char *pp2_charset_token_a_to_z(pp2_charset_token_t prt)
wrbuf_putc(prt->norm_str, c);
cp++;
}
wrbuf_putc(prt->norm_str, c);
cp++;
}
+ prt->len = (cp - prt->cp0) - prt->start;
prt->cp = cp;
return wrbuf_cstr(prt->norm_str);
}
prt->cp = cp;
return wrbuf_cstr(prt->norm_str);
}
@@
-412,6
+434,13
@@
static const char *pp2_get_display_ascii(pp2_charset_token_t prt)
}
}
}
}
+static void pp2_get_org_ascii(pp2_charset_token_t prt,
+ size_t *start, size_t *len)
+{
+ *start = prt->start;
+ *len = prt->len;
+}
+
static const char *pp2_charset_token_null(pp2_charset_token_t prt)
{
const char *cp = prt->cp;
static const char *pp2_charset_token_null(pp2_charset_token_t prt)
{
const char *cp = prt->cp;
@@
-420,6
+449,7
@@
static const char *pp2_charset_token_null(pp2_charset_token_t prt)
while (*cp)
cp++;
prt->cp = cp;
while (*cp)
cp++;
prt->cp = cp;
+ prt->len = cp - prt->cp0;
return prt->last_cp;
}
return prt->last_cp;
}
@@
-443,6
+473,11
@@
static const char *pp2_get_display_icu(pp2_charset_token_t prt)
return icu_iter_get_display(prt->iter);
}
return icu_iter_get_display(prt->iter);
}
+static void pp2_get_org_icu(pp2_charset_token_t prt, size_t *start, size_t *len)
+{
+ icu_iter_get_org_info(prt->iter, start, len);
+}
+
#endif // YAZ_HAVE_ICU
#endif // YAZ_HAVE_ICU