1*946379e7Schristos /* Message list test for ASCII character set.
2*946379e7Schristos Copyright (C) 2001-2002, 2005-2006 Free Software Foundation, Inc.
3*946379e7Schristos Written by Bruno Haible <haible@clisp.cons.org>, 2001.
4*946379e7Schristos
5*946379e7Schristos This program is free software; you can redistribute it and/or modify
6*946379e7Schristos it under the terms of the GNU General Public License as published by
7*946379e7Schristos the Free Software Foundation; either version 2, or (at your option)
8*946379e7Schristos any later version.
9*946379e7Schristos
10*946379e7Schristos This program is distributed in the hope that it will be useful,
11*946379e7Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
12*946379e7Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*946379e7Schristos GNU General Public License for more details.
14*946379e7Schristos
15*946379e7Schristos You should have received a copy of the GNU General Public License
16*946379e7Schristos along with this program; if not, write to the Free Software Foundation,
17*946379e7Schristos Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18*946379e7Schristos
19*946379e7Schristos
20*946379e7Schristos #ifdef HAVE_CONFIG_H
21*946379e7Schristos # include "config.h"
22*946379e7Schristos #endif
23*946379e7Schristos
24*946379e7Schristos /* Specification. */
25*946379e7Schristos #include "msgl-ascii.h"
26*946379e7Schristos
27*946379e7Schristos #include "c-ctype.h"
28*946379e7Schristos
29*946379e7Schristos
30*946379e7Schristos /* This file's structure parallels msgl-iconv.c. */
31*946379e7Schristos
32*946379e7Schristos
33*946379e7Schristos bool
is_ascii_string(const char * string)34*946379e7Schristos is_ascii_string (const char *string)
35*946379e7Schristos {
36*946379e7Schristos for (; *string; string++)
37*946379e7Schristos if (!c_isascii ((unsigned char) *string))
38*946379e7Schristos return false;
39*946379e7Schristos return true;
40*946379e7Schristos }
41*946379e7Schristos
42*946379e7Schristos bool
is_ascii_string_list(string_list_ty * slp)43*946379e7Schristos is_ascii_string_list (string_list_ty *slp)
44*946379e7Schristos {
45*946379e7Schristos size_t i;
46*946379e7Schristos
47*946379e7Schristos if (slp != NULL)
48*946379e7Schristos for (i = 0; i < slp->nitems; i++)
49*946379e7Schristos if (!is_ascii_string (slp->item[i]))
50*946379e7Schristos return false;
51*946379e7Schristos return true;
52*946379e7Schristos }
53*946379e7Schristos
54*946379e7Schristos bool
is_ascii_message(message_ty * mp)55*946379e7Schristos is_ascii_message (message_ty *mp)
56*946379e7Schristos {
57*946379e7Schristos const char *p = mp->msgstr;
58*946379e7Schristos const char *p_end = p + mp->msgstr_len;
59*946379e7Schristos
60*946379e7Schristos for (; p < p_end; p++)
61*946379e7Schristos if (!c_isascii ((unsigned char) *p))
62*946379e7Schristos return false;
63*946379e7Schristos
64*946379e7Schristos if (!is_ascii_string_list (mp->comment))
65*946379e7Schristos return false;
66*946379e7Schristos if (!is_ascii_string_list (mp->comment_dot))
67*946379e7Schristos return false;
68*946379e7Schristos
69*946379e7Schristos /* msgid and msgid_plural are normally ASCII, so why checking?
70*946379e7Schristos Because in complete UTF-8 environments they can be UTF-8, not ASCII. */
71*946379e7Schristos if (!is_ascii_string (mp->msgid))
72*946379e7Schristos return false;
73*946379e7Schristos if (mp->msgid_plural != NULL && !is_ascii_string (mp->msgid_plural))
74*946379e7Schristos return false;
75*946379e7Schristos
76*946379e7Schristos /* Likewise for msgctxt. */
77*946379e7Schristos if (mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt))
78*946379e7Schristos return false;
79*946379e7Schristos
80*946379e7Schristos /* Likewise for the prev_* fields. */
81*946379e7Schristos if (mp->prev_msgctxt != NULL && !is_ascii_string (mp->prev_msgctxt))
82*946379e7Schristos return false;
83*946379e7Schristos if (mp->prev_msgid != NULL && !is_ascii_string (mp->prev_msgid))
84*946379e7Schristos return false;
85*946379e7Schristos if (mp->prev_msgid_plural != NULL && !is_ascii_string (mp->prev_msgid_plural))
86*946379e7Schristos return false;
87*946379e7Schristos
88*946379e7Schristos return true;
89*946379e7Schristos }
90*946379e7Schristos
91*946379e7Schristos bool
is_ascii_message_list(message_list_ty * mlp)92*946379e7Schristos is_ascii_message_list (message_list_ty *mlp)
93*946379e7Schristos {
94*946379e7Schristos size_t j;
95*946379e7Schristos
96*946379e7Schristos for (j = 0; j < mlp->nitems; j++)
97*946379e7Schristos if (!is_ascii_message (mlp->item[j]))
98*946379e7Schristos return false;
99*946379e7Schristos
100*946379e7Schristos return true;
101*946379e7Schristos }
102*946379e7Schristos
103*946379e7Schristos bool
is_ascii_msgdomain_list(msgdomain_list_ty * mdlp)104*946379e7Schristos is_ascii_msgdomain_list (msgdomain_list_ty *mdlp)
105*946379e7Schristos {
106*946379e7Schristos size_t k;
107*946379e7Schristos
108*946379e7Schristos for (k = 0; k < mdlp->nitems; k++)
109*946379e7Schristos if (!is_ascii_message_list (mdlp->item[k]->messages))
110*946379e7Schristos return false;
111*946379e7Schristos
112*946379e7Schristos return true;
113*946379e7Schristos }
114